-
Notifications
You must be signed in to change notification settings - Fork 1
feat(instrumentation): otel collector #61
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
4107b0d
78fb5d2
f1286d0
713709c
a44b0fa
0c446f3
94ffaf8
fc6d1a4
814cfb7
f008537
bb94155
cad8f32
6a90352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| use opentelemetry::global; | ||
| use opentelemetry::metrics::{Counter, Gauge, Histogram}; | ||
| use std::time::Instant; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct BatchMetrics { | ||
| pub batch_number_counter: Counter<u64>, | ||
| pub number_of_transactions_batch: Histogram<u64>, | ||
| } | ||
| impl BatchMetrics { | ||
| pub fn init() -> Self { | ||
| let metrics_meter = global::meter("nexus-metrics"); | ||
| let batch_number_counter = metrics_meter.u64_counter("block_number").with_unit("Blocks").init(); | ||
| let number_of_transactions_batch = metrics_meter.u64_histogram("number_of_transactions").init(); | ||
| Self { | ||
| batch_number_counter, | ||
| number_of_transactions_batch, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct MempoolMetrics { | ||
| pub mempool_txn_count_gauge: Gauge<u64>, | ||
| } | ||
| impl MempoolMetrics { | ||
| pub fn init() -> Self { | ||
| let metrics_meter = global::meter("nexus-metrics"); | ||
| let mempool_txn_count_gauge = metrics_meter.u64_gauge("mempool_txn_count").with_unit("Transactions").init(); | ||
| Self { mempool_txn_count_gauge } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct ExecutionMetrics { | ||
| pub batch_execution_time: Histogram<u64>, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rebase to vr/sequencing, so execution metrics and prover metrics can be separated.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| pub batch_proving_time: Histogram<u64>, | ||
| pub total_batch_execution_time: Histogram<u64>, | ||
| } | ||
| impl ExecutionMetrics { | ||
| pub fn init() -> Self { | ||
| let metrics_meter = global::meter("nexus-metrics"); | ||
| let batch_execution_time = metrics_meter.u64_histogram("batch_execution_time").init(); | ||
| let batch_proving_time = metrics_meter.u64_histogram("batch_proving_time").init(); | ||
| let total_batch_execution_time = metrics_meter.u64_histogram("total_batch_execution_time").init(); | ||
| Self { | ||
| batch_execution_time, | ||
| batch_proving_time, | ||
| total_batch_execution_time, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct ApiMetrics { | ||
| submit_tx_counter: Counter<u64>, | ||
| tx_status_counter: Counter<u64>, | ||
| get_block_counter: Counter<u64>, | ||
| get_state_counter: Counter<u64>, | ||
| get_state_hex_counter: Counter<u64>, | ||
| get_header_counter: Counter<u64>, | ||
| range_counter: Counter<u64>, | ||
|
|
||
| submit_tx_response_time: Histogram<f64>, | ||
| tx_status_response_time: Histogram<f64>, | ||
| get_block_response_time: Histogram<f64>, | ||
| get_state_response_time: Histogram<f64>, | ||
| get_state_hex_response_time: Histogram<f64>, | ||
| get_header_response_time: Histogram<f64>, | ||
| range_response_time: Histogram<f64>, | ||
| } | ||
|
|
||
| impl ApiMetrics { | ||
| pub fn new() -> Self { | ||
| let meter = global::meter("nexus_api"); | ||
|
|
||
| let submit_tx_counter = meter | ||
| .u64_counter("nexus_api_submit_tx_requests") | ||
| .with_description("Number of transaction submission requests") | ||
| .init(); | ||
|
|
||
| let tx_status_counter = meter | ||
| .u64_counter("nexus_api_tx_status_requests") | ||
| .with_description("Number of transaction status requests") | ||
| .init(); | ||
|
|
||
| let get_block_counter = meter | ||
| .u64_counter("nexus_api_get_block_requests") | ||
| .with_description("Number of block retrieval requests") | ||
| .init(); | ||
|
|
||
| let get_state_counter = meter | ||
| .u64_counter("nexus_api_get_state_requests") | ||
| .with_description("Number of account state requests") | ||
| .init(); | ||
|
|
||
| let get_state_hex_counter = meter | ||
| .u64_counter("nexus_api_get_state_hex_requests") | ||
| .with_description("Number of hex account state requests") | ||
| .init(); | ||
|
|
||
| let get_header_counter = meter | ||
| .u64_counter("nexus_api_get_header_requests") | ||
| .with_description("Number of header requests") | ||
| .init(); | ||
|
|
||
| let range_counter = meter | ||
| .u64_counter("nexus_api_range_requests") | ||
| .with_description("Number of block range requests") | ||
| .init(); | ||
|
|
||
| // Create histograms for response times (in milliseconds) | ||
| let submit_tx_response_time = meter | ||
| .f64_histogram("nexus_api_submit_tx_response_time") | ||
| .with_description("Response time for transaction submission") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let tx_status_response_time = meter | ||
| .f64_histogram("nexus_api_tx_status_response_time") | ||
| .with_description("Response time for transaction status requests") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let get_block_response_time = meter | ||
| .f64_histogram("nexus_api_get_block_response_time") | ||
| .with_description("Response time for block retrieval") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let get_state_response_time = meter | ||
| .f64_histogram("nexus_api_get_state_response_time") | ||
| .with_description("Response time for account state requests") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let get_state_hex_response_time = meter | ||
| .f64_histogram("nexus_api_get_state_hex_response_time") | ||
| .with_description("Response time for hex account state requests") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let get_header_response_time = meter | ||
| .f64_histogram("nexus_api_get_header_response_time") | ||
| .with_description("Response time for header requests") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| let range_response_time = meter | ||
| .f64_histogram("nexus_api_range_response_time") | ||
| .with_description("Response time for block range requests") | ||
| .with_unit("ms") | ||
| .init(); | ||
|
|
||
| Self { | ||
| submit_tx_counter, | ||
| tx_status_counter, | ||
| get_block_counter, | ||
| get_state_counter, | ||
| get_state_hex_counter, | ||
| get_header_counter, | ||
| range_counter, | ||
|
|
||
| submit_tx_response_time, | ||
| tx_status_response_time, | ||
| get_block_response_time, | ||
| get_state_response_time, | ||
| get_state_hex_response_time, | ||
| get_header_response_time, | ||
| range_response_time, | ||
| } | ||
| } | ||
|
|
||
| // Measure response time and increment counter for submit_tx endpoint | ||
| pub fn record_submit_tx_request(&self, start_time: Instant) { | ||
| self.submit_tx_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.submit_tx_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for tx_status endpoint | ||
| pub fn record_tx_status_request(&self, start_time: Instant) { | ||
| self.tx_status_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.tx_status_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for get_block endpoint | ||
| pub fn record_get_block_request(&self, start_time: Instant) { | ||
| self.get_block_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.get_block_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for get_state endpoint | ||
| pub fn record_get_state_request(&self, start_time: Instant) { | ||
| self.get_state_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.get_state_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for get_state_hex endpoint | ||
| pub fn record_get_state_hex_request(&self, start_time: Instant) { | ||
| self.get_state_hex_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.get_state_hex_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for get_header endpoint | ||
| pub fn record_get_header_request(&self, start_time: Instant) { | ||
| self.get_header_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.get_header_response_time.record(duration, &[]); | ||
| } | ||
|
|
||
| // Measure response time and increment counter for range endpoint | ||
| pub fn record_range_request(&self, start_time: Instant) { | ||
| self.range_counter.add(1, &[]); | ||
| let duration = start_time.elapsed().as_millis() as f64; | ||
| self.range_response_time.record(duration, &[]); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. As I updated the risc 0 version we don't need to install the cargo components separately.