From f4cb869f8f47fe54622dae474ff7446d1b82c8d5 Mon Sep 17 00:00:00 2001 From: Ridwan Sharif Date: Fri, 23 Jan 2026 17:02:11 +0000 Subject: [PATCH] otlp: switch to UTR endpoint --- apps/otlp.go | 8 +++-- confgenerator/confgenerator.go | 32 +++++++++++--------- integration_test/ops_agent_test/main_test.go | 4 +-- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/apps/otlp.go b/apps/otlp.go index 6ceb70e637..def491ccfa 100644 --- a/apps/otlp.go +++ b/apps/otlp.go @@ -137,7 +137,11 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e receiverPipelineType, metricsRDM, metricsProcessors := r.metricsProcessors(ctx) - return []otel.ReceiverPipeline{{ + converter := confgenerator.ConvertGCMOtelExporterToOtlpExporter + if r.MetricsMode != "googlecloudmonitoring" { + converter = confgenerator.ConvertPrometheusExporterToOtlpExporter + } + return []otel.ReceiverPipeline{converter(otel.ReceiverPipeline{ ExporterTypes: map[string]otel.ExporterType{ "metrics": receiverPipelineType, "traces": otel.OTel, @@ -163,7 +167,7 @@ func (r ReceiverOTLP) Pipelines(ctx context.Context) ([]otel.ReceiverPipeline, e "traces": otel.SetIfMissing, "logs": otel.SetIfMissing, }, - }}, nil + }, ctx)}, nil } func init() { diff --git a/confgenerator/confgenerator.go b/confgenerator/confgenerator.go index d5d0db869c..b4b78ae14d 100644 --- a/confgenerator/confgenerator.go +++ b/confgenerator/confgenerator.go @@ -75,22 +75,24 @@ func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context, if !expOtlpExporter { return pipeline } - _, err := pipeline.ExporterTypes["metrics"] - if !err { - return pipeline - } - pipeline.ExporterTypes["metrics"] = otel.OTLP - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName())) - if isSystem { - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes()) - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes()) - } + if _, ok := pipeline.ExporterTypes["metrics"]; ok { + pipeline.ExporterTypes["metrics"] = otel.OTLP + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName())) + if isSystem { + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes()) + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes()) + } - // The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits. - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch()) - if isPrometheus { - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter()) - pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime()) + // The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits. + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch()) + if isPrometheus { + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter()) + pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime()) + } + } + if _, ok := pipeline.ExporterTypes["traces"]; ok { + pipeline.ExporterTypes["traces"] = otel.OTLP + pipeline.Processors["traces"] = append(pipeline.Processors["traces"], otel.GCPProjectID(resource.ProjectName())) } return pipeline } diff --git a/integration_test/ops_agent_test/main_test.go b/integration_test/ops_agent_test/main_test.go index 40088d7db3..21d765a5a5 100644 --- a/integration_test/ops_agent_test/main_test.go +++ b/integration_test/ops_agent_test/main_test.go @@ -5223,7 +5223,7 @@ traces: func TestOTLPTraces(t *testing.T) { t.Parallel() - gce.RunForEachImage(t, func(t *testing.T, imageSpec string) { + RunForEachImageAndFeatureFlag(t, []string{OtlpHttpExporterFeatureFlag}, func(t *testing.T, imageSpec string, feature string) { t.Parallel() ctx, logger, vm := setupMainLogAndVM(t, imageSpec) otlpConfig := ` @@ -5241,7 +5241,7 @@ metrics: service: pipelines: ` - if err := agents.SetupOpsAgent(ctx, logger, vm, otlpConfig); err != nil { + if err := SetupOpsAgentWithFeatureFlag(ctx, logger, vm, otlpConfig, feature); err != nil { t.Fatal(err) }