From 3ac20a6b0c5d0f043d6289622e8355bcad71e508 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Thu, 30 May 2024 18:58:15 +0000 Subject: [PATCH] add support for exponential histograms in the GMP exporter --- .../googlemanagedprometheus/naming.go | 2 + .../googlemanagedprometheus/naming_test.go | 8 +- .../testcases/testcases_metrics.go | 8 + .../exponential_histogram_gmp_expect.json | 207 +++++++++++++++++- 4 files changed, 219 insertions(+), 6 deletions(-) diff --git a/exporter/collector/googlemanagedprometheus/naming.go b/exporter/collector/googlemanagedprometheus/naming.go index 2f7f4b252..dc1c09304 100644 --- a/exporter/collector/googlemanagedprometheus/naming.go +++ b/exporter/collector/googlemanagedprometheus/naming.go @@ -50,6 +50,8 @@ func (c Config) GetMetricName(baseName string, metric pmetric.Metric) (string, e } return compliantName + "/summary", nil case pmetric.MetricTypeHistogram: + fallthrough + case pmetric.MetricTypeExponentialHistogram: return compliantName + "/histogram", nil default: return "", fmt.Errorf("unsupported metric datatype: %v", metric.Type()) diff --git a/exporter/collector/googlemanagedprometheus/naming_test.go b/exporter/collector/googlemanagedprometheus/naming_test.go index deb507fd7..1d7bc9de2 100644 --- a/exporter/collector/googlemanagedprometheus/naming_test.go +++ b/exporter/collector/googlemanagedprometheus/naming_test.go @@ -157,13 +157,13 @@ func TestGetMetricName(t *testing.T) { expected: "hello/histogram", }, { - desc: "other", - baseName: "other", + desc: "exponential histogram", + baseName: "hello", metric: func(m pmetric.Metric) { - m.SetName("other") + m.SetName("hello") m.SetEmptyExponentialHistogram() }, - expectErr: true, + expected: "hello/histogram", }, { desc: "untyped gauge with feature gate enabled returns unknown", diff --git a/exporter/collector/integrationtest/testcases/testcases_metrics.go b/exporter/collector/integrationtest/testcases/testcases_metrics.go index 676ad6f07..8b82e08e6 100644 --- a/exporter/collector/integrationtest/testcases/testcases_metrics.go +++ b/exporter/collector/integrationtest/testcases/testcases_metrics.go @@ -386,6 +386,14 @@ var MetricsTestCases = []TestCase{ // prometheus_target is not supported by the SDK SkipForSDK: true, }, + { + Name: "[GMP] Exponential Histogram becomes a GCM Distribution with exponential bucketOptions and a /histogram suffix", + OTLPInputFixturePath: "testdata/fixtures/metrics/exponential_histogram.json", + ExpectFixturePath: "testdata/fixtures/metrics/exponential_histogram_gmp_expect.json", + ConfigureCollector: configureGMPCollector, + // prometheus_target is not supported by the SDK + SkipForSDK: true, + }, { Name: "[GMP] Summary becomes a GCM Cumulative for sum/count, Gauges for quantiles", OTLPInputFixturePath: "testdata/fixtures/metrics/summary.json", diff --git a/exporter/collector/integrationtest/testdata/fixtures/metrics/exponential_histogram_gmp_expect.json b/exporter/collector/integrationtest/testdata/fixtures/metrics/exponential_histogram_gmp_expect.json index 760267b22..9aa6f4fb8 100644 --- a/exporter/collector/integrationtest/testdata/fixtures/metrics/exponential_histogram_gmp_expect.json +++ b/exporter/collector/integrationtest/testdata/fixtures/metrics/exponential_histogram_gmp_expect.json @@ -3,6 +3,208 @@ { "name": "projects/fakeprojectid", "timeSeries": [ + { + "metric": { + "type": "prometheus.googleapis.com/durationhist_seconds/histogram" + }, + "resource": { + "type": "prometheus_target", + "labels": { + "cluster": "", + "instance": "", + "job": "", + "location": "", + "namespace": "" + } + }, + "metricKind": "CUMULATIVE", + "valueType": "DISTRIBUTION", + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "count": "10000", + "mean": 198.4636328211394, + "bucketOptions": { + "exponentialBuckets": { + "numFiniteBuckets": 113, + "growthFactor": 1.0442737824274138, + "scale": 98.70149282610706 + } + }, + "bucketCounts": [ + "0", + "646", + "736", + "733", + "639", + "606", + "585", + "480", + "481", + "411", + "436", + "366", + "304", + "309", + "270", + "226", + "210", + "238", + "169", + "181", + "178", + "149", + "132", + "131", + "117", + "109", + "89", + "107", + "80", + "78", + "75", + "56", + "73", + "59", + "51", + "46", + "53", + "22", + "31", + "35", + "24", + "23", + "31", + "18", + "8", + "16", + "12", + "15", + "13", + "12", + "12", + "12", + "7", + "7", + "7", + "9", + "5", + "4", + "4", + "8", + "6", + "3", + "1", + "4", + "2", + "2", + "4", + "5", + "1", + "2", + "2", + "1", + "0", + "1", + "2", + "2", + "1", + "0", + "0", + "2", + "1", + "2", + "1", + "0", + "2", + "0", + "0", + "2", + "0", + "1", + "1", + "0", + "0", + "0", + "0", + "1", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "1", + "0", + "0", + "0", + "0", + "1", + "1", + "0", + "1", + "0" + ] + } + } + } + ], + "unit": "s" + }, + { + "metric": { + "type": "prometheus.googleapis.com/foohist_seconds/histogram" + }, + "resource": { + "type": "prometheus_target", + "labels": { + "cluster": "", + "instance": "", + "job": "", + "location": "", + "namespace": "" + } + }, + "metricKind": "CUMULATIVE", + "valueType": "DISTRIBUTION", + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "count": "7", + "mean": 1.7857142857142858, + "bucketOptions": { + "exponentialBuckets": { + "numFiniteBuckets": 3, + "growthFactor": 4, + "scale": 0.25 + } + }, + "bucketCounts": [ + "2", + "1", + "3", + "1", + "0" + ] + } + } + } + ], + "unit": "s" + }, { "metric": { "type": "prometheus.googleapis.com/target_info/gauge" @@ -55,7 +257,7 @@ "startTime": "1970-01-01T00:00:00Z" }, "value": { - "int64Value": "1" + "int64Value": "3" } } ] @@ -410,5 +612,6 @@ } } ] - } + }, + "userAgent": "opentelemetry-collector-contrib latest grpc-go/1.63.2" }