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

WIP: feat(metrics): add actix-web metrics exporter #793

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lefuturiste
Copy link

For a starter, we can only include the basics metrics from the actix web prom crate.

as discussed in #773

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

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

this looks fine, and I read your discussion in nlopes/actix-web-prom#72 - but still not certain I understood the resolution of the problem -- would it make sense for the middleware to have an extra API to override path param to convert from /srcA,srcB/1/1/1 to srcA,srcB (but at the same time ignore the tilejson request /srcA,srcB? Should this be some magical attribute?


// labels.insert("label_foo".to_string(), "value_barbarbbabbmiles".to_string());
let prometheus = PrometheusMetricsBuilder::new("martin")
.endpoint("/metrics")
Copy link
Member

Choose a reason for hiding this comment

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

if we start handling /metrics, we would have to declare this as a reserved keyword (we might be missing docs in a martin book for this). One workaround perhaps would be to add everything "magical" to the /_/metrics style prefixes because _ is not a valid source ID i think.

/// List of keywords that cannot be used as source IDs. Some of these are reserved for future use.
/// Reserved keywords must never end in a "dot number" (e.g. ".1")
pub const RESERVED_KEYWORDS: &[&str] = &[
"catalog", "config", "font", "health", "help", "index", "manifest", "refresh", "reload",
"sprite", "status",
];

Copy link
Author

Choose a reason for hiding this comment

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

if we start handling /metrics, we would have to declare this as a reserved keyword (we might be missing docs in a martin book for this). One workaround perhaps would be to add everything "magical" to the /_/metrics style prefixes because _ is not a valid source ID i think.

/// List of keywords that cannot be used as source IDs. Some of these are reserved for future use.
/// Reserved keywords must never end in a "dot number" (e.g. ".1")
pub const RESERVED_KEYWORDS: &[&str] = &[
"catalog", "config", "font", "health", "help", "index", "manifest", "refresh", "reload",
"sprite", "status",
];

Right, as you wish, I'm fine with both solutions (the reserved keyword and the /_/metrics workaround). We just have to keep in mind that /metrics is the standard path and the default, so the second solution would mean a little bit more config on the scraper side.

Copy link
Member

Choose a reason for hiding this comment

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

good point about conventions (actually, didn't we talk about it elsewhere?), i'm ok to add /metrics to reserved then

@lefuturiste
Copy link
Author

this looks fine, and I read your discussion in nlopes/actix-web-prom#72 - but still not certain I understood the resolution of the problem -- would it make sense for the middleware to have an extra API to override path param to convert from /srcA,srcB/1/1/1 to srcA,srcB (but at the same time ignore the tilejson request /srcA,srcB? Should this be some magical attribute?

I don't really what you are saying, the issue is with the variance of /srcA,srcB, could also be /srcB,srcA (I suppose)
So probably the best thing to do is to have a magical callback that is defined on the maplibre side, that take the request parameter and request path and return the path for metrics. So the business logic stay downstream and not defined in the lib.
But, I don't recall that we settled on a solution yet.

@lefuturiste lefuturiste marked this pull request as draft August 4, 2023 07:58
@nyurik
Copy link
Member

nyurik commented Aug 5, 2023

this looks fine, and I read your discussion in nlopes/actix-web-prom#72 - but still not certain I understood the resolution of the problem -- would it make sense for the middleware to have an extra API to override path param to convert from /srcA,srcB/1/1/1 to srcA,srcB (but at the same time ignore the tilejson request /srcA,srcB? Should this be some magical attribute?

I don't really what you are saying, the issue is with the variance of /srcA,srcB, could also be /srcB,srcA (I suppose) So probably the best thing to do is to have a magical callback that is defined on the maplibre side, that take the request parameter and request path and return the path for metrics. So the business logic stay downstream and not defined in the lib. But, I don't recall that we settled on a solution yet.

Are you sure its a big deal to collapse /srcA,srcB and /srcB,srcA into one? I wouldn't worry too much about this tbh... Worst case - can later add some sort of a collapser, e.g. /srcA+ would mean everything with srcA as the first layer, plus any number of other layers mixed in. The collapser could even be configurable to how many sources to keep, e.g. 0 -- /+ means all multi-sourced requests, or 2 would create /srcA,srcB and /srcA,srcB+ metrics

@lefuturiste
Copy link
Author

this looks fine, and I read your discussion in nlopes/actix-web-prom#72 - but still not certain I understood the resolution of the problem -- would it make sense for the middleware to have an extra API to override path param to convert from /srcA,srcB/1/1/1 to srcA,srcB (but at the same time ignore the tilejson request /srcA,srcB? Should this be some magical attribute?

I don't really what you are saying, the issue is with the variance of /srcA,srcB, could also be /srcB,srcA (I suppose) So probably the best thing to do is to have a magical callback that is defined on the maplibre side, that take the request parameter and request path and return the path for metrics. So the business logic stay downstream and not defined in the lib. But, I don't recall that we settled on a solution yet.

Are you sure its a big deal to collapse /srcA,srcB and /srcB,srcA into one? I wouldn't worry too much about this tbh... Worst case - can later add some sort of a collapser, e.g. /srcA+ would mean everything with srcA as the first layer, plus any number of other layers mixed in. The collapser could even be configurable to how many sources to keep, e.g. 0 -- /+ means all multi-sourced requests, or 2 would create /srcA,srcB and /srcA,srcB+ metrics

yes, you right, for now, let's not worry about this issue, will deal with that later.

@nyurik
Copy link
Member

nyurik commented Aug 13, 2023

@lefuturiste i added metrics to reserved in #802 , let me know if you need any help with this PR

nyurik added a commit that referenced this pull request Aug 13, 2023
minor change to allow for #793
@nyurik
Copy link
Member

nyurik commented Aug 27, 2023

@lefuturiste any updates? thx

@lefuturiste
Copy link
Author

lefuturiste commented Sep 6, 2023

@lefuturiste any updates? thx

Hi!
I've updated upstream PR for this, because I really want to have path cardinality (idk really why an obsession may be 😄 ), nlopes/actix-web-prom#73
I awaiting response from actix-web-prom dev.

@lefuturiste
Copy link
Author

while i'm awaiting for a response from the actix-web-prom developer I will explore the instrumentation of postgresql connexion.

@lefuturiste
Copy link
Author

The PR at nlopes/actix-web-prom#73 was merged today. So we can go forward from there.

@nyurik
Copy link
Member

nyurik commented Dec 1, 2023

exciting, thanks, let me know if you need any help

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.

None yet

2 participants