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

Option to map "path" to something else #20

Closed
kodieg opened this issue Mar 13, 2020 · 4 comments · Fixed by #30
Closed

Option to map "path" to something else #20

kodieg opened this issue Mar 13, 2020 · 4 comments · Fixed by #30

Comments

@kodieg
Copy link

kodieg commented Mar 13, 2020

I have an endpoint that is parametrized with and entity id

#[get("/get/{id}")]
async fn get(...) -> impl Responder {}

Using PrometheusMetric middleware I get different metric for each id (because thay make different path). Would be great to have an option to somehow map real path to /get/{id} or something. I'm not sure if it's feasible to automatically find mapping provided in get/post/... macros. However, maybe it would be enough to add option to provide custom function to modify path for purposes of storing metrics.

Maybe something like (or something similar) could work:

   fn map_fn<'a>(path: &'a str) -> Cow<'a, str> {
       ...
   }
   let prometheus = PrometheusMetrics::new("api", Some("/metrics"), None, map_fn);

Is there an option to add such functionality? Would that make sens or is there any better option?

@nazar-pc
Copy link
Contributor

Created upstream ticket to expose API necessary to implement essential fix for this efficiently: actix/actix-web#1565

@nlopes
Copy link
Owner

nlopes commented Jun 16, 2020

Thank you for doing this @nazar-pc.

@nazar-pc
Copy link
Contributor

Implemented upstream and should be a part of some future release of actix-web

@nazar-pc
Copy link
Contributor

nazar-pc commented Sep 9, 2020

I think with dependency on actix-web 3.0 it makes sense to switch to new API from actix/actix-web#1565

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 a pull request may close this issue.

3 participants