Skip to content

Commit 468d4da

Browse files
sky333999jefchien
andauthored
Add AMP as a metrics destination (#1192)
Co-authored-by: Jeffrey Chien <[email protected]>
1 parent 01b5366 commit 468d4da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2391
-263
lines changed

cmd/config-translator/translator_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ func TestInvalidLogFilterConfig(t *testing.T) {
179179
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/invalidLogFilesWithFilters.json", false, expectedErrorMap)
180180
}
181181

182+
func TestMetricsDestinationsConfig(t *testing.T) {
183+
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/validMetricsDestinations.json", true, map[string]int{})
184+
expectedErrorMap := map[string]int{}
185+
expectedErrorMap["required"] = 1
186+
checkIfSchemaValidateAsExpected(t, "../../translator/config/sampleSchema/invalidMetricsDestinations.json", false, expectedErrorMap)
187+
}
188+
182189
// Validate all sampleConfig files schema
183190
func TestSampleConfigSchema(t *testing.T) {
184191
if files, err := os.ReadDir("../../translator/tocwconfig/sampleConfig/"); err == nil {

go.mod

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ replace (
2727
)
2828

2929
replace (
30+
// For clear resource attributes after copy functionality https://github.com/amazon-contributing/opentelemetry-collector-contrib/pull/148
31+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry => github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.0.0-20240903195955-5944792b593a
3032
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza => github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza v0.0.0-20240903195955-5944792b593a
3133
// Replace with contrib to revert upstream change https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/20519
3234
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus => github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/translator/prometheus v0.0.0-20240903195955-5944792b593a
@@ -99,7 +101,6 @@ require (
99101
github.com/gobwas/glob v0.2.3
100102
github.com/google/go-cmp v0.6.0
101103
github.com/google/uuid v1.6.0
102-
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
103104
github.com/hashicorp/golang-lru v1.0.2
104105
github.com/influxdata/telegraf v0.0.0-00010101000000-000000000000
105106
github.com/influxdata/wlog v0.0.0-20160411224016-7c63b0a71ef8
@@ -113,6 +114,7 @@ require (
113114
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter v0.103.0
114115
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter v0.103.0
115116
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter v0.103.0
117+
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter v0.103.0
116118
github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsproxy v0.103.0
117119
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.103.0
118120
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/ecsobserver v0.103.0
@@ -149,13 +151,14 @@ require (
149151
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.103.0
150152
github.com/pkg/errors v0.9.1
151153
github.com/prometheus/client_golang v1.19.1
152-
github.com/prometheus/common v0.54.0
154+
github.com/prometheus/common v0.55.0
153155
github.com/prometheus/prometheus v0.51.2-0.20240405174432-b4a973753c6e
154156
github.com/shirou/gopsutil v3.21.11+incompatible
155157
github.com/shirou/gopsutil/v3 v3.24.5
156158
github.com/stretchr/testify v1.9.0
157159
github.com/xeipuuv/gojsonschema v1.2.0
158160
go.opentelemetry.io/collector/component v0.103.0
161+
go.opentelemetry.io/collector/config/configauth v0.103.0
159162
go.opentelemetry.io/collector/config/configopaque v1.10.0
160163
go.opentelemetry.io/collector/config/configtelemetry v0.103.0
161164
go.opentelemetry.io/collector/config/configtls v0.103.0
@@ -249,7 +252,7 @@ require (
249252
github.com/cespare/xxhash/v2 v2.3.0 // indirect
250253
github.com/checkpoint-restore/go-criu/v5 v5.3.0 // indirect
251254
github.com/cilium/ebpf v0.11.0 // indirect
252-
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 // indirect
255+
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
253256
github.com/containerd/cgroups/v3 v3.0.3 // indirect
254257
github.com/containerd/console v1.0.3 // indirect
255258
github.com/containerd/errdefs v0.1.0 // indirect
@@ -306,6 +309,7 @@ require (
306309
github.com/gorilla/mux v1.8.1 // indirect
307310
github.com/gorilla/websocket v1.5.0 // indirect
308311
github.com/gosnmp/gosnmp v1.34.0 // indirect
312+
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
309313
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
310314
github.com/hashicorp/consul/api v1.29.1 // indirect
311315
github.com/hashicorp/cronexpr v1.1.2 // indirect
@@ -392,6 +396,7 @@ require (
392396
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.103.0 // indirect
393397
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.103.0 // indirect
394398
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.103.0 // indirect
399+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite v0.103.0 // indirect
395400
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.103.0 // indirect
396401
github.com/opencontainers/go-digest v1.0.0 // indirect
397402
github.com/opencontainers/image-spec v1.1.0 // indirect
@@ -409,7 +414,7 @@ require (
409414
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
410415
github.com/prometheus/client_model v0.6.1 // indirect
411416
github.com/prometheus/common/sigv4 v0.1.0 // indirect
412-
github.com/prometheus/procfs v0.15.0 // indirect
417+
github.com/prometheus/procfs v0.15.1 // indirect
413418
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
414419
github.com/relvacode/iso8601 v1.4.0 // indirect
415420
github.com/rogpeppe/go-internal v1.12.0 // indirect
@@ -428,6 +433,8 @@ require (
428433
github.com/tidwall/gjson v1.10.2 // indirect
429434
github.com/tidwall/match v1.1.1 // indirect
430435
github.com/tidwall/pretty v1.2.0 // indirect
436+
github.com/tidwall/tinylru v1.1.0 // indirect
437+
github.com/tidwall/wal v1.1.7 // indirect
431438
github.com/tinylib/msgp v1.1.6 // indirect
432439
github.com/tklauser/go-sysconf v0.3.12 // indirect
433440
github.com/tklauser/numcpus v0.6.1 // indirect
@@ -446,7 +453,6 @@ require (
446453
go.etcd.io/bbolt v1.3.10 // indirect
447454
go.opencensus.io v0.24.0 // indirect
448455
go.opentelemetry.io/collector v0.103.0 // indirect
449-
go.opentelemetry.io/collector/config/configauth v0.103.0 // indirect
450456
go.opentelemetry.io/collector/config/configcompression v1.10.0 // indirect
451457
go.opentelemetry.io/collector/config/configgrpc v0.103.0 // indirect
452458
go.opentelemetry.io/collector/config/confighttp v0.103.0 // indirect
@@ -482,16 +488,16 @@ require (
482488
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
483489
golang.org/x/crypto v0.25.0 // indirect
484490
golang.org/x/mod v0.17.0 // indirect
485-
golang.org/x/oauth2 v0.20.0 // indirect
491+
golang.org/x/oauth2 v0.21.0 // indirect
486492
golang.org/x/term v0.22.0 // indirect
487493
golang.org/x/time v0.5.0 // indirect
488494
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
489495
gonum.org/v1/gonum v0.15.0 // indirect
490496
google.golang.org/api v0.169.0 // indirect
491497
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
492-
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
493-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
494-
google.golang.org/grpc v1.64.1 // indirect
498+
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
499+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
500+
google.golang.org/grpc v1.65.0 // indirect
495501
google.golang.org/protobuf v1.34.2 // indirect
496502
gopkg.in/inf.v0 v0.9.1 // indirect
497503
gopkg.in/ini.v1 v1.67.0 // indirect

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ github.com/amazon-contributing/opentelemetry-collector-contrib/internal/kubelet
210210
github.com/amazon-contributing/opentelemetry-collector-contrib/internal/kubelet v0.0.0-20240903195955-5944792b593a/go.mod h1:4qvmHiXPOkOXJdpmmxMqprb2BXxOGPgOG45BwLdipUM=
211211
github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-20240903195955-5944792b593a h1:EQQLrlrDkjs3rm1i+vj0zTrdJkBdGS5n1w0tmcLNEz8=
212212
github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws v0.0.0-20240903195955-5944792b593a/go.mod h1:t/hYoRTnlPuRjh8y0BwVGgNvNIXpU2QJME5YVppUUHQ=
213+
github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.0.0-20240903195955-5944792b593a h1:6rB8vnscjDsrl/vU7wZh9e4r6ZQBnqzdVuo8kUOUejQ=
214+
github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.0.0-20240903195955-5944792b593a/go.mod h1:Rr5b3hr6Jy9w/zTjsOl3vcyDDusc90P+iGdOd0UCYOo=
213215
github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza v0.0.0-20240903195955-5944792b593a h1:ansEEnZyu1rMVJJP+Pb55RSyFZU8U4QwgYDk6tlMTOQ=
214216
github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza v0.0.0-20240903195955-5944792b593a/go.mod h1:2NSghK+mafMGxM8c4Gff8qcprdMD3YQebZtD9UAdB3E=
215217
github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/translator/prometheus v0.0.0-20240903195955-5944792b593a h1:U9tYL8FEcwCBNVTTcFGbC+MLmIYaqQQSTUfZLi2rbjg=
@@ -378,8 +380,8 @@ github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h
378380
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
379381
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
380382
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
381-
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc=
382-
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM=
383+
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw=
384+
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
383385
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
384386
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
385387
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
@@ -1175,8 +1177,6 @@ github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.103.0
11751177
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.103.0/go.mod h1:hmeKPJaZjzOjcndDxpWnjt0781EMqvj3or01baNVoRI=
11761178
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.103.0 h1:1cZyMMLSpSWFdfITyVc9Bb+8rn175/GGwtWZQ3nClpc=
11771179
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.103.0/go.mod h1:o8BPP4DM2SkdkPJxJOdmgxKz5DftGcuyUXgqf5MoWAw=
1178-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.103.0 h1:imXTMt9ravkIqcvvow0ya3aQh64OOiQpMOyWeG/SLDQ=
1179-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.103.0/go.mod h1:DR/fbOxaIyobmsd8nbDzuwqwwSNX9+yONDWx8dF2qS4=
11801180
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling v0.103.0 h1:L1DCWusakqlxHC/5yfAfq4c5og1kFdJKV0jcw7FDdoE=
11811181
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling v0.103.0/go.mod h1:Ok6bUxGfoGMUBvO0Lwgp3xsHHKqe0TMq4juIl7X3Oxo=
11821182
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.103.0 h1:GiP0syg12+MrI5IpL8Qt+rQktWDMsP0/8Nu9qmMtscw=
@@ -1313,8 +1313,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8
13131313
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
13141314
github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
13151315
github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
1316-
github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=
1317-
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
1316+
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
1317+
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
13181318
github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4=
13191319
github.com/prometheus/common/sigv4 v0.1.0/go.mod h1:2Jkxxk9yYvCkE5G1sQT7GuEXm57JrvHu9k5YwTjsNtI=
13201320
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
@@ -1323,8 +1323,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
13231323
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
13241324
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
13251325
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
1326-
github.com/prometheus/procfs v0.15.0 h1:A82kmvXJq2jTu5YUhSGNlYoxh85zLnKgPz4bMZgI5Ek=
1327-
github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk=
1326+
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
1327+
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
13281328
github.com/prometheus/prometheus v0.51.2-0.20240405174432-b4a973753c6e h1:UmqAuY2OyDoog8+l5FybViJE5B2r+UxVGCUwFTsY5AA=
13291329
github.com/prometheus/prometheus v0.51.2-0.20240405174432-b4a973753c6e/go.mod h1:+0ld+ozir7zWFcHA2vVpWAKxXakIioEjPPNOqH+J3ZA=
13301330
github.com/rabbitmq/amqp091-go v1.2.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
@@ -1790,8 +1790,8 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr
17901790
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
17911791
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
17921792
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
1793-
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
1794-
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
1793+
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
1794+
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
17951795
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
17961796
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
17971797
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -2059,10 +2059,10 @@ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxH
20592059
google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
20602060
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
20612061
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
2062-
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
2063-
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
2064-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 h1:Q2RxlXqh1cgzzUgV261vBO2jI5R/3DD1J2pM0nI4NhU=
2065-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
2062+
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw=
2063+
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
2064+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
2065+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
20662066
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
20672067
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
20682068
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
@@ -2082,8 +2082,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv
20822082
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
20832083
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
20842084
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
2085-
google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA=
2086-
google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0=
2085+
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
2086+
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
20872087
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
20882088
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
20892089
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

internal/metric/metric.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,67 @@ var serviceInputMeasurements = collections.NewSet[string](
1717
"prometheus",
1818
)
1919

20+
// DataPoint is used to provide a common interface for OTEL metric data points.
21+
type DataPoint[T any] interface {
22+
pmetric.NumberDataPoint | pmetric.HistogramDataPoint | pmetric.ExponentialHistogramDataPoint | pmetric.SummaryDataPoint
23+
MoveTo(dest T)
24+
Attributes() pcommon.Map
25+
StartTimestamp() pcommon.Timestamp
26+
SetStartTimestamp(pcommon.Timestamp)
27+
Timestamp() pcommon.Timestamp
28+
SetTimestamp(pcommon.Timestamp)
29+
CopyTo(dest T)
30+
}
31+
32+
// DataPoints is used to provide a common interface for OTEL slice types.
33+
type DataPoints[T DataPoint[T]] interface {
34+
Len() int
35+
At(i int) T
36+
EnsureCapacity(newCap int)
37+
AppendEmpty() T
38+
RemoveIf(f func(T) bool)
39+
}
40+
41+
func RangeMetrics(md pmetric.Metrics, fn func(m pmetric.Metric)) {
42+
rms := md.ResourceMetrics()
43+
for i := 0; i < rms.Len(); i++ {
44+
ilms := rms.At(i).ScopeMetrics()
45+
for j := 0; j < ilms.Len(); j++ {
46+
ms := ilms.At(j).Metrics()
47+
for k := 0; k < ms.Len(); k++ {
48+
fn(ms.At(k))
49+
}
50+
}
51+
}
52+
}
53+
54+
func RangeDataPointAttributes(m pmetric.Metric, fn func(attrs pcommon.Map)) {
55+
switch m.Type() {
56+
case pmetric.MetricTypeGauge:
57+
rangeDataPointAttributes[pmetric.NumberDataPoint](m.Gauge().DataPoints(), fn)
58+
case pmetric.MetricTypeSum:
59+
rangeDataPointAttributes[pmetric.NumberDataPoint](m.Sum().DataPoints(), fn)
60+
case pmetric.MetricTypeHistogram:
61+
rangeDataPointAttributes[pmetric.HistogramDataPoint](m.Histogram().DataPoints(), fn)
62+
case pmetric.MetricTypeExponentialHistogram:
63+
rangeDataPointAttributes[pmetric.ExponentialHistogramDataPoint](m.ExponentialHistogram().DataPoints(), fn)
64+
case pmetric.MetricTypeSummary:
65+
rangeDataPointAttributes[pmetric.SummaryDataPoint](m.Summary().DataPoints(), fn)
66+
}
67+
}
68+
69+
func RangeDataPoints[T DataPoint[T]](dps DataPoints[T], fn func(dp T)) {
70+
for i := 0; i < dps.Len(); i++ {
71+
fn(dps.At(i))
72+
}
73+
}
74+
75+
func rangeDataPointAttributes[T DataPoint[T]](dps DataPoints[T], fn func(attrs pcommon.Map)) {
76+
RangeDataPoints[T](dps, func(dp T) {
77+
fn(dp.Attributes())
78+
})
79+
}
80+
2081
type Metrics struct {
2182
metrics pmetric.MetricSlice
2283
}

0 commit comments

Comments
 (0)