-
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
Include SCRIPT_NAME when determining path #197
Conversation
When determining the path for a request, `Rack::Request` prefixes the `SCRIPT_NAME`, [as seen here][1]. This makes sure the relative path is included. At work, we use [Iodine](https://github.com/boazsegev/iodine) and Turbolinks, and without this patch most of our requests paths in Promethus are `""`. This patch fixes that. [1]: https://github.com/rack/rack/blob/294fd239a71aab805877790f0a92ee3c72e67d79/lib/rack/request.rb#L512 Signed-off-by: Ian Ker-Seymer <i.kerseymer@gmail.com>
69ecb70
to
aa41f5f
Compare
Signed-off-by: Ian Ker-Seymer <i.kerseymer@gmail.com>
c6cb3c3
to
f50ee67
Compare
Hi Ian, We provide this middleware as a sort of "example" / starting point on how to collect Rack metrics. We know it doesn't cater for every use case, and we encourage people to use it as a base to make their own version, if this one doesn't suit. Documented here We, for example, don't use this one, we have our own version that is quite similar, but does a few more checks on the path before exposing metrics. I'm not sure your change is generic enough that it will work for everyone, and won't break existing working cases. This may be a backwards incompatible change, for example, in which case i'm not too keen on adding this. For this use case, i'd encourage you to copy this collector into your codebase, and make these modifications in your project, rather than upstream in the gem. As for the second commit... (I consider this a separate change completely, worth discussing individually) Are you just reducing duplication there? Or is this actually measurably faster than what the existing code does? (i'm not sure which meaning of "optimize" you're going for in the commit message) Maybe we should extract the call to Thanks! |
I would imagine for a lot of people, the current implementation would not have the expected behavior. Also, pulling this into our codebase is not ideal for a couple of reasons:
This is a good point. Would you be willing to merge a backwards compatible version that took an option to mimic
I was just removing the rendundant call to |
We haven't heard other cases of this particular behaviour being an issue, and we do encourage making your own collector if you have special needs.
In my opinion, it's not a huge amount of code to bring in. We're doing it at our company and haven't had an issue with it.
That is indeed annoying. One option might be to make a small gem with just the collector, maybe
My concern is I don't see how we can have a backwards-compatible version, which simultaneously behaves the same as the current code, and also fixes your issue. I feel like i'm missing something here.
Have you measured what kind of actual performance impact this has? Unless it's a measurable difference, I think the existing code is much more readable. To clarify: I don't mean measuring just the two ways of generating those hashes, I mean measuring that as part of actual Rack requests, because even if one version is 100 times faster, if the simpler-to-read code is taking an insignificant amount of time in the context of a Rack request, then I still think we should keep the more readable code. |
A contributor opened another PR (#204) to address this same issue. Some supporting evidence that this may be the way to go (from their PR's description): https://github.com/rack/rack/blob/master/lib/rack/handler/webrick.rb#L92 |
Given now that there are multiple PRs attempting to address this issue, it makes me wonder how many have encountered the issue and haven't PR'd 😄 Would you consider including this change in the next major release? |
Ok, we've finally had time to look into this enough to convince ourselves this is definitely the right thing to do. I'm going to close this and merge #206, and cut a new major version soon that fixes this. Thank you for bringing this to our attention and for the PR! |
When determining the path for a request,
Rack::Request
prefixes theSCRIPT_NAME
, as seen here. This makes sure the relative path is included. At work, we use Iodine and Turbolinks, and without this patch most of our requests paths in Prometheus are""
. This patch fixes that.