-
Notifications
You must be signed in to change notification settings - Fork 396
feat(aggregation-mode): scrap metrics with prometheus and visualize via Grafana dashboard #2218
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
Merged
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a51d8f7
feat(aggregation-mode): add grafana dashboard
maximopalopoli 94c0404
fix: return BadRequest for the request denied exams
maximopalopoli 9ce4dde
Update the dashboard to include code ranges (2xx, 4xx, 5xx)
maximopalopoli 531e929
Filter by range in dashboards and remove the /metrics reqs in 2xx one
maximopalopoli 61f889a
Add time_elapsed_db_post metric to have a metric in use
maximopalopoli 00d5338
Add the payments poller metrics integration
maximopalopoli 77fc789
fix clippy lints on agg mode
maximopalopoli 710ff46
Remove unnecessary labeling on actix prometheus metrics builder
maximopalopoli 3aeb64a
use tracing::error instead of eprintln
maximopalopoli 07eb91b
Remove anyhow dependency
maximopalopoli dad51de
Convert the warp servers into
maximopalopoli 09cc63c
Merge branch 'staging' into feataggmode/add-grafana-dashboard
maximopalopoli deaa77a
Add comment about the actix http prometheus server
maximopalopoli 09eb015
Return an Arc in the Metrics structs start method
maximopalopoli 7ee8201
Make the time_elapsed_db_query to be a histogram vec
maximopalopoli b50ebb4
Change the actix prometheus version to the latest stable
maximopalopoli 2aa1550
Fix expression in grafana dashboard to match the rate interval instea…
maximopalopoli c38b398
Merge branch 'staging' into feataggmode/add-grafana-dashboard
maximopalopoli f4696d8
update the grafana dashboard timeline queries
maximopalopoli 816e710
Improve naming on time elapsed vars of http server
maximopalopoli c00abcd
simplify the name for the prometheus jobs and bots for agg mode
maximopalopoli c608dc2
update the agg mode dash with the new names
maximopalopoli 3281d07
Merge branch 'staging' into feataggmode/add-grafana-dashboard
maximopalopoli 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
Large diffs are not rendered by default.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ pub mod config; | |
| pub mod db; | ||
| mod helpers; | ||
| pub mod http; | ||
| mod metrics; | ||
| mod types; | ||
| mod verifiers; | ||
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,54 @@ | ||
| use prometheus::{self, histogram_opts, register_histogram}; | ||
| use warp::{reject::Rejection, reply::Reply, Filter}; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct GatewayMetrics { | ||
| pub time_elapsed_db_post: prometheus::Histogram, | ||
| } | ||
|
|
||
| impl GatewayMetrics { | ||
| pub fn start(metrics_port: u16) -> anyhow::Result<Self> { | ||
| let registry = prometheus::Registry::new(); | ||
|
|
||
| let time_elapsed_db_post = register_histogram!(histogram_opts!( | ||
| "time_elapsed_db_post", | ||
| "Time elapsed in DB posts" | ||
| ))?; | ||
|
|
||
| registry.register(Box::new(time_elapsed_db_post.clone()))?; | ||
|
|
||
| let metrics_route = warp::path!("metrics") | ||
| .and(warp::any().map(move || registry.clone())) | ||
| .and_then(GatewayMetrics::metrics_handler); | ||
|
|
||
| tokio::task::spawn(async move { | ||
| warp::serve(metrics_route) | ||
| .run(([0, 0, 0, 0], metrics_port)) | ||
| .await; | ||
| }); | ||
|
|
||
| Ok(Self { | ||
| time_elapsed_db_post, | ||
| }) | ||
| } | ||
|
|
||
| pub async fn metrics_handler(registry: prometheus::Registry) -> Result<impl Reply, Rejection> { | ||
| use prometheus::Encoder; | ||
| let encoder = prometheus::TextEncoder::new(); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| if let Err(e) = encoder.encode(®istry.gather(), &mut buffer) { | ||
| eprintln!("could not encode prometheus metrics: {e}"); | ||
|
MarcosNicolau marked this conversation as resolved.
Outdated
|
||
| }; | ||
| let res = String::from_utf8(buffer.clone()) | ||
| .inspect_err(|e| eprintln!("prometheus metrics could not be parsed correctly: {e}")) | ||
| .unwrap_or_default(); | ||
| buffer.clear(); | ||
|
|
||
| Ok(res) | ||
| } | ||
|
|
||
| pub fn register_db_response_time_post(&self, value: f64) { | ||
| self.time_elapsed_db_post.observe(value); | ||
| } | ||
| } | ||
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,4 +1,5 @@ | ||
| pub mod config; | ||
| pub mod db; | ||
| pub mod metrics; | ||
| pub mod payments; | ||
| pub mod types; |
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,54 @@ | ||
| use prometheus::{self, opts, register_gauge}; | ||
| use warp::{reject::Rejection, reply::Reply, Filter}; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct PaymentsPollerMetrics { | ||
| pub last_processed_block: prometheus::Gauge, | ||
| } | ||
|
|
||
| impl PaymentsPollerMetrics { | ||
| pub fn start(metrics_port: u16) -> anyhow::Result<Self> { | ||
| let registry = prometheus::Registry::new(); | ||
|
|
||
| let last_processed_block = register_gauge!(opts!( | ||
| "last_processed_block", | ||
| "Last processed block by poller" | ||
| ))?; | ||
|
|
||
| registry.register(Box::new(last_processed_block.clone()))?; | ||
|
|
||
| let metrics_route = warp::path!("metrics") | ||
| .and(warp::any().map(move || registry.clone())) | ||
| .and_then(PaymentsPollerMetrics::metrics_handler); | ||
|
|
||
| tokio::task::spawn(async move { | ||
| warp::serve(metrics_route) | ||
| .run(([0, 0, 0, 0], metrics_port)) | ||
| .await; | ||
| }); | ||
|
|
||
| Ok(Self { | ||
| last_processed_block, | ||
| }) | ||
| } | ||
|
|
||
| pub async fn metrics_handler(registry: prometheus::Registry) -> Result<impl Reply, Rejection> { | ||
| use prometheus::Encoder; | ||
| let encoder = prometheus::TextEncoder::new(); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| if let Err(e) = encoder.encode(®istry.gather(), &mut buffer) { | ||
| eprintln!("could not encode prometheus metrics: {e}"); | ||
| }; | ||
| let res = String::from_utf8(buffer.clone()) | ||
| .inspect_err(|e| eprintln!("prometheus metrics could not be parsed correctly: {e}")) | ||
| .unwrap_or_default(); | ||
| buffer.clear(); | ||
|
|
||
| Ok(res) | ||
| } | ||
|
|
||
| pub fn register_last_processed_block(&self, value: u64) { | ||
| self.last_processed_block.set(value as f64); | ||
| } | ||
| } |
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
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.