Prometheus Receiver metric type fixes to match Prometheus functionality#3853
Prometheus Receiver metric type fixes to match Prometheus functionality#3853gracewehner wants to merge 2 commits into
Conversation
| MetricDescriptor: &metricspb.MetricDescriptor{ | ||
| Name: "something_not_exists", | ||
| Type: metricspb.MetricDescriptor_UNSPECIFIED, | ||
| Type: metricspb.MetricDescriptor_GAUGE_DOUBLE, |
There was a problem hiding this comment.
I don't actually see where you set the type to GAUGE_DOUBLE anywhere in this PR. Is this a work in progress, or did you forget to commit some changes?
There was a problem hiding this comment.
The change is a bit hidden. This change sets the metadata.Type to textparse.MetricTypeUnknown which is already being done in line 66 here, just only in the situation where the metric name is not equal to the family name but the metadata still cannot be found:
The function convToOCAMetricType() is converting the textparse.MetricTypeUnknown to a GAUGE_DOUBLE, whereas before the change it was defaulting to UNSPECIFIED:
…should still have _total
|
@gracewehner thanks a lot for the PR. We are in process of changing the use of OpenCensus in the receiver #3741 and would be good if we can fix this in the pdata version and avoid using opencensus dependencies. |
|
@gracewehner sorry, unfortunately this needs to be moved to contrib, since we moved the prometheusreceiver there. |
Description:
# TYPEhint as UNSPECIFIED which converts to empty OTLP metrics: such as{"metrics":[{},{},{}]}in the OTLP json output and considers these metric invalid. Prometheus, however, will treat these metrics as a Gauge type and these metrics show up correctly in the Prometheus expression browser. With these changes, if the metadata type is not found, the type is set totextparse.MetricTypeUnknownso that in the functionconvToOCAMetricType(metadata.Type), the type is converted tometricspb.MetricDescriptor_GAUGE_DOUBLE._totalto list of trimmable metric name suffixes #3603 fixed the issue by checking the name without the _total suffix to lookup the metadata. However, the family name without the _total suffix is used as the metric name, so the metricpython_gc_objects_collected_totalis converted to the namepython_gc_objects_collectedwhereas Prometheus still includes the _total suffix. This is because previously the metric family name only differed from metric names when the metric was a summary and histogram that have the metrics with _sum and _count, which are added back in later. There isn't this special logic for counters, so the family name needs to be set to the actual metric name when it is a counter and has the _total suffix.Link to tracking Issue: #3852 #3557
Testing:
Tested out on a Kubernetes cluster with Prometheus scrape targets that have metrics without the
# TYPEhint for (1) and metrics using the python sdk sending metrics such as below for testing (2):Changed tests for metrics without the type hint to expect the gauge type.
Added test case for situation where metadata key excludes _total suffix but metric name should still have _total suffix