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

Question: How to avoid WARN actix_web_prom: Cannot build mixed cardinality pattern ? #82

Open
helio-frota opened this issue May 13, 2024 · 4 comments

Comments

@helio-frota
Copy link

helio-frota commented May 13, 2024

Hi, I'm excluding swagger-ui but I'm still seeing a warning in logs

let metrics = PrometheusMetricsBuilder::new(namespace.as_ref())
            .registry(registry.into())
            .exclude("/swagger-ui")
            .exclude_regex("/swagger-ui/.*")
            .build();
2024-05-13T14:04:36.844346Z  WARN actix_web_prom: Cannot build mixed cardinality pattern "/swagger-ui/{_:.*}"
2024-05-13T14:04:36.850008Z  WARN actix_web_prom: Cannot build mixed cardinality pattern "/swagger-ui/{_:.*}"

Am I using the correct approach? thanks

@helio-frota
Copy link
Author

helio-frota commented May 13, 2024

Hi I noticed that it successfully excludes the paths, but continues showing the warning in logs
trustification/trustify#261 (comment)

@nlopes
Copy link
Owner

nlopes commented Aug 24, 2024

Hi @helio-frota,

Can you try to point your branch at main of actix-web-prom?

I just pushed the change below (I've linked the code entry) which should give me better visibility on the problem. As it stands it seems that the warning is appearing because the params passed to the endpoint aren't parsed properly but this should help.

warn!("Cannot build mixed cardinality pattern {full_pattern}, with params {params:?}");

@helio-frota
Copy link
Author

@nlopes hi,

thanks for the feedback, I found the place where this happened https://github.com/nlopes/actix-web-prom/pull/83/files
but I closed the PR since that was not a good way to fix

@lefuturiste
Copy link
Contributor

lefuturiste commented Aug 29, 2024

Hi @helio-frota,

Can you try to point your branch at main of actix-web-prom?

I just pushed the change below (I've linked the code entry) which should give me better visibility on the problem. As it stands it seems that the warning is appearing because the params passed to the endpoint aren't parsed properly but this should help.

warn!("Cannot build mixed cardinality pattern {full_pattern}, with params {params:?}");

Okay I think this is my fault, in code introduced in #73.

The root issue is in the code that build a mixed pattern:

The full_pattern variable is populated from req.match_pattern() and my code is expecting to only have simple brace expression with only simple identifier.
The full_pattern is then passed to the strfmt crate that of course doesn't accept any wild card patterns like in the route matching pattern "/swagger-ui/{_:.*}"

The issue is that the way we parse the match pattern with strfmt is different that the way that actix-web parse it.
The current code is a crappy workaround because actix-web doesn't expose the parsed match pattern.
So may be we should review if we can use or call the code in actix-web that parse the match pattern.

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

No branches or pull requests

3 participants