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

Implement automatic exposition format detection #14445

Merged
merged 10 commits into from
Apr 25, 2023

Conversation

alopezz
Copy link
Contributor

@alopezz alopezz commented Apr 24, 2023

What does this PR do?

Changes the decision of what parser to use for OpenMetrics (Prometheus or OpenMetrics) to be dynamic, based on the Content-Type header.

Motivation

AI-2416.

The decision to use the OpenMetrics parser (a.k.a. strict in the code) or the Prometheus format parser was based on a config option called use_latest_spec, which is not very obvious. As it so happens, both formats specify what the Content-Type header should look like when using each of those formats, which makes it reasonable for us to rely on it to make that decision dynamically instead of by using a explicit option. This will also keep our integrations working without changes in the event existing applications make the switch from the currently more widespread prometheus format to the OpenMetrics standard (which is supposed to represent the future). It should safe to rely on that header, as Prometheus itself does the same.

Additional Notes

  • use_latest_spec still exists as a escape hatch to force the OpenMetrics format regardless of content header. A follow-up PR will hide it.
  • I'm not sure how versioning should be applied to this change, since it affects all integrations based on the base class, and it's technically a breaking change. I'm open to merging Deprecate use_latest_spec option #14446 into this in order to apply the same versioning change to all affected integrations.
  • There are some file renames and movement of code between files which should be easier to follow by looking at the individual commits.

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
  • If the PR doesn't need to be tested during QA, please add a qa/skip-qa label.

@alopezz alopezz requested review from a team as code owners April 24, 2023 12:46
Copy link
Contributor Author

alopezz commented Apr 24, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@github-actions
Copy link

The validations job has failed; please review the Files changed tab for possible suggestions to resolve.

@github-actions
Copy link

Label changelog/Changed was added to this Pull Request, so the next release will bump major version. Please make sure this is a breaking change, or use the changelog/Fixed label.

@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #14445 (1abfce5) into master (37aab9c) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Flag Coverage Δ
active_directory 100.00% <ø> (+17.64%) ⬆️
activemq_xml 82.31% <ø> (ø)
amazon_msk 89.07% <ø> (ø)
ambari 85.75% <ø> (ø)
apache 95.08% <ø> (ø)
arangodb 98.21% <ø> (ø)
argocd 88.43% <ø> (ø)
aspdotnet 100.00% <ø> (+26.19%) ⬆️
avi_vantage 92.54% <ø> (ø)
azure_iot_edge 82.00% <ø> (ø)
boundary 100.00% <ø> (ø)
btrfs 82.91% <ø> (ø)
cacti 87.90% <ø> (ø)
calico 83.33% <ø> (ø)
cisco_aci 95.27% <ø> (ø)
citrix_hypervisor 87.50% <ø> (ø)
cloud_foundry_api 95.98% <ø> (+0.12%) ⬆️
cloudera 99.82% <ø> (ø)
consul 91.64% <ø> (ø)
coredns 94.54% <ø> (ø)
crio 89.79% <ø> (ø)
datadog_checks_base 89.26% <100.00%> (+0.38%) ⬆️
datadog_checks_dev 80.14% <ø> (+0.03%) ⬆️
datadog_checks_downloader 80.48% <ø> (ø)
datadog_cluster_agent 90.00% <ø> (ø)
ddev 99.16% <ø> (ø)
directory 96.42% <ø> (ø)
disk 89.64% <ø> (ø)
dns_check 93.90% <ø> (ø)
druid 97.70% <ø> (ø)
ecs_fargate 80.92% <ø> (ø)
eks_fargate 94.05% <ø> (ø)
envoy 94.40% <ø> (ø)
external_dns 89.09% <ø> (ø)
fluentd 94.77% <ø> (ø)
foundationdb 78.50% <ø> (ø)
go_expvar 92.73% <ø> (ø)
gunicorn 92.85% <ø> (+0.75%) ⬆️
hazelcast 92.39% <ø> (ø)
hdfs_datanode 89.74% <ø> (ø)
hdfs_namenode 86.72% <ø> (ø)
http_check 95.82% <ø> (+2.15%) ⬆️
ibm_i 81.95% <ø> (ø)
ibm_mq 51.95% <ø> (ø)
impala 97.97% <ø> (ø)
istio 77.43% <ø> (+0.55%) ⬆️
kube_apiserver_metrics 97.89% <ø> (ø)
kube_controller_manager 96.00% <ø> (ø)
kube_dns 95.97% <ø> (ø)
kube_metrics_server 94.87% <ø> (ø)
kube_proxy 96.80% <ø> (ø)
kube_scheduler 96.53% <ø> (ø)
kubelet 90.69% <ø> (ø)
kubernetes_state 89.18% <ø> (ø)
kyototycoon 85.96% <ø> (ø)
lighttpd 83.64% <ø> (ø)
linkerd 85.14% <ø> (+1.14%) ⬆️
linux_proc_extras 96.22% <ø> (ø)
mapreduce 81.35% <ø> (ø)
marathon 83.12% <ø> (ø)
mcache 93.50% <ø> (ø)
mesos_master 89.75% <ø> (ø)
nagios 89.01% <ø> (ø)
network 94.01% <ø> (+1.10%) ⬆️
nginx_ingress_controller 98.36% <ø> (ø)
openldap 96.33% <ø> (ø)
openmetrics 97.95% <100.00%> (+0.05%) ⬆️
openstack 51.45% <ø> (ø)
openstack_controller 91.12% <ø> (ø)
php_fpm 90.25% <ø> (+0.84%) ⬆️
postfix 88.04% <ø> (ø)
powerdns_recursor 96.65% <ø> (ø)
process 85.42% <ø> (+0.28%) ⬆️
prometheus 94.17% <ø> (ø)
proxysql 98.97% <ø> (ø)
pulsar 100.00% <ø> (ø)
rethinkdb 97.93% <ø> (ø)
riak 99.22% <ø> (ø)
silk 93.69% <ø> (ø)
squid 100.00% <ø> (ø)
supervisord 92.30% <ø> (ø)
system_core 90.90% <ø> (ø)
system_swap 98.30% <ø> (ø)
tcp_check 91.58% <ø> (ø)
temporal 100.00% <ø> (ø)
teradata 94.24% <ø> (ø)
tls 92.07% <ø> (+0.82%) ⬆️
twemproxy 79.45% <ø> (ø)
twistlock 79.62% <ø> (ø)
wmi_check 92.91% <ø> (ø)
yarn 89.50% <ø> (ø)

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

@alopezz
Copy link
Contributor Author

alopezz commented Apr 24, 2023

The validations job has failed; please review the Files changed tab for possible suggestions to resolve.

It's complaining about a license year due to file renames. I think it's safe to ignore that validation error on this instance; it's a bit of an edge case for the license header validation.

@github-actions
Copy link

github-actions bot commented Apr 24, 2023

Test Results

     979 files       979 suites   7h 41m 3s ⏱️
  5 314 tests   4 972 ✔️    334 💤 5  3 🔥
21 365 runs  17 701 ✔️ 3 655 💤 6  3 🔥

For more details on these failures and errors, see this check.

Results for commit 6121ec6.

♻️ This comment has been updated with latest results.

@property
def parse_metric_families(self):
media_type = self._content_type.split(';')[0]
return self._parsers[media_type]
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on https://github.com/prometheus/prometheus/blob/v2.43.0/model/textparse/interface.go#L83-L90 couldn't we get rid of the parser mapping attribute and this could be simplified?

Suggested change
return self._parsers[media_type]
return (
parse_openmetrics
if self.use_latest_spec or media_type == 'application/openmetrics-text'
else parse_prometheus
)

@alopezz alopezz force-pushed the alopez/openmetrics/dynamic-parser-selection branch from 70d3df2 to 6121ec6 Compare April 24, 2023 16:23
@github-actions
Copy link

The validations job has failed; please review the Files changed tab for possible suggestions to resolve.

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.

Awesome!

@alopezz alopezz force-pushed the alopez/openmetrics/dynamic-parser-selection branch from 6121ec6 to 1abfce5 Compare April 25, 2023 08:01
@github-actions
Copy link

The validations job has failed; please review the Files changed tab for possible suggestions to resolve.

@alopezz alopezz merged commit 7d8dc6d into master Apr 25, 2023
@alopezz alopezz deleted the alopez/openmetrics/dynamic-parser-selection branch April 25, 2023 10:20
github-actions bot pushed a commit that referenced this pull request Apr 25, 2023
* Put all tests for OpenMetrics V2 in the same file

In preparation for adding tests for dynamic parsing based on content type

* Rename test file

* Choose openmetrics parser dynamically

* Add content-type to prometheus test

* Refactor fixtures into more granular ones

* Rename fixtures to use prometheus / openmetrics

Instead of "strict"

* Test that `use_latest_spec` behaves as expected regardless of `Content-Type`

* Rename parsing function names

* Small refactor in parser selection

* Move parser selection to explicit conditional 7d8dc6d
alopezz added a commit that referenced this pull request Apr 25, 2023
As those are no longer needed after #14445.
alopezz added a commit that referenced this pull request Apr 26, 2023
* Be specific about the exposition formats supported

* Remove references to configuration of actual format

As those are no longer needed after #14445.
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.

2 participants