Skip to content

Commit 887fa92

Browse files
Merge branch 'master' into fcovalente-system-log-test
2 parents 9e64144 + db7f747 commit 887fa92

10 files changed

Lines changed: 633 additions & 370 deletions

File tree

confgenerator/agentmetrics.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var grpcToStringStatus = map[string]string{
8080

8181
func (r AgentSelfMetrics) AddSelfMetricsPipelines(receiverPipelines map[string]otel.ReceiverPipeline, pipelines map[string]otel.Pipeline, ctx context.Context) {
8282
// Receiver pipelines names should have 1 underscore to avoid collision with user configurations.
83-
receiverPipelines["agent_prometheus"] = r.PrometheusMetricsPipeline()
83+
receiverPipelines["agent_prometheus"] = r.PrometheusMetricsPipeline(ctx)
8484

8585
// Pipeline names should have no underscores to avoid collision with user configurations.
8686
pipelines["otel"] = otel.Pipeline{
@@ -101,15 +101,15 @@ func (r AgentSelfMetrics) AddSelfMetricsPipelines(receiverPipelines map[string]o
101101
Processors: r.LoggingMetricsPipelineProcessors(),
102102
}
103103

104-
receiverPipelines["ops_agent"] = r.OpsAgentPipeline()
104+
receiverPipelines["ops_agent"] = r.OpsAgentPipeline(ctx)
105105
pipelines["opsagent"] = otel.Pipeline{
106106
Type: "metrics",
107107
ReceiverPipelineName: "ops_agent",
108108
}
109109
}
110110

111-
func (r AgentSelfMetrics) PrometheusMetricsPipeline() otel.ReceiverPipeline {
112-
return otel.ReceiverPipeline{
111+
func (r AgentSelfMetrics) PrometheusMetricsPipeline(ctx context.Context) otel.ReceiverPipeline {
112+
return ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
113113
Receiver: otel.Component{
114114
Type: "prometheus",
115115
Config: map[string]interface{}{
@@ -150,7 +150,7 @@ func (r AgentSelfMetrics) PrometheusMetricsPipeline() otel.ReceiverPipeline {
150150
),
151151
},
152152
},
153-
}
153+
}, ctx)
154154
}
155155

156156
func (r AgentSelfMetrics) OtelPipelineProcessors(ctx context.Context) []otel.Component {
@@ -373,18 +373,18 @@ func (r AgentSelfMetrics) LoggingMetricsPipelineProcessors() []otel.Component {
373373
}
374374
}
375375

376-
func (r AgentSelfMetrics) OpsAgentPipeline() otel.ReceiverPipeline {
377-
receiver_config := map[string]any{
376+
func (r AgentSelfMetrics) OpsAgentPipeline(ctx context.Context) otel.ReceiverPipeline {
377+
receiverConfig := map[string]any{
378378
"include": []string{
379379
filepath.Join(r.OtelRuntimeDir, "enabled_receivers_otlp.json"),
380380
filepath.Join(r.OtelRuntimeDir, "feature_tracking_otlp.json")},
381381
"replay_file": true,
382382
"poll_interval": time.Duration(60 * time.Second).String(),
383383
}
384-
return otel.ReceiverPipeline{
384+
return ConvertGCMSystemExporterToOtlpExporter(otel.ReceiverPipeline{
385385
Receiver: otel.Component{
386386
Type: "otlpjsonfile",
387-
Config: receiver_config,
387+
Config: receiverConfig,
388388
},
389389
ExporterTypes: map[string]otel.ExporterType{
390390
"metrics": otel.System,
@@ -394,7 +394,7 @@ func (r AgentSelfMetrics) OpsAgentPipeline() otel.ReceiverPipeline {
394394
otel.Transform("metric", "datapoint", []ottl.Statement{"set(time, Now())"}),
395395
},
396396
},
397-
}
397+
}, ctx)
398398
}
399399

400400
// intentionally not registered as a component because this is not created by users

confgenerator/confgenerator.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func ConvertGCMSystemExporterToOtlpExporter(pipeline otel.ReceiverPipeline, ctx
8282

8383
func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context, isPrometheus bool, isSystem bool) otel.ReceiverPipeline {
8484
expOtlpExporter := experimentsFromContext(ctx)["otlp_exporter"]
85-
resource, _ := platform.FromContext(ctx).GetResource()
8685
if !expOtlpExporter {
8786
return pipeline
8887
}
@@ -91,7 +90,6 @@ func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context,
9190
return pipeline
9291
}
9392
pipeline.ExporterTypes["metrics"] = otel.OTLP
94-
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.GCPProjectID(resource.ProjectName()))
9593
if isSystem {
9694
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveInstrumentationLibraryLabelsAttributes())
9795
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsRemoveServiceAttributes())
@@ -100,9 +98,7 @@ func ConvertToOtlpExporter(pipeline otel.ReceiverPipeline, ctx context.Context,
10098
// b/476109839: For prometheus metrics using the OTLP exporter. The dots "." in the metric name are NOT replaced with underscore "_".
10199
// This is diffrent from the GMP endpoint.
102100
if isPrometheus {
103-
104101
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricUnknownCounter())
105-
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricStartTime())
106102
// If a metric already has a domain, it will not be considered a prometheus metric by the UTR endpoint unless we add the prefix.
107103
// This behavior is the same as the GCM/GMP exporters.
108104
pipeline.Processors["metrics"] = append(pipeline.Processors["metrics"], otel.MetricsTransform(otel.AddPrefix("prometheus.googleapis.com")))
@@ -194,6 +190,7 @@ func (uc *UnifiedConfig) GenerateOtelConfig(ctx context.Context, outDir, stateDi
194190
OtelLogging: uc.Logging.Service.OTelLogging,
195191
}
196192
agentSelfMetrics.AddSelfMetricsPipelines(receiverPipelines, pipelines, ctx)
193+
resource, _ := p.GetResource()
197194

198195
otelConfig, err := otel.ModularConfig{
199196
LogLevel: uc.getOTelLogLevel(),
@@ -216,6 +213,8 @@ func (uc *UnifiedConfig) GenerateOtelConfig(ctx context.Context, outDir, stateDi
216213
// The OTLP exporter doesn't batch by default like the googlecloud.* exporters.
217214
// We need this to avoid the API point limits.
218215
"metrics": {
216+
otel.GCPProjectID(resource.ProjectName()),
217+
otel.MetricStartTime(),
219218
otel.BatchProcessor(200, 200, "200ms"),
220219
},
221220
// Batching logs improves log export performance.

confgenerator/testdata/goldens/combined-receiver_otlp_otlphttp/golden/linux-gpu/otel.yaml

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
exporters:
2-
googlecloud:
3-
metric:
4-
instrumentation_library_labels: false
5-
prefix: ""
6-
resource_filters: []
7-
service_resource_labels: false
8-
skip_create_descriptor: true
9-
user_agent: Google-Cloud-Ops-Agent-Metrics/latest (BuildDistro=build_distro;Platform=linux;ShortName=linux_platform;ShortVersion=linux_platform_version)
102
googlecloud/otel:
113
metric:
124
instrumentation_library_labels: true
@@ -28,7 +20,7 @@ processors:
2820
agentmetrics/hostmetrics_0:
2921
blank_label_metrics:
3022
- system.cpu.utilization
31-
batch/otlp/otlp_metrics_0:
23+
batch/otlp/otlp_metrics_2:
3224
send_batch_max_size: 200
3325
send_batch_size: 200
3426
timeout: 200ms
@@ -105,7 +97,7 @@ processors:
10597
- location
10698
interval/loggingmetrics_7:
10799
interval: 1m
108-
metricstarttime/otlp_5:
100+
metricstarttime/otlp/otlp_metrics_1:
109101
strategy: subtract_initial_point
110102
metricstransform/fluentbit_1:
111103
transforms:
@@ -658,23 +650,13 @@ processors:
658650
include: ^(.*)$$
659651
match_type: regexp
660652
new_name: agent.googleapis.com/$${1}
661-
metricstransform/otlp_6:
653+
metricstransform/otlp_4:
662654
transforms:
663655
- action: update
664656
include: ^(.*)$$
665657
match_type: regexp
666658
new_name: prometheus.googleapis.com/$${1}
667-
resource/hostmetrics_1_1:
668-
attributes:
669-
- action: insert
670-
key: gcp.project_id
671-
value: test-project
672-
resource/hostmetrics_3:
673-
attributes:
674-
- action: insert
675-
key: gcp.project_id
676-
value: test-project
677-
resource/otlp_3:
659+
resource/otlp/otlp_metrics_0:
678660
attributes:
679661
- action: insert
680662
key: gcp.project_id
@@ -699,13 +681,13 @@ processors:
699681
- delete_key(resource.attributes, "service.instance.id")
700682
- delete_key(resource.attributes, "server.port")
701683
- delete_key(resource.attributes, "url.scheme")
702-
transform/hostmetrics_1_2:
684+
transform/agent_prometheus_1:
703685
metric_statements:
704686
- context: scope
705687
statements:
706688
- set(name, "")
707689
- set(version, "")
708-
transform/hostmetrics_1_3:
690+
transform/agent_prometheus_2:
709691
metric_statements:
710692
- context: resource
711693
error_mode: silent
@@ -714,13 +696,28 @@ processors:
714696
- delete_key(attributes, "service.instance.id")
715697
- delete_key(attributes, "service.namespace")
716698
- delete_key(attributes, "service.version")
717-
transform/hostmetrics_4:
699+
transform/hostmetrics_1_1:
718700
metric_statements:
719701
- context: scope
720702
statements:
721703
- set(name, "")
722704
- set(version, "")
723-
transform/hostmetrics_5:
705+
transform/hostmetrics_1_2:
706+
metric_statements:
707+
- context: resource
708+
error_mode: silent
709+
statements:
710+
- delete_key(attributes, "service.name")
711+
- delete_key(attributes, "service.instance.id")
712+
- delete_key(attributes, "service.namespace")
713+
- delete_key(attributes, "service.version")
714+
transform/hostmetrics_3:
715+
metric_statements:
716+
- context: scope
717+
statements:
718+
- set(name, "")
719+
- set(version, "")
720+
transform/hostmetrics_4:
724721
metric_statements:
725722
- context: resource
726723
error_mode: silent
@@ -756,6 +753,21 @@ processors:
756753
- context: datapoint
757754
statements:
758755
- set(time, Now())
756+
transform/ops_agent_1:
757+
metric_statements:
758+
- context: scope
759+
statements:
760+
- set(name, "")
761+
- set(version, "")
762+
transform/ops_agent_2:
763+
metric_statements:
764+
- context: resource
765+
error_mode: silent
766+
statements:
767+
- delete_key(attributes, "service.name")
768+
- delete_key(attributes, "service.instance.id")
769+
- delete_key(attributes, "service.namespace")
770+
- delete_key(attributes, "service.version")
759771
transform/otel_0:
760772
error_mode: ignore
761773
metric_statements:
@@ -772,7 +784,7 @@ processors:
772784
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
773785
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
774786
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
775-
transform/otlp_4:
787+
transform/otlp_3:
776788
error_mode: ignore
777789
metric_statements:
778790
- context: metric
@@ -833,42 +845,51 @@ service:
833845
- agentmetrics/hostmetrics_0
834846
- filter/hostmetrics_1
835847
- metricstransform/hostmetrics_2
836-
- resource/hostmetrics_3
848+
- transform/hostmetrics_3
837849
- transform/hostmetrics_4
838-
- transform/hostmetrics_5
839850
- filter/default__pipeline_hostmetrics_0
840851
- resourcedetection/_global_0
841-
- batch/otlp/otlp_metrics_0
852+
- resource/otlp/otlp_metrics_0
853+
- metricstarttime/otlp/otlp_metrics_1
854+
- batch/otlp/otlp_metrics_2
842855
receivers:
843856
- hostmetrics/hostmetrics
844857
metrics/default__pipeline_hostmetrics_1:
845858
exporters:
846859
- otlp/otlp
847860
processors:
848861
- metricstransform/hostmetrics_1_0
849-
- resource/hostmetrics_1_1
862+
- transform/hostmetrics_1_1
850863
- transform/hostmetrics_1_2
851-
- transform/hostmetrics_1_3
852864
- filter/default__pipeline_hostmetrics_1_0
853865
- resourcedetection/_global_0
854-
- batch/otlp/otlp_metrics_0
866+
- resource/otlp/otlp_metrics_0
867+
- metricstarttime/otlp/otlp_metrics_1
868+
- batch/otlp/otlp_metrics_2
855869
receivers:
856870
- nvml/hostmetrics_1
857871
metrics/fluentbit:
858872
exporters:
859-
- googlecloud
873+
- otlp/otlp
860874
processors:
861875
- transform/agent_prometheus_0
876+
- transform/agent_prometheus_1
877+
- transform/agent_prometheus_2
862878
- filter/fluentbit_0
863879
- metricstransform/fluentbit_1
864880
- resourcedetection/_global_0
881+
- resource/otlp/otlp_metrics_0
882+
- metricstarttime/otlp/otlp_metrics_1
883+
- batch/otlp/otlp_metrics_2
865884
receivers:
866885
- prometheus/agent_prometheus
867886
metrics/loggingmetrics:
868887
exporters:
869-
- googlecloud
888+
- otlp/otlp
870889
processors:
871890
- transform/agent_prometheus_0
891+
- transform/agent_prometheus_1
892+
- transform/agent_prometheus_2
872893
- transform/loggingmetrics_0
873894
- filter/loggingmetrics_1
874895
- filter/loggingmetrics_2
@@ -879,26 +900,39 @@ service:
879900
- interval/loggingmetrics_7
880901
- metricstransform/loggingmetrics_8
881902
- resourcedetection/_global_0
903+
- resource/otlp/otlp_metrics_0
904+
- metricstarttime/otlp/otlp_metrics_1
905+
- batch/otlp/otlp_metrics_2
882906
receivers:
883907
- prometheus/agent_prometheus
884908
metrics/opsagent:
885909
exporters:
886-
- googlecloud
910+
- otlp/otlp
887911
processors:
888912
- transform/ops_agent_0
913+
- transform/ops_agent_1
914+
- transform/ops_agent_2
889915
- resourcedetection/_global_0
916+
- resource/otlp/otlp_metrics_0
917+
- metricstarttime/otlp/otlp_metrics_1
918+
- batch/otlp/otlp_metrics_2
890919
receivers:
891920
- otlpjsonfile/ops_agent
892921
metrics/otel:
893922
exporters:
894-
- googlecloud
923+
- otlp/otlp
895924
processors:
896925
- transform/agent_prometheus_0
926+
- transform/agent_prometheus_1
927+
- transform/agent_prometheus_2
897928
- transform/otel_0
898929
- filter/otel_1
899930
- filter/otel_2
900931
- metricstransform/otel_3
901932
- resourcedetection/_global_0
933+
- resource/otlp/otlp_metrics_0
934+
- metricstarttime/otlp/otlp_metrics_1
935+
- batch/otlp/otlp_metrics_2
902936
receivers:
903937
- prometheus/agent_prometheus
904938
metrics/otlp_otlp:
@@ -908,11 +942,11 @@ service:
908942
- resourcedetection/otlp_0
909943
- transform/otlp_1
910944
- groupbyattrs/otlp_2
911-
- resource/otlp_3
912-
- transform/otlp_4
913-
- metricstarttime/otlp_5
914-
- metricstransform/otlp_6
915-
- batch/otlp/otlp_metrics_0
945+
- transform/otlp_3
946+
- metricstransform/otlp_4
947+
- resource/otlp/otlp_metrics_0
948+
- metricstarttime/otlp/otlp_metrics_1
949+
- batch/otlp/otlp_metrics_2
916950
receivers:
917951
- otlp/otlp
918952
traces/traces_otlp_otlp:

0 commit comments

Comments
 (0)