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

Get controller labels from controller, not params #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

richardTowers
Copy link

prometheus_exporter currently reads the controller and action label from action_dispatch.request.parameters. This can lead to conflicts, where there's a form parameter called "action", or "controller" which takes precedence over "which controller action is this?".

This can be validated with a curl request to a rails application instrumented with prometheus_exporter:

curl -v http://127.0.0.1:3000/ --data 'controller=test'

Results in:

# HELP http_requests_total Total HTTP requests from web app.
# TYPE http_requests_total counter
http_requests_total{action="other",controller="test",status="404"} 1

This commit pulls the controller instance from action_controller.instance, and then calls the controller_name / action_name methods, which should be accurate even when conflicting form parameters are provided.

I haven't added any new tests for this, but I have tested it locally (by pointing a local rails app at a local copy of the gem, and doing the curl request above). Please let me know if you'd like a test (I might need a hint as to where to put it though).

prometheus_exporter currently reads the controller and action label from
action_dispatch.request.parameters. This can lead to conflicts, where
there's a form parameter called "action", or "controller" which takes
precedence over "which controller action is this?".

This can be validated with a curl request to a rails application
instrumented with prometheus_exporter:

  curl -v http://127.0.0.1:3000/ --data 'controller=test'

Results in:

  # HELP http_requests_total Total HTTP requests from web app.
  # TYPE http_requests_total counter
  http_requests_total{action="other",controller="test",status="404"} 1

This commit pulls the controller instance from `action_controller.instance`,
and then calls the controller_name / action_name methods, which should
be accurate even when conflicting form parameters are provided.
richardTowers added a commit to alphagov/govuk_app_config that referenced this pull request Oct 3, 2023
I've got an open PR to do this for the default default in
prometheus_exporter itself:

github[.]com/discourse/prometheus_exporter/pull/293

But it's unclear whether the maintainers will accept that, and if so how
long that will take.

In the meantime, we've got quite a bit of noise in our metrics because
it's currently possible for an HTTP request to overwrite the action /
controller labels by passing them in as request parameters like this:

    curl -v http://127.0.0.1:3000/ --data 'controller=test'

This commit extends the default middleware so we have more sensible
defaults for both Rails and Sinatra apps. I couldn't work out any good
labels for sinatra apps that wouldn't be potentially high cardinality,
so those are just blank.
richardTowers added a commit to alphagov/govuk_app_config that referenced this pull request Oct 3, 2023
I've got an open PR to do this for the default default in
prometheus_exporter itself:

github.com/discourse/prometheus_exporter/pull/293

But it's unclear whether the maintainers will accept that, and if so how
long that will take.

In the meantime, we've got quite a bit of noise in our metrics because
it's currently possible for an HTTP request to overwrite the action /
controller labels by passing them in as request parameters like this:

    curl -v http://127.0.0.1:3000/ --data 'controller=test'

This commit extends the default middleware so we have more sensible
defaults for both Rails and Sinatra apps. I couldn't work out any good
labels for sinatra apps that wouldn't be potentially high cardinality,
so those are just blank.
richardTowers added a commit to alphagov/govuk_app_config that referenced this pull request Oct 3, 2023
I've got an open PR to do this for the default default in
prometheus_exporter itself:

github.com/discourse/prometheus_exporter/pull/293

But it's unclear whether the maintainers will accept that, and if so how
long that will take.

In the meantime, we've got quite a bit of noise in our metrics because
it's currently possible for an HTTP request to overwrite the action /
controller labels by passing them in as request parameters like this:

    curl -v http://127.0.0.1:3000/ --data 'controller=test'

This commit extends the default middleware so we have more sensible
defaults for both Rails and Sinatra apps. I couldn't work out any good
labels for sinatra apps that wouldn't be potentially high cardinality,
so those are just blank.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant