Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc benchmark: script to pull Grafana logs #20911

Open
wants to merge 5 commits into
base: rpc-benchmark-init
Choose a base branch
from

Conversation

gegaowp
Copy link
Contributor

@gegaowp gegaowp commented Jan 17, 2025

Description

a stacked pr, pull sampled JSON RPC request logs from Grafana API, now a local port-forward is necessary to make it work

Test plan

local run

  • on one CLI (some pre-requisite gcloud setup is needed)
k -n loki port-forward loki-loki-distributed-querier-11 3100:3100
  • the other CLI, with limit for faster test run
RUST_LOG=debug GRAFANA_LOGS_URL="http://localhost:3100/loki/api/v1/query_range" NET="mainnet" LIMIT=1000 cargo run --bin pull_grafana_logs

the output, suix_getBalance / suix_getAllBalances are the top ones taking the majority

2025-01-24T06:29:42.818121Z  INFO pull_grafana_logs: Found 1000 logs.
2025-01-24T06:29:42.836915Z  INFO pull_grafana_logs: Writing 1 logs for method: sui_getLatestCheckpointSequenceNumber
2025-01-24T06:29:42.836962Z  INFO pull_grafana_logs: Writing 1 logs for method: suix_queryTransactionBlocks
2025-01-24T06:29:42.836968Z  INFO pull_grafana_logs: Writing 12 logs for method: suix_getCoinMetadata
2025-01-24T06:29:42.836981Z  INFO pull_grafana_logs: Writing 10 logs for method: sui_getTransactionBlock
2025-01-24T06:29:42.836992Z  INFO pull_grafana_logs: Writing 41 logs for method: sui_getObject
2025-01-24T06:29:42.837037Z  INFO pull_grafana_logs: Writing 9 logs for method: suix_getCoins
2025-01-24T06:29:42.837047Z  INFO pull_grafana_logs: Writing 44 logs for method: suix_getReferenceGasPrice
2025-01-24T06:29:42.837074Z  INFO pull_grafana_logs: Writing 12 logs for method: suix_getOwnedObjects
2025-01-24T06:29:42.837096Z  INFO pull_grafana_logs: Writing 186 logs for method: suix_getAllBalances
2025-01-24T06:29:42.837186Z  INFO pull_grafana_logs: Writing 1 logs for method: sui_multiGetTransactionBlocks
2025-01-24T06:29:42.837193Z  INFO pull_grafana_logs: Writing 559 logs for method: suix_getBalance
2025-01-24T06:29:42.837424Z  INFO pull_grafana_logs: Writing 5 logs for method: suix_getStakes
2025-01-24T06:29:42.837435Z  INFO pull_grafana_logs: Writing 1 logs for method: suix_getValidatorsApy
2025-01-24T06:29:42.837440Z  INFO pull_grafana_logs: Writing 4 logs for method: suix_queryEvents
2025-01-24T06:29:42.837446Z  INFO pull_grafana_logs: Writing 1 logs for method: suix_getDynamicFieldObject
2025-01-24T06:29:42.837451Z  INFO pull_grafana_logs: Writing 13 logs for method: sui_getNormalizedMoveFunction
2025-01-24T06:29:42.837467Z  INFO pull_grafana_logs: Writing 7 logs for method: suix_resolveNameServiceNames
2025-01-24T06:29:42.837476Z  INFO pull_grafana_logs: Writing 2 logs for method: suix_getLatestSuiSystemState
2025-01-24T06:29:42.837481Z  INFO pull_grafana_logs: Writing 20 logs for method: sui_multiGetObjects
2025-01-24T06:29:42.837509Z  INFO pull_grafana_logs: Writing 8 logs for method: sui_getProtocolConfig
2025-01-24T06:29:42.837517Z  INFO pull_grafana_logs: Writing 57 logs for method: sui_dryRunTransactionBlock
2025-01-24T06:29:42.837608Z  INFO pull_grafana_logs: Done! Wrote grouped logs to sampled_read_requests.jsonl

logged jsonl file is like

{"method":"sui_getLatestCheckpointSequenceNumber", "body":{"jsonrpc": "2.0", "id": 1, "method": "sui_getLatestCheckpointSequenceNumber", "params": []}}
{"method":"suix_queryTransactionBlocks", "body":{"jsonrpc":"2.0","id":103,"method":"suix_queryTransactionBlocks","params":[{"filter":{"FromAddress":"0x231ea89eff93a0a49644d80a2a90edb08b86d191188ca886a2e901df098dee00"},"options":{"showInput":true,"showEffects":true,"showEvents":true}},null,null,true]}}
...

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 27, 2025 3:51pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jan 27, 2025 3:51pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jan 27, 2025 3:51pm

@gegaowp gegaowp temporarily deployed to sui-typescript-aws-kms-test-env January 17, 2025 09:08 — with GitHub Actions Inactive
@gegaowp gegaowp temporarily deployed to sui-typescript-aws-kms-test-env January 24, 2025 06:35 — with GitHub Actions Inactive
@gegaowp gegaowp changed the title Grafana pull rpc benchmark: pull Grafana logs Jan 24, 2025
@gegaowp gegaowp marked this pull request as ready for review January 24, 2025 06:41
@gegaowp gegaowp temporarily deployed to sui-typescript-aws-kms-test-env January 24, 2025 06:41 — with GitHub Actions Inactive
@gegaowp gegaowp changed the title rpc benchmark: pull Grafana logs rpc benchmark: script to pull Grafana logs Jan 24, 2025
Comment on lines +55 to +72
async fn fetch_logs(
client: &reqwest::Client,
url: &str,
query: &str,
start: &str,
end: &str,
limit: u64,
offset: Option<u64>,
) -> Result<LokiResponse, Box<dyn Error>> {
let mut params = vec![
("query".to_string(), query.to_string()),
("start".to_string(), start.to_string()),
("end".to_string(), end.to_string()),
("limit".to_string(), limit.to_string()),
];
if let Some(o) = offset {
params.push(("start_from".to_string(), o.to_string()));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mainly when we're benchmarking against a remote jsonrpc service right? if we were to benchmark jsonrpc locally, then we can pull from the local metrics service or something like that directly?

message: String,
}

fn extract_body_from_message(message: &str) -> Option<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add doc comments explaining the format that you are parsing here, and for fetch_logs.

.with_env()
.init();
if let Err(e) = run().await {
error!("Error: {}", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error!("Error: {}", e);
error!("{e}");

let mut writer = BufWriter::new(file);

for (method, bodies) in method_map {
info!("Writing {} logs for method: {}", bodies.len(), method);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
info!("Writing {} logs for method: {}", bodies.len(), method);
info!(len=bodies.len(), method, "Writing logs");

Comment on lines +193 to +195
let line = format!(r#"{{"method":"{}", "body":{}}}"#, method, body);
writer.write_all(line.as_bytes())?;
writer.write_all(b"\n")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to allocate for the line before writing it out.

Suggested change
let line = format!(r#"{{"method":"{}", "body":{}}}"#, method, body);
writer.write_all(line.as_bytes())?;
writer.write_all(b"\n")?;
write!(writer, r#"{{"method":"{method}", "body":"#)?;
writer.write_all(body.as_bytes())?;
write!(writer, "}}\n")?;

let mut method_map: HashMap<String, Vec<String>> = HashMap::new();
for log_entry in all_logs {
if let Some(body_content) = extract_body_from_message(&log_entry.message) {
if let Ok(parsed) = serde_json::from_str::<Value>(&body_content) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we print an error if we weren't able to parse the JSON?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants