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

refactor(rpc-server): Split error metrics to disambiguate the error reasons #98

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

khorolets
Copy link
Member

Resolves #97

What this PR is about?

In this PR my goal was to disambiguate the error counters to reflect different (known) reasons for the errors. I achieve this by renaming the existing metrics and adding the code as a suffix.

Yeah, I am aware of the antipattern of "magic numbers", but I want to keep the metric names shorter. Here's the list of the available codes (also, I've added this info to the rpc-server README).

  • 0 - ReadRPC returns a Success result, and NEAR RPC returns a Success result, but the results don't match
  • 1 - ReadRPC returns Success result, and NEAR RPC returns an Error result
  • 2 - ReadRPC returns an Error result, and NEAR RPC returns Success result
  • 3 - ReadRPC returns an Error result, and NEAR RPC returns an Error result, but the results don't match
  • 4 - Could not perform consistency check because of the error (either network or parsing the results)

So for the block method, the metric with error code 0 will look like this BLOCK_ERROR_0.

Things I want to draw your attention to

All the changes in this PR work only with the shadow_data_consistency feature flag and don't affect the other sides of the project.

FYI while renaming metrics, I've reached some limits of lazy_static, so I had to group the static refs of the metrics to a separate lazy_static! {} "containers".

To keep the code cleaner and follow the DRY principle, I introduced a macro capture_shadow_consistency_error! that handles the ShadowConsistencyError:

  • Captures the error variant
  • Emits a proper log message based on the variant and subvariants of the error

This PR also contains a small change to the docker-compose.yml, but that is just an improvement since we got rid of the ridiculous log target is_data_consistency in favor of the shadow_data_consistency similar to the feature name.

And yeah, merging this PR will break the existing ReadRPC dashboard, I am going to redo it afterward.

Copy link
Collaborator

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

this PR will break the existing ReadRPC dashboard

Which one?

There's a more elegant way to create all these counters (e.g. using arrays should make this PR ~5 times shorter, we anyway use magic constants)
But I'm fine with the current approach if it solves the problem

rpc-server/README.md Outdated Show resolved Hide resolved
DataMismatchReason::ReadRpcSuccessNearRpcSuccess => 0,
DataMismatchReason::ReadRpcSuccessNearRpcError => 1,
DataMismatchReason::ReadRpcErrorNearRpcSuccess => 2,
DataMismatchReason::ReadRpcErrorNearRpcError => 3,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Haven't you missed the last option here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, number 4 is for other reason of error, it's not related to the DataMismatchReason

crate::utils::capture_shadow_consistency_error!(
err,
error_meta,
"EXPERIMENTAL_TX_STATUS"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: last arg could be enum to avoid typos

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, though we can improve it later.

// QUERY counters
lazy_static! {
// QUERY.view_account
pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_0: IntCounter = try_create_int_counter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't we need to mark all this with the feature flag as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean we could, though it's not that big of a trouble.

Co-authored-by: Olga Telezhnaya <olyatelezhnaya@gmail.com>
@khorolets
Copy link
Member Author

@telezhnaya

There's a more elegant way to create all these counters (e.g. using arrays should make this PR ~5 times shorter, we anyway use magic constants)

Could you elaborate on arrays, I believe my knowledge of Prometheus is too weak. If you feel inspired enough, could you fire a separate issue about improvements (arrays)?

@telezhnaya
Copy link
Collaborator

I meant arrays on Rust side

@khorolets khorolets merged commit d1707e6 into main Aug 10, 2023
3 checks passed
@kobayurii kobayurii deleted the refactor/disambiguate-metric-errors branch December 20, 2023 14:02
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.

Split error metrics to disambiguate the reason
2 participants