- Notifications
You must be signed in to change notification settings - Fork 838
Emit native histograms only when OM 2.0.0 is requested #1128
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| | @@ -4,13 +4,17 @@ | |||||
| from sys import maxunicode | ||||||
| from typing import Callable | ||||||
| | ||||||
| from packaging.version import Version | ||||||
| | ||||||
| from ..utils import floatToGoString | ||||||
| from ..validation import ( | ||||||
| _is_valid_legacy_labelname, _is_valid_legacy_metric_name, | ||||||
| ) | ||||||
| | ||||||
| CONTENT_TYPE_LATEST = 'application/openmetrics-text; version=1.0.0; charset=utf-8' | ||||||
| """Content type of the latest OpenMetrics text format""" | ||||||
| """Content type of the latest OpenMetrics 1.0 text format""" | ||||||
| CONTENT_TYPE_LATEST_2_0 = 'application/openmetrics-text; version=2.0.0; charset=utf-8' | ||||||
| """Content type of the OpenMetrics 2.0 text format""" | ||||||
| ESCAPING_HEADER_TAG = 'escaping' | ||||||
| | ||||||
| | ||||||
| | @@ -53,7 +57,7 @@ def _compose_exemplar_string(metric, sample, exemplar): | |||||
| return exemplarstr | ||||||
| | ||||||
| | ||||||
| def generate_latest(registry, escaping=UNDERSCORES): | ||||||
| def generate_latest(registry, escaping=UNDERSCORES, version="1.0.0"): | ||||||
| '''Returns the metrics from the registry in latest text format as a string.''' | ||||||
| output = [] | ||||||
| for metric in registry.collect(): | ||||||
| | @@ -95,7 +99,7 @@ def generate_latest(registry, escaping=UNDERSCORES): | |||||
| positive_spans = '' | ||||||
| positive_deltas = '' | ||||||
| | ||||||
| if s.native_histogram: | ||||||
| if s.native_histogram and Version(version) >= Version('2.0.0'): | ||||||
| # Initialize basic nh template | ||||||
| nh_sample_template = '{{count:{},sum:{},schema:{},zero_threshold:{},zero_count:{}' | ||||||
| | ||||||
| | @@ -136,8 +140,12 @@ def generate_latest(registry, escaping=UNDERSCORES): | |||||
| nh_exemplarstr = _compose_exemplar_string(metric, s, nh_ex) | ||||||
| exemplarstr += nh_exemplarstr | ||||||
| | ||||||
| # Skip native histogram samples entirely if version < 2.0.0 | ||||||
| if s.native_histogram and Version(version) < Version('2.0.0'): | ||||||
| continue | ||||||
| | ||||||
| value = '' | ||||||
| if s.native_histogram: | ||||||
| if s.native_histogram and Version(version) >= Version('2.0.0'): | ||||||
| ||||||
| if s.native_histogram and Version(version) >= Version('2.0.0'): | |
| if native_histogram: |
I think that instead of checking for both source and the flag we can just check to see if the constructed native_histogram variable is no longer empty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we do this skip on line 95 and then not have to add
and Version(version) >= Version('2.0.0')in other places?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe even further up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, if we're skipping anyway I think we could just do one check and the
continuelogic at the very beginning of native histogram processing. Otherwise if there are multiple entry points we want to check I think it would be nice to have a single variable likenative_histograms_supportedthat we calculate based off the version at the top of the function, then we can add more flags for other open metrics 2.0 things like the inline created timestamp.