-
Notifications
You must be signed in to change notification settings - Fork 6
feat(common): add eth_call udf observability #2029
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
Open
shiyasmohd
wants to merge
1
commit into
main
Choose a base branch
from
shiyasmohd/eth-call-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| mod cache; | ||
| mod metrics; | ||
| mod udf; | ||
|
|
||
| pub use cache::{EthCallForNetworkError, EthCallUdfsCache}; | ||
| pub use metrics::{EthCallErrorClass, EthCallMetrics}; | ||
| pub use udf::EthCall; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| //! Metrics for eth_call UDF observability. | ||
|
|
||
| use monitoring::telemetry::metrics::{Counter, Histogram, KeyValue, Meter}; | ||
|
|
||
| /// Error classification for eth_call metrics. | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum EthCallErrorClass { | ||
| /// JSON-RPC error codes 3 or -32000 (non-retryable). | ||
| RpcErrorNonRetryable, | ||
| /// All retry attempts exhausted. | ||
| RpcErrorRetryExhausted, | ||
| /// Request timed out. | ||
| Timeout, | ||
| /// Invalid arguments (bad address, calldata, block). | ||
| InvalidRequest, | ||
| /// No provider configured for the requested network. | ||
| NetworkNotConfigured, | ||
| /// Unclassified error. | ||
| Other, | ||
| } | ||
|
|
||
| impl EthCallErrorClass { | ||
| /// Returns the string label used in metric attributes. | ||
| pub fn as_str(&self) -> &'static str { | ||
| match self { | ||
| Self::RpcErrorNonRetryable => "rpc_error_non_retryable", | ||
| Self::RpcErrorRetryExhausted => "rpc_error_retry_exhausted", | ||
| Self::Timeout => "timeout", | ||
| Self::InvalidRequest => "invalid_request", | ||
| Self::NetworkNotConfigured => "network_not_configured", | ||
| Self::Other => "other", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Metrics registry for eth_call UDF observability. | ||
| #[derive(Debug, Clone)] | ||
| pub struct EthCallMetrics { | ||
| /// Total eth_call UDF invocations. | ||
| requests_total: Counter, | ||
| /// Wall-clock latency including retries (milliseconds). | ||
| latency_ms: Histogram<f64>, | ||
| /// Failed invocations by error class. | ||
| errors_total: Counter, | ||
| /// Individual retry attempts. | ||
| retries_total: Counter, | ||
| } | ||
|
|
||
| impl EthCallMetrics { | ||
| /// Creates a new metrics registry from the given meter. | ||
| pub fn new(meter: &Meter) -> Self { | ||
| Self { | ||
| requests_total: Counter::new( | ||
| meter, | ||
| "eth_call_requests_total", | ||
| "Total number of eth_call UDF invocations", | ||
| ), | ||
| latency_ms: Histogram::new_f64( | ||
| meter, | ||
| "eth_call_latency_ms", | ||
| "Wall-clock latency of eth_call including retries", | ||
| "milliseconds", | ||
| ), | ||
| errors_total: Counter::new( | ||
| meter, | ||
| "eth_call_errors_total", | ||
| "Total number of failed eth_call invocations", | ||
| ), | ||
| retries_total: Counter::new( | ||
| meter, | ||
| "eth_call_retries_total", | ||
| "Total number of eth_call retry attempts", | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| /// Record a single eth_call request. | ||
| pub(crate) fn record_request(&self, network: &str, provider: &str) { | ||
| self.requests_total | ||
| .inc_with_kvs(&self.base_kvs(network, provider)); | ||
| } | ||
|
|
||
| /// Record wall-clock latency for a completed invocation. | ||
| pub(crate) fn record_latency(&self, latency_ms: f64, network: &str, provider: &str) { | ||
| self.latency_ms | ||
| .record_with_kvs(latency_ms, &self.base_kvs(network, provider)); | ||
| } | ||
|
|
||
| /// Record a failed invocation with the given error class. | ||
| pub(crate) fn record_error(&self, network: &str, provider: &str, class: EthCallErrorClass) { | ||
| let kvs = [ | ||
| KeyValue::new("network", network.to_string()), | ||
| KeyValue::new("provider", provider.to_string()), | ||
| KeyValue::new("class", class.as_str().to_string()), | ||
| ]; | ||
| self.errors_total.inc_with_kvs(&kvs); | ||
| } | ||
|
|
||
| /// Record a single retry attempt. | ||
| pub(crate) fn record_retry(&self, network: &str, provider: &str) { | ||
| self.retries_total | ||
| .inc_with_kvs(&self.base_kvs(network, provider)); | ||
| } | ||
|
|
||
| fn base_kvs(&self, network: &str, provider: &str) -> [KeyValue; 2] { | ||
| [ | ||
| KeyValue::new("network", network.to_string()), | ||
| KeyValue::new("provider", provider.to_string()), | ||
| ] | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this error enum in the metrics module? Shouldn't it be co-located with the logic reporting this error?
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.
Actually, why isn't this deriving
thiserror::Error?