Skip to content

Commit

Permalink
[api] Add metrics to api tester (#9307)
Browse files Browse the repository at this point in the history
This commit introduces logging tools on top of the consistent API testing introduced here. See proposal for more high level information.

Changes:

Added metrics pusher to aptos-api-tester with 4 histogram metrics for success, error, fail rates, and latency.
Added logs to tests instead of printing to stdout.
  • Loading branch information
ngkuru committed Aug 4, 2023
1 parent 42af50b commit 0c0f9a9
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 47 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/aptos-api-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ anyhow = { workspace = true }
aptos-api-types = { workspace = true }
aptos-cached-packages = { workspace = true }
aptos-framework = { workspace = true }
aptos-logger = { workspace = true }
aptos-network = { workspace = true }
aptos-push-metrics = { workspace = true }
aptos-rest-client = { workspace = true }
aptos-sdk = { workspace = true }
aptos-types = { workspace = true }
move-core-types = { workspace = true }
once_cell = { workspace = true }
prometheus = { workspace = true }
rand = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
55 changes: 55 additions & 0 deletions crates/aptos-api-tester/src/counters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright © Aptos Foundation

use once_cell::sync::Lazy;
use prometheus::{register_histogram_vec, Histogram, HistogramVec};

pub static API_TEST_SUCCESS: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"api_test_success",
"Number of user flows which succesfully passed",
&["test_name", "network_name"],
)
.unwrap()
});

pub fn test_success(test_name: &str, network_name: &str) -> Histogram {
API_TEST_SUCCESS.with_label_values(&[test_name, network_name])
}

pub static API_TEST_FAIL: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"api_test_fail",
"Number of user flows which failed checks",
&["test_name", "network_name"],
)
.unwrap()
});

pub fn test_fail(test_name: &str, network_name: &str) -> Histogram {
API_TEST_FAIL.with_label_values(&[test_name, network_name])
}

pub static API_TEST_ERROR: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!("api_test_error", "Number of user flows which crashed", &[
"test_name",
"network_name",
])
.unwrap()
});

pub fn test_error(test_name: &str, network_name: &str) -> Histogram {
API_TEST_ERROR.with_label_values(&[test_name, network_name])
}

pub static API_TEST_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"api_test_latency",
"Time it takes to complete a user flow",
&["test_name", "network_name", "result"],
)
.unwrap()
});

pub fn test_latency(test_name: &str, network_name: &str, result: &str) -> Histogram {
API_TEST_LATENCY.with_label_values(&[test_name, network_name, result])
}
Loading

0 comments on commit 0c0f9a9

Please sign in to comment.