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

Fix incorrect OpenMetrics V2 check exposition format HTTP header #11899

Merged
merged 2 commits into from
May 10, 2022

Conversation

jalaziz
Copy link
Contributor

@jalaziz jalaziz commented Apr 27, 2022

What does this PR do?

With this change, the openmetrics check should request the appropriate
exposition format fixing "Clashing name" errors.

Motivation

The exposition format to request is set via the "Accept" header. Despite
the OpenMetricsScraper appearing to set the correct header when
use_latest_spec is enabled, it is actually a no-op due to the default
HTTP headers including Accept: */* and the use of setdefault.

Additional Notes

Tests incoming. It appears that there were no existing tests of use_latest_spec or the new exposition format.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

The exposition format to request is set via the "Accept" header. Despite
the OpenMetricsScraper appearing to set the correct header when
`use_latest_spec` is enabled, it is actually a no-op due to the default
HTTP headers including `Accept: */*` and the use of `setdefault`.

With this change, the openmetrics check should request the appropriate
exposition format fixing "Clashing name" errors.
@jalaziz jalaziz requested review from a team as code owners April 27, 2022 08:02
@codecov
Copy link

codecov bot commented Apr 27, 2022

Codecov Report

Merging #11899 (4eebc0d) into master (aaae622) will not change coverage.
The diff coverage is 75.00%.

Flag Coverage Δ
arangodb 95.74% <ø> (ø)
avi_vantage 91.92% <ø> (ø)
calico 83.33% <ø> (ø)
citrix_hypervisor 87.50% <ø> (ø)
crio 89.79% <ø> (ø)
ibm_i 81.58% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

djmitche
djmitche previously approved these changes Apr 27, 2022
Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

Thanks! What do you think about always just overriding the header?

@jalaziz
Copy link
Contributor Author

jalaziz commented Apr 27, 2022

Thanks! What do you think about always just overriding the header?

That's how I approached it at first, but then realized that it may break workflows where a user sets headers in check config. In fact, that's how I'm working around this issue for now:

      {
        "openmetrics_endpoint": "http://%%host%%:%%port_prometheus%%/metrics",
        "metrics": [".*"],
        "namespace": "foo",
        "use_latest_spec": true,
        "headers": {
          "Accept": "application/openmetrics-text; version=0.0.1; charset=utf-8"
        }
      }

Another option would be to override the header by setting it on config if headers['Accept'] is not set.

@jalaziz jalaziz force-pushed the jameel/fix-openmetricsv2-exposition branch from da5355e to 4eebc0d Compare April 28, 2022 07:47
@jalaziz
Copy link
Contributor Author

jalaziz commented Apr 28, 2022

@ofek Added some really basic tests. Please let me know if anything else is needed.

As for always overriding, happy to switch to that if you think there's never a need to override it via instance configs.

@jalaziz jalaziz requested review from djmitche and ofek April 29, 2022 20:39
@jalaziz
Copy link
Contributor Author

jalaziz commented May 3, 2022

@ofek just following up since you requested the changes. Happy to implement "always" override path, but want to confirm that it's okay to break the override path that exists today.

Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

Thanks, great job as always!!!

@ofek ofek merged commit d979458 into DataDog:master May 10, 2022
github-actions bot pushed a commit that referenced this pull request May 10, 2022
)

* Fix incorrect exposition format header with OpenMetricsV2 check

The exposition format to request is set via the "Accept" header. Despite
the OpenMetricsScraper appearing to set the correct header when
`use_latest_spec` is enabled, it is actually a no-op due to the default
HTTP headers including `Accept: */*` and the use of `setdefault`.

With this change, the openmetrics check should request the appropriate
exposition format fixing "Clashing name" errors.

* Add tests d979458
@jalaziz jalaziz deleted the jameel/fix-openmetricsv2-exposition branch June 1, 2022 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants