Skip to content

feat: allow patterns#86

Merged
Ptrskay3 merged 3 commits intoPtrskay3:masterfrom
pbstck:allow-patterns
Jun 30, 2025
Merged

feat: allow patterns#86
Ptrskay3 merged 3 commits intoPtrskay3:masterfrom
pbstck:allow-patterns

Conversation

@erwanncloarec
Copy link
Copy Markdown
Contributor

@erwanncloarec erwanncloarec commented Jun 20, 2025

This is a proposal to resolve the following issue:

This is my first contribution, please let me know if there's anything I can do 🙏

I tested on a small project like this:

let (prometheus_layer, metric_handle) = PrometheusMetricLayerBuilder::new()
        .with_default_metrics()
        .with_allow_patterns(&["/hello", "/hola", "/hi", "/hi/hi", "/hi/{other}"])
        .with_group_patterns_as("/hi", &["/hi/hi", "/hi/{other}"])
        .build_pair();

    // Build our application with a route and the metrics endpoint
    let router = Router::new()
        .route("/hello", get(hello_world))
        .route("/hola", get(hello_world))
        .route("/hi", get(hello_world))
        .route("/hi/hi", get(hello_world))
        .route("/hi/{other}", get(hello_world))
        .route("/metrics", get(|| async move { metric_handle.render() }))
        .layer(ServiceBuilder::new().layer(prometheus_layer));

With the following calls:

#!/bin/sh

curl localhost:8000/hello
curl localhost:8000/hello
curl localhost:8000/hello
curl localhost:8000/hola
curl localhost:8000/hola
curl localhost:8000/hi
curl localhost:8000/hi/hi
curl localhost:8000/hi/tomato

curl localhost:8000/.aws/credentials
curl localhost:8000/.aws/credentials
curl localhost:8000/.aws/credentials
curl localhost:8000/sqdokqsdk
curl localhost:8000/:sqdqsd
curl localhost:8000/azerty

I've got those metrics:
image

@Ptrskay3
Copy link
Copy Markdown
Owner

Thanks, looks good from first glance. I'll probably have to time review it properly this weekend.

Copy link
Copy Markdown
Owner

@Ptrskay3 Ptrskay3 left a comment

Choose a reason for hiding this comment

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

Just a nit, but looks good. Thanks!

Do you want to add this to the changelog as well?

@Ptrskay3 Ptrskay3 merged commit 7fa6da3 into Ptrskay3:master Jun 30, 2025
5 checks passed
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.

2 participants