Skip to content

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

Merged
lzchen merged 13 commits into
open-telemetry:masterfrom
cbrand:master
Sep 24, 2020
Merged

fix(ext/prometheus): support minmaxsumcount aggregator#945
lzchen merged 13 commits into
open-telemetry:masterfrom
cbrand:master

Conversation

@cbrand

@cbrand cbrand commented Jul 27, 2020

Copy link
Copy Markdown
Contributor

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

linux-foundation-easycla Bot commented Jul 27, 2020

Copy link
Copy Markdown

CLA Check
The committers are authorized under a signed CLA.

@cbrand

cbrand commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

metric_name += self._sanitize(metric_record.instrument.name)

description = getattr(metric_record.instrument, "description", "")
if isinstance(metric_record.instrument, Counter):

Copy link
Copy Markdown
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?

@cbrand cbrand Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

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.

@lzchen lzchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice job!

@plajjan

plajjan commented Sep 23, 2020

Copy link
Copy Markdown
Contributor

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

lzchen commented Sep 23, 2020

Copy link
Copy Markdown
Contributor

@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

cbrand commented Sep 24, 2020

Copy link
Copy Markdown
Contributor Author

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

plajjan commented Sep 24, 2020

Copy link
Copy Markdown
Contributor

@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

plajjan commented Sep 24, 2020

Copy link
Copy Markdown
Contributor

@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