-
Notifications
You must be signed in to change notification settings - Fork 624
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(ext/prometheus): support minmaxsumcount aggregator #945
Conversation
I seem to be unable to get with classes in a type annotation from an external library sphinx to build without a warning. Thus, b71d498 removes the Iterable and Union statements which include objects of the |
labels=label_values, value=metric_record.aggregator.checkpoint | ||
) | ||
value = metric_record.aggregator.checkpoint | ||
if isinstance(value, MinMaxSumCountAggregator._TYPE): # pylint: disable=W0212 |
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.
Nit: Compare the aggregator itself instead of the value?
isinstance(metric_record.aggregator, MinMaxSumCountAggregator)
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.
Adjusted in fa7cfde
if isinstance( | ||
value, MinMaxSumCountAggregator._TYPE # pylint: disable=W0212 | ||
): | ||
value = metric_record.aggregator.checkpoint |
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.
Seems like value is defined twice? Line 165
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.
Fixed in bb6b8ff
instead of value
@@ -152,33 +152,44 @@ def _translate_to_prometheus(self, metric_record: MetricRecord): | |||
metric_name = self._prefix + "_" | |||
metric_name += self._sanitize(metric_record.instrument.name) | |||
|
|||
description = getattr(metric_record.instrument, "description", "") | |||
if isinstance(metric_record.instrument, Counter): |
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.
Curious, is does prometheus not support any other metric type? What about UpDownCounter
?
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.
Prometheus does actually provide a lot of other metric types:
Following the README at: https://github.com/prometheus/client_python#instrumenting the following types are supported:
I am not quite sure why the initial implementation only included unknown data sets and counters.
Maybe it was just enough for the use case of the contributor of this package.
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.
Nice job!
I'm seeing this problem too. Any particular reason why PR isn't merged yet? It was approved but never merged... CI is currently failing, does the patch perhaps need to be rebased? |
From last time I looked into it it seems that the build is failing due to deviations in the master branch (mainly one removed functionality from the metrics package). I pushed a fix up which seems to work with the new master base branch as expected. @lzchen please take a look. |
@lzchen I meant that I see the bug that this PR fixes, so I am interested in getting it resolved. Looks like CI is passing now after @cbrand applied his fix (thanks @cbrand for the quick turnaround). The branch is approved since earlier, perhaps a quick check on the newer changes is warranted but otherwise, good to merge? |
This PR fixes the export of
MinMaxSumCountAggregator
aggregated metrics in Prometheus.Before this PR, the specified test produces the following exception:
To fix this, the
_translate_to_prometheus
function checks if the metric's checkpoint value is a minmaxsumcount namedtuple instance and creates aSummaryMetricFamily
object of it as this seems to be the best possible supported Prometheus Export type, thus dropping recording of the min and max entries, but persisting thesum
andcount
calculations.Additionally, this PR adds types to all functions within this package. Some unused imports have also been removed.