Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion apps/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r MetricsReceiverIis) Pipelines(ctx context.Context) ([]otel.ReceiverPipel
}

// Return version 1 if version is anything other than 2
return []otel.ReceiverPipeline{confgenerator.ConvertGCMOtelExporterToOtlpExporter(otel.ReceiverPipeline{
return []otel.ReceiverPipeline{confgenerator.ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "windowsperfcounters",
Config: map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion apps/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m MetricsReceiverMssql) Pipelines(ctx context.Context) ([]otel.ReceiverPip
}, ctx)}, nil
}

return []otel.ReceiverPipeline{confgenerator.ConvertGCMOtelExporterToOtlpExporter(otel.ReceiverPipeline{
return []otel.ReceiverPipeline{confgenerator.ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
Receiver: otel.Component{
Type: "windowsperfcounters",
Config: map[string]interface{}{
Expand Down
37 changes: 22 additions & 15 deletions confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,42 @@ 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())
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
}
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_4:
send_batch_max_size: 200
send_batch_size: 200
batch/hostmetrics_6:
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,36 @@ 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_1_3:
metric_statements:
- context: resource
error_mode: silent
statements:
- delete_key(attributes, "service.name")
- delete_key(attributes, "service.instance.id")
- delete_key(attributes, "service.namespace")
- delete_key(attributes, "service.version")
transform/hostmetrics_4:
metric_statements:
- context: scope
statements:
- set(name, "")
- set(version, "")
transform/hostmetrics_5:
metric_statements:
- context: resource
error_mode: silent
statements:
- delete_key(attributes, "service.name")
- delete_key(attributes, "service.instance.id")
- delete_key(attributes, "service.namespace")
- delete_key(attributes, "service.version")
transform/loggingmetrics_0:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -758,20 +804,28 @@ 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
- transform/hostmetrics_5
- batch/hostmetrics_6
- 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
- transform/hostmetrics_1_3
- batch/hostmetrics_1_4
- 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_6:
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,21 @@ 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/hostmetrics_5:
metric_statements:
- context: resource
error_mode: silent
statements:
- delete_key(attributes, "service.name")
- delete_key(attributes, "service.instance.id")
- delete_key(attributes, "service.namespace")
- delete_key(attributes, "service.version")
transform/loggingmetrics_0:
error_mode: ignore
metric_statements:
Expand Down Expand Up @@ -727,11 +750,15 @@ 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
- transform/hostmetrics_5
- batch/hostmetrics_6
- filter/default__pipeline_hostmetrics_0
- resourcedetection/_global_0
receivers:
Expand Down
Loading
Loading