-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: create metrics middleware #502
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
Merged
gusinacio
merged 17 commits into
main
from
gustavo/tap-306-create-middleware-for-metrics
Nov 22, 2024
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
347ee76
refactor: create inject_deployment middleware
gusinacio 708092b
refactor: move indexer error to error.rs
gusinacio f4e461d
refactor: add inject receipt middleware
gusinacio 0475bc2
refactor: add inject sender middleware
gusinacio 9e5eb0f
refactor: add inject allocation middleware
gusinacio 05a4eca
refactor: add inject labels middleware
gusinacio 2a1995d
refactor: add metrics middleware
gusinacio 5c6f19e
refactor: add map_watcher
gusinacio d1ac5c4
refactor: add deployment_to_allocation monitor
gusinacio 5851510
refactor: move handler metrics to metrics mod
gusinacio cd4d5cc
refactor: use metrics middleware in request handler
gusinacio e439aef
refactor: use extensions for query
gusinacio 5613baa
refactor: rename metrics to prometheus metrics
gusinacio a209e9b
docs: add documentation to middlewares
gusinacio 73bfe0d
test: update middleware tests
gusinacio 37adb82
docs: add comment on why we dont fail in absense
gusinacio 55c40a9
test: add no labels case
gusinacio 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::collections::HashMap; | ||
| use thegraph_core::{Address, DeploymentId}; | ||
| use tokio::sync::watch::Receiver; | ||
|
|
||
| use indexer_allocation::Allocation; | ||
| use indexer_watcher::map_watcher; | ||
|
|
||
| /// Watcher of indexer allocation | ||
| /// returning a map of subgraph deployment to allocation id | ||
| pub fn deployment_to_allocation( | ||
| indexer_allocations_rx: Receiver<HashMap<Address, Allocation>>, | ||
| ) -> Receiver<HashMap<DeploymentId, Address>> { | ||
| map_watcher(indexer_allocations_rx, move |allocation| { | ||
| allocation | ||
| .iter() | ||
|
Contributor
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. Why not use |
||
| .map(|(address, allocation)| (allocation.subgraph_deployment.id, *address)) | ||
| .collect() | ||
| }) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use tokio::sync::watch; | ||
|
|
||
| use super::deployment_to_allocation; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_deployment_to_allocation() { | ||
| let allocations = test_assets::INDEXER_ALLOCATIONS.clone(); | ||
| let allocations_watcher = watch::channel(allocations.clone()).1; | ||
| let deployment = deployment_to_allocation(allocations_watcher); | ||
|
|
||
| let deployments = deployment.borrow(); | ||
| // one of the allocation id point to the same subgraph | ||
| assert_eq!(deployments.len(), 3); | ||
| // check if all allocations point to the subgraph id | ||
| for (key, val) in deployments.iter() { | ||
| assert_eq!(allocations.get(val).unwrap().subgraph_deployment.id, *key); | ||
| } | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| mod cli; | ||
| mod database; | ||
| mod error; | ||
| mod metrics; | ||
| mod middleware; | ||
| mod routes; | ||
| pub mod service; | ||
| mod tap; | ||
|
|
||
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,39 @@ | ||
| // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use lazy_static::lazy_static; | ||
| use prometheus::{register_counter_vec, register_histogram_vec, CounterVec, HistogramVec}; | ||
|
|
||
| lazy_static! { | ||
| /// Metric registered in global registry for | ||
| /// indexer query handler | ||
| /// | ||
| /// Labels: "deployment", "allocation", "sender" | ||
| pub static ref HANDLER_HISTOGRAM: HistogramVec = register_histogram_vec!( | ||
| "indexer_query_handler_seconds", | ||
| "Histogram for default indexer query handler", | ||
| &["deployment", "allocation", "sender"] | ||
| ).unwrap(); | ||
|
|
||
| /// Metric registered in global registry for | ||
| /// Failed queries to handler | ||
| /// | ||
| /// Labels: "deployment" | ||
| pub static ref HANDLER_FAILURE: CounterVec = register_counter_vec!( | ||
| "indexer_query_handler_failed_total", | ||
| "Failed queries to handler", | ||
| &["deployment"] | ||
| ).unwrap(); | ||
|
|
||
| /// Metric registered in global registry for | ||
| /// Failed receipt checks | ||
| /// | ||
| /// Labels: "deployment", "allocation", "sender" | ||
| pub static ref FAILED_RECEIPT: CounterVec = register_counter_vec!( | ||
| "indexer_receipt_failed_total", | ||
| "Failed receipt checks", | ||
| &["deployment", "allocation", "sender"] | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.