-
Notifications
You must be signed in to change notification settings - Fork 149
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
better path handling #233
Comments
Hello, sorry for my late response! Our general recommended approach with the For this case, it'd probably be easiest to subclass the one provided with the gem and override the With respect to your suggestion, we tried in the past making this more configurable through parameters, and it invariable became a messy pile of indirection which was very hard to understand, and which ended up providing very little benefit for an object that does so little work, and which invariable ended up requiring more customization. We think it's better to provide a simple one that you can either use as-is, if it works for you, or that is very easy to understand if you need to use it as a starting point to make your own. Hope that helps! |
Thank you for taking the time to answer I'd like to try and challenge the assumption that your argument relies on: that this is a "custom" and very specific use case I'm referring to in my issue. I think that this kind of behavior is what I would have expected from the ruby client by default. Taking the matching route pattern as-is makes zero assumptions on the clients needs where the current implementation applies pre defined logic trying to guesstimate :id and :uuid in the actual path, enforcing users to repeatedly override it just to avoid their route patterns being altered on the monitoring dashboard. Personally I was very surprised by the fact that the Prometheus library applies such a logic to my routes as a default behavior. Another point I would like make is that the current solution uses logic to replace actual path parts with path variables like :id and :uuid but might miss a lot of the cases where the path part does not match the regular expression So to sum it up I would say the current behavior is the custom one whereas my suggestion applies zero logic to the matched route pattern and as such is more predictable from client's perspective. Would love to hear your opinion and thanks for the answer again |
Thank you for coming back to this. I've started looking at this a bit deeper, and I think I understand what you're asking for a bit better. I have two comments:
Basically, in my mind, any part of the path that is a number delimited by slashes should be turned to So I think we should fix the Regex to pick up all these groups of numbers delimited by slashes, and replace all of them with The Regex in question: The problem with this is that it consumes the second slash, so the next numerical parameter doesn't match anymore. If we change the regex to Example:
I propose that we change the Regex to do that, so that all "number parts" in the string will be recognized as an @Sinjo what do you think about this second proposed change? |
thanks for opening this issue again
I'll try to check regarding 1 and update here if I find anything we can use |
@dmagliola so I checked it on the sinatra repo and there's a {"sinatra.route"=>"GET /add/:num_a/:num_b"} we can use this path pattern for the path value when reporting to prometheus instead of reverse-engineering the path pattern given an actual path what do you think? |
Is there an equivalent for Rails? @Sinjo do you have any thoughts? |
I think it would be nice to do something like this on a best-effort basis (obviously dependant on us being provided the route that matched by the web framework). Given Rails' popularity it would be awesome to have similar support for it built in. I'm not sure off the top of my head if it injects anything like this into I'm not sure if there are other frameworks worth supporting? Do people use Grape or Hanami in significant enough numbers for us to try and add those? |
Oh, to be clear: even if we can't find anything similar for Rails I still think we should make it nicer for Sinatra. I don't think most people spend their days switching between the two, so it doesn't seem like it would be all that jarring. We can always ask the Rails team/send a PR as a proposal to them to inject this info. |
@dmagliola So I've been playing around with this a bit. I think that what @erez-rabih has suggested is the best solution for Sinatra and we should go ahead with that for 3.0.0 (i.e. squeeze this in while we're making other breaking changes). I've had a bit of a play with a sample Rails app, and I can't see anything similar in "action_dispatch.request.path_parameters": {
"controller": "example",
"action": "show",
"id": "7"
}, but I can't see anything would give us the original route definition. In digging into this, I did notice something about our implementation of
I'm not sure if this was intentional, but if not I can definitely see how we ended up here. Most URL paths for show routes are made up of either a single resource followed by an ID, or an alternating pattern of My current leaning is:
|
I decided to have a look at Grape, since it's easy enough to set a small app up. It looks like there is an equivalent we can do there if we particularly feel like it, but it's a little less direct than the Sinatra one:
|
I also tried Hanami, and their app generator throws an exception, and that is exactly how much time I am willing to give it:
|
@dmagliola Oh, I'd totally skipped over your second point in this comment before investigating our regex and coming to the same conclusion. 🙈 I don't feel all that strongly either way about it. It's maybe a slight improvement to the heuristic we use, but we're getting deeper into guesswork territory about people's route structures. |
After a quick chat with @dmagliola, we've agreed on the following:
We're going to slightly delay 3.0.0 to get this in. I'll hopefully have time to make a PR some time this week and we can cut a release soon after that's merged. |
Everything we can implement at the moment is in #245, and I've opened a thread on the rubyonrails-core discussion board. |
I'm trying to use the collector rack middleware with a sinatra app
I have a simple endpoint
/add/:num_a/:num_b
that takes num_a and num_b and returns their sumThe path label value generated by the collector middleware for that route is
path="/add/:id/5
,path="/add/:id/3
...I think a batter solution would be to take the matching route pattern and use it as the path value, in my case, I'd expect to have
path="/add/:num_a/:num_b
any thoughts about that?
The text was updated successfully, but these errors were encountered: