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

Remove framework-specific route detection from collector middleware #251

Merged
merged 2 commits into from Mar 24, 2022

Conversation

Sinjo
Copy link
Member

@Sinjo Sinjo commented Mar 8, 2022

Sadly, with the benefit of hindsight, this wasn't a good idea.

There are two reasons we're dropping this:

  • It doesn't play nicely with libraries like Rack::Builder, which
    dispatches requests to different Rack apps based on a path prefix in
    a way that isn't visible to middleware.

    For example, when using Rack::Builder, sinatra.route only
    contains the parts of the path after the prefix that Rack::Builder
    used to dispatch to the specific app, and doesn't leave any
    information in the request environment to indicate which prefix it
    dispatched to.

  • It turns out framework-specific route info isn't always formatted in
    a way that looks good in a Prometheus label.

    For example, when using regex-based route-matching in Sinatra, you
    can end up with labels that look like \\/vapes\\/([0-9]+)\\/?.

For a really detailed dive into those two issues, see this GitHub
comment:

#249 (comment)

Fixes #249

@Sinjo Sinjo force-pushed the sinjo-remove-framework-specific-routing branch from 20a21e7 to a26ae7d Compare March 8, 2022 23:14
@Sinjo Sinjo requested a review from dmagliola March 8, 2022 23:19
Sadly, with the benefit of hindsight, this wasn't a good idea.

There are two reasons we're dropping this:

  - It doesn't play nicely with libraries like `Rack::Builder`, which
    dispatches requests to different Rack apps based on a path prefix in
    a way that isn't visible to middleware.

    For example, when using `Rack::Builder`, `sinatra.route` only
    contains the parts of the path after the prefix that `Rack::Builder`
    used to dispatch to the specific app, and doesn't leave any
    information in the request environment to indicate which prefix it
    dispatched to.
  - It turns out framework-specific route info isn't always formatted in
    a way that looks good in a Prometheus label.

    For example, when using regex-based route-matching in Sinatra, you
    can end up with labels that look like `\\/vapes\\/([0-9]+)\\/?`.

For a really detailed dive into those two issues, see this GitHub
comment:

#249 (comment)

Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
@Sinjo Sinjo force-pushed the sinjo-remove-framework-specific-routing branch from a26ae7d to e0dd0f9 Compare March 9, 2022 12:16
Copy link
Collaborator

@dmagliola dmagliola left a comment

Choose a reason for hiding this comment

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

Should we document this new idea that if you want specific path labeing, the way to go is subclassing the Collector and adding your class as the middleware instead?

@Sinjo
Copy link
Member Author

Sinjo commented Mar 23, 2022

Sure thing. Maybe a slight rearrange of this doc to emphasise that you can customise path in its entirety?

@dmagliola
Copy link
Collaborator

Yeah, that sounds perfect.

@Sinjo Sinjo force-pushed the sinjo-remove-framework-specific-routing branch from 1533fbd to 1dfc1ad Compare March 23, 2022 22:46
Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
@Sinjo
Copy link
Member Author

Sinjo commented Mar 23, 2022

All done!

Copy link
Collaborator

@dmagliola dmagliola left a comment

Choose a reason for hiding this comment

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

Awesome, thank you

@Sinjo Sinjo merged commit e2afbe7 into master Mar 24, 2022
@Sinjo Sinjo deleted the sinjo-remove-framework-specific-routing branch March 24, 2022 13:20
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.

generate_path yields incorrect values for Sinatra+Rack::Build apps
2 participants