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(ext/prometheus): support minmaxsumcount aggregator #945

Merged
merged 13 commits into from
Sep 24, 2020
Merged

fix(ext/prometheus): support minmaxsumcount aggregator #945

merged 13 commits into from
Sep 24, 2020

Conversation

cbrand
Copy link
Contributor

@cbrand cbrand commented Jul 27, 2020

This PR fixes the export of MinMaxSumCountAggregator aggregated metrics in Prometheus.

Before this PR, the specified test produces the following exception:

TypeError: ("float() argument must be a string or a number, not 'minmaxsumcount'", Metric(testprefix_test_name, testdesc, unknown, , [Sample(name='testprefix_test_name', labels={}, value=minmaxsumcount(min=123, max=456, sum=579, count=2), timestamp=None, exemplar=None)]))

To fix this, the _translate_to_prometheus function checks if the metric's checkpoint value is a minmaxsumcount namedtuple instance and creates a SummaryMetricFamily 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 the sum and count calculations.

Additionally, this PR adds types to all functions within this package. Some unused imports have also been removed.

@cbrand cbrand requested a review from a team July 27, 2020 15:23
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 27, 2020

CLA Check
The committers are authorized under a signed CLA.

@cbrand
Copy link
Contributor Author

cbrand commented Jul 27, 2020

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 prometheus_client package. This does reduce the value of the typing annotation. Feedback is very welcome on how to get sphinx in the CI to run through while keeping the typing annotations in.

labels=label_values, value=metric_record.aggregator.checkpoint
)
value = metric_record.aggregator.checkpoint
if isinstance(value, MinMaxSumCountAggregator._TYPE): # pylint: disable=W0212
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in bb6b8ff

@@ -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):
Copy link
Contributor

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?

Copy link
Contributor Author

@cbrand cbrand Jul 27, 2020

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.

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Nice job!

@plajjan
Copy link
Contributor

plajjan commented Sep 23, 2020

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?

@lzchen
Copy link
Contributor

lzchen commented Sep 23, 2020

@plajjan
What error are you referring to? It seems like the build is failing on legitimate issues.

@cbrand
Are you planning on continuing PR?

@cbrand
Copy link
Contributor Author

cbrand commented Sep 24, 2020

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.

@plajjan
Copy link
Contributor

plajjan commented Sep 24, 2020

@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?

@lzchen lzchen merged commit 2b46d11 into open-telemetry:master Sep 24, 2020
@plajjan
Copy link
Contributor

plajjan commented Sep 24, 2020

@cbrand @lzchen thx!! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants