Skip to content

Commit

Permalink
Add WRITE_RATE_LIMIT_STEP_BYTES_WRITTEN for WriteRateLimitStep (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
banool authored Jan 21, 2025
1 parent a56b641 commit f2dc006
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::{
types::transaction_context::TransactionContext,
utils::{
errors::ProcessorError,
step_metrics::{StepMetricLabels, WRITE_RATE_LIMIT_STEP_REMAINING_BYTES},
step_metrics::{
StepMetricLabels, WRITE_RATE_LIMIT_STEP_BYTES_WRITTEN,
WRITE_RATE_LIMIT_STEP_REMAINING_BYTES,
},
},
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -134,6 +137,13 @@ where
})
.set(self.current_bucket_size as i64);

// Bump the inverse metric, which is just the bytes written as a counter.
WRITE_RATE_LIMIT_STEP_BYTES_WRITTEN
.get_or_create(&StepMetricLabels {
step_name: self.name(),
})
.inc_by(size_of_item as u64);

Ok(out)
}
}
Expand Down
9 changes: 9 additions & 0 deletions aptos-indexer-processors-sdk/sdk/src/utils/step_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ pub fn init_step_metrics_registry(registry: &mut Registry) {
"WriteRateLimitStep remaining bytes (aka tokens) that can be written this instant",
WRITE_RATE_LIMIT_STEP_REMAINING_BYTES.clone(),
);

registry.register(
format!("{}_{}", METRICS_PREFIX, "write_rate_limit_bytes_written"),
"WriteRateLimitStep bytes written",
WRITE_RATE_LIMIT_STEP_BYTES_WRITTEN.clone(),
);
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
Expand Down Expand Up @@ -165,6 +171,9 @@ pub static POLLING_ERROR_COUNT: Lazy<Family<StepMetricLabels, Counter>> =
pub static WRITE_RATE_LIMIT_STEP_REMAINING_BYTES: Lazy<Family<StepMetricLabels, Gauge>> =
Lazy::new(Family::<StepMetricLabels, Gauge>::default);

pub static WRITE_RATE_LIMIT_STEP_BYTES_WRITTEN: Lazy<Family<StepMetricLabels, Counter>> =
Lazy::new(Family::<StepMetricLabels, Counter>::default);

#[derive(Builder)]
pub struct StepMetrics {
pub labels: StepMetricLabels,
Expand Down

0 comments on commit f2dc006

Please sign in to comment.