Skip to content
Open
8 changes: 4 additions & 4 deletions apps/hostmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (r MetricsReceiverHostmetrics) Pipelines(ctx context.Context) ([]otel.Recei
)
}
transforms = append(transforms, otel.AddPrefix("agent.googleapis.com"))
pipelines := []otel.ReceiverPipeline{{
pipelines := []otel.ReceiverPipeline{confgenerator.ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "hostmetrics",
Config: map[string]interface{}{
Expand Down Expand Up @@ -327,10 +327,10 @@ func (r MetricsReceiverHostmetrics) Pipelines(ctx context.Context) ([]otel.Recei
),
otel.MetricsTransform(transforms...),
}},
}}
}, ctx)}

if p.HasNvidiaGpu && !r.disableGPUMetrics {
pipelines = append(pipelines, otel.ReceiverPipeline{
pipelines = append(pipelines, confgenerator.ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "nvml",
Config: map[string]interface{}{
Expand Down Expand Up @@ -363,7 +363,7 @@ func (r MetricsReceiverHostmetrics) Pipelines(ctx context.Context) ([]otel.Recei
otel.AddPrefix("agent.googleapis.com"),
),
}},
})
}, ctx))
}

return pipelines, nil
Expand Down
36 changes: 21 additions & 15 deletions confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,41 @@ func googleCloudExporter(userAgent string, instrumentationLabels bool, serviceRe
}
}

func ConvertPrometheusExporterToOtlpExporter(receiver otel.ReceiverPipeline, ctx context.Context) otel.ReceiverPipeline {
return ConvertToOtlpExporter(receiver, ctx, true)
func ConvertPrometheusExporterToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context) otel.ReceiverPipeline {
return ConvertToOtlpExporter(pipeline, ctx, true, false)
}

func ConvertGCMOtelExporterToOtlpExporter(receiver otel.ReceiverPipeline, ctx context.Context) otel.ReceiverPipeline {
return ConvertToOtlpExporter(receiver, ctx, false)
func ConvertGCMOtelExporterToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context) otel.ReceiverPipeline {
return ConvertToOtlpExporter(pipeline, ctx, false, false)
}

func ConvertToOtlpExporter(receiver otel.ReceiverPipeline, ctx context.Context, isPrometheus bool) otel.ReceiverPipeline {
func ConvertGCMSystemExporterToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context) otel.ReceiverPipeline {
return ConvertToOtlpExporter(pipeline, ctx, false, true)
}

func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context, isPrometheus bool, isSystem bool) otel.ReceiverPipeline {
expOtlpExporter := experimentsFromContext(ctx)["otlp_exporter"]
resource, _ := platform.FromContext(ctx).GetResource()
if !expOtlpExporter {
return receiver
return pipeline
}
_, err := receiver.ExporterTypes["metrics"]
_, err := pipeline.ExporterTypes["metrics"]
if !err {
return receiver
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())
}
receiver.ExporterTypes["metrics"] = otel.OTLP

receiver.Processors["metrics"] = append(receiver.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))

// The OTLP exporter doesn't batch by default like the googlecloud.* exporters. We need this to avoid the API point limits.
receiver.Processors["metrics"] = append(receiver.Processors["metrics"], otel.Batch())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.Batch())
if isPrometheus {
receiver.Processors["metrics"] = append(receiver.Processors["metrics"], otel.MetricUnknownCounter())
receiver.Processors["metrics"] = append(receiver.Processors["metrics"], otel.MetricStartTime())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
}
return receiver
return pipeline
}

func otlpExporter(userAgent string) otel.Component {
Expand Down
7 changes: 7 additions & 0 deletions confgenerator/otel/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ func MetricsRemoveServiceAttributes() Component {
}
}

func MetricsRemoveInstrumentationLibraryLabelsAttributes() Component {
return TransformationMetrics(
SetScopeName(""),
SetScopeVersion(""),
)
}

// TransformQueryContext is a type wrapper for the context of a query expression within the transoform processor
type TransformQueryContext string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ processors:
agentmetrics/hostmetrics_0:
blank_label_metrics:
- system.cpu.utilization
batch/hostmetrics_1_3:
send_batch_max_size: 200
send_batch_size: 200
batch/hostmetrics_5:
send_batch_max_size: 200
send_batch_size: 200
batch/prometheus_2:
send_batch_max_size: 200
send_batch_size: 200
Expand Down Expand Up @@ -590,6 +596,16 @@ processors:
include: ^(.*)$$
match_type: regexp
new_name: agent.googleapis.com/$${1}
resource/hostmetrics_1_1:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resource/hostmetrics_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resource/prometheus_1:
attributes:
- action: insert
Expand All @@ -607,6 +623,18 @@ processors:
- delete_key(resource.attributes, "service.instance.id")
- delete_key(resource.attributes, "server.port")
- delete_key(resource.attributes, "url.scheme")
transform/hostmetrics_1_2:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/hostmetrics_4:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/loggingmetrics_0:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -758,20 +786,26 @@ service:
pipelines:
metrics/default__pipeline_hostmetrics:
exporters:
- googlecloud
- otlphttp/otlp
processors:
- agentmetrics/hostmetrics_0
- filter/hostmetrics_1
- metricstransform/hostmetrics_2
- resource/hostmetrics_3
- transform/hostmetrics_4
- batch/hostmetrics_5
- filter/default__pipeline_hostmetrics_0
- resourcedetection/_global_0
receivers:
- hostmetrics/hostmetrics
metrics/default__pipeline_hostmetrics_1:
exporters:
- googlecloud
- otlphttp/otlp
processors:
- metricstransform/hostmetrics_1_0
- resource/hostmetrics_1_1
- transform/hostmetrics_1_2
- batch/hostmetrics_1_3
- filter/default__pipeline_hostmetrics_1_0
- resourcedetection/_global_0
receivers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ processors:
agentmetrics/hostmetrics_0:
blank_label_metrics:
- system.cpu.utilization
batch/hostmetrics_5:
send_batch_max_size: 200
send_batch_size: 200
batch/prometheus_2:
send_batch_max_size: 200
send_batch_size: 200
Expand Down Expand Up @@ -561,6 +564,11 @@ processors:
include: ^(.*)$$
match_type: regexp
new_name: agent.googleapis.com/$${1}
resource/hostmetrics_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resource/prometheus_1:
attributes:
- action: insert
Expand All @@ -578,6 +586,12 @@ processors:
- delete_key(resource.attributes, "service.instance.id")
- delete_key(resource.attributes, "server.port")
- delete_key(resource.attributes, "url.scheme")
transform/hostmetrics_4:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/loggingmetrics_0:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -727,11 +741,14 @@ service:
pipelines:
metrics/default__pipeline_hostmetrics:
exporters:
- googlecloud
- otlphttp/otlp
processors:
- agentmetrics/hostmetrics_0
- filter/hostmetrics_1
- metricstransform/hostmetrics_2
- resource/hostmetrics_3
- transform/hostmetrics_4
- batch/hostmetrics_5
- filter/default__pipeline_hostmetrics_0
- resourcedetection/_global_0
receivers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ processors:
agentmetrics/hostmetrics_0:
blank_label_metrics:
- system.cpu.utilization
batch/hostmetrics_5:
send_batch_max_size: 200
send_batch_size: 200
batch/iis_5:
send_batch_max_size: 200
send_batch_size: 200
Expand Down Expand Up @@ -633,6 +636,11 @@ processors:
match_type: regexp
new_name: agent.googleapis.com/$${1}
normalizesums/iis_2: {}
resource/hostmetrics_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resource/iis_4:
attributes:
- action: insert
Expand Down Expand Up @@ -660,6 +668,12 @@ processors:
- delete_key(resource.attributes, "service.instance.id")
- delete_key(resource.attributes, "server.port")
- delete_key(resource.attributes, "url.scheme")
transform/hostmetrics_4:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/iis_3:
metric_statements:
- context: scope
Expand Down Expand Up @@ -856,11 +870,14 @@ service:
pipelines:
metrics/default__pipeline_hostmetrics:
exporters:
- googlecloud
- otlphttp/otlp
processors:
- agentmetrics/hostmetrics_0
- filter/hostmetrics_1
- metricstransform/hostmetrics_2
- resource/hostmetrics_3
- transform/hostmetrics_4
- batch/hostmetrics_5
- filter/default__pipeline_hostmetrics_0
- resourcedetection/_global_0
receivers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ processors:
agentmetrics/hostmetrics_0:
blank_label_metrics:
- system.cpu.utilization
batch/hostmetrics_5:
send_batch_max_size: 200
send_batch_size: 200
batch/iis_5:
send_batch_max_size: 200
send_batch_size: 200
Expand Down Expand Up @@ -633,6 +636,11 @@ processors:
match_type: regexp
new_name: agent.googleapis.com/$${1}
normalizesums/iis_2: {}
resource/hostmetrics_3:
attributes:
- action: insert
key: gcp.project_id
value: test-project
resource/iis_4:
attributes:
- action: insert
Expand Down Expand Up @@ -660,6 +668,12 @@ processors:
- delete_key(resource.attributes, "service.instance.id")
- delete_key(resource.attributes, "server.port")
- delete_key(resource.attributes, "url.scheme")
transform/hostmetrics_4:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/iis_3:
metric_statements:
- context: scope
Expand Down Expand Up @@ -856,11 +870,14 @@ service:
pipelines:
metrics/default__pipeline_hostmetrics:
exporters:
- googlecloud
- otlphttp/otlp
processors:
- agentmetrics/hostmetrics_0
- filter/hostmetrics_1
- metricstransform/hostmetrics_2
- resource/hostmetrics_3
- transform/hostmetrics_4
- batch/hostmetrics_5
- filter/default__pipeline_hostmetrics_0
- resourcedetection/_global_0
receivers:
Expand Down
4 changes: 2 additions & 2 deletions integration_test/ops_agent_test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ func testDefaultMetrics(ctx context.Context, t *testing.T, logger *log.Logger, v

func TestDefaultMetricsNoProxy(t *testing.T) {
t.Parallel()
RunForEachImageAndFeatureFlag(t, []string{OtelLoggingFeatureFlag}, func(t *testing.T, imageSpec string, feature string) {
RunForEachImageAndFeatureFlag(t, []string{OtelLoggingFeatureFlag, OtlpHttpExporterFeatureFlag}, func(t *testing.T, imageSpec string, feature string) {
t.Parallel()
ctx, logger, vm := setupMainLogAndVM(t, imageSpec)
if err := SetupOpsAgentWithFeatureFlag(ctx, logger, vm, "", feature); err != nil {
Expand All @@ -2766,7 +2766,7 @@ func TestDefaultMetricsNoProxy(t *testing.T) {
// go/sdi-integ-test#proxy-testing
func TestDefaultMetricsWithProxy(t *testing.T) {
t.Parallel()
RunForEachImageAndFeatureFlag(t, []string{OtelLoggingFeatureFlag}, func(t *testing.T, imageSpec string, feature string) {
RunForEachImageAndFeatureFlag(t, []string{OtelLoggingFeatureFlag, OtlpHttpExporterFeatureFlag}, func(t *testing.T, imageSpec string, feature string) {
t.Parallel()
if !gce.IsWindows(imageSpec) {
t.Skip("Proxy test is currently only supported on windows.")
Expand Down
Loading