From d15adebd22262be2b40335dd8e2d20b7e4694a80 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Fri, 1 Nov 2024 14:50:07 +0000 Subject: [PATCH] restore prometheus sanitization for GMP exporter --- exporter/googlemanagedprometheusexporter/config.go | 8 +++++++- exporter/googlemanagedprometheusexporter/go.mod | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/exporter/googlemanagedprometheusexporter/config.go b/exporter/googlemanagedprometheusexporter/config.go index 544165f44707..739057629540 100644 --- a/exporter/googlemanagedprometheusexporter/config.go +++ b/exporter/googlemanagedprometheusexporter/config.go @@ -9,6 +9,9 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus" "go.opentelemetry.io/collector/exporter/exporterhelper" + "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" ) // Config defines configuration for Google Cloud Managed Service for Prometheus exporter. @@ -47,7 +50,10 @@ func (c *GMPConfig) toCollectorConfig() collector.Config { cfg.MetricConfig.InstrumentationLibraryLabels = false cfg.MetricConfig.ServiceResourceLabels = false // Update metric naming to match GMP conventions - cfg.MetricConfig.GetMetricName = c.MetricConfig.Config.GetMetricName + cfg.MetricConfig.GetMetricName = func(baseName string, metric pmetric.Metric) (string, error) { + compliantName := prometheus.BuildCompliantName(metric, "", c.MetricConfig.Config.AddMetricSuffixes) + return googlemanagedprometheus.GetMetricName(baseName, compliantName, metric) + } // Map to the prometheus_target monitored resource cfg.MetricConfig.MapMonitoredResource = c.MetricConfig.Config.MapToPrometheusTarget cfg.MetricConfig.ExtraMetrics = c.MetricConfig.Config.ExtraMetrics diff --git a/exporter/googlemanagedprometheusexporter/go.mod b/exporter/googlemanagedprometheusexporter/go.mod index 02bf40369a5e..3e4aed9efeed 100644 --- a/exporter/googlemanagedprometheusexporter/go.mod +++ b/exporter/googlemanagedprometheusexporter/go.mod @@ -5,6 +5,7 @@ go 1.22.0 require ( github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0.49.0 github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.49.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.112.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.112.0 go.opentelemetry.io/collector/confmap v1.18.0