From 3764d0fc713d96bb2644a4515c7c0cde3e9fbdfa Mon Sep 17 00:00:00 2001 From: Braydon Kains Date: Tue, 17 Oct 2023 11:57:18 -0400 Subject: [PATCH] fixing test failures --- Makefile | 1 + .../googlemanagedprometheusexporter/config.go | 18 +++----- .../config_test.go | 4 ++ .../factory.go | 6 +++ go.mod | 22 +++++----- go.sum | 22 ++++++++++ receiver/mongodbreceiver/scraper.go | 4 +- receiver/prometheusreceiver/config.go | 7 +-- receiver/prometheusreceiver/config_test.go | 1 + receiver/prometheusreceiver/factory.go | 2 +- .../prometheusreceiver/internal/appendable.go | 15 +++---- .../internal/metricfamily.go | 12 +++--- .../internal/metricfamily_test.go | 11 ++--- .../internal/transaction.go | 17 +++----- .../internal/transaction_test.go | 43 +++++++++---------- .../prometheusreceiver/metrics_receiver.go | 7 +-- .../metrics_receiver_helper_test.go | 6 +-- .../metrics_receiver_honor_timestamp_test.go | 5 +-- .../metrics_receiver_labels_test.go | 21 +++++---- ...ics_receiver_metric_name_normalize_test.go | 8 +--- .../metrics_receiver_non_numerical_test.go | 7 ++- .../metrics_receiver_open_metrics_test.go | 7 ++- .../metrics_receiver_target_allocator_test.go | 3 +- .../metrics_receiver_test.go | 9 ++-- .../metrics_reciever_metric_rename_test.go | 9 ++-- .../prometheusreceiver/testdata/config.yaml | 1 + receiver/varnishreceiver/scraper.go | 6 ++- 27 files changed, 145 insertions(+), 129 deletions(-) diff --git a/Makefile b/Makefile index ea529c3cd..0322bdfae 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ update-components: grep -v "go.opentelemetry.io/collector/featuregate" | \ grep -v "go.opentelemetry.io/collector/pdata" | \ xargs -t -I '{}' go get {}@$(OTEL_VER) + go get -u github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus@latest go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all | \ grep "^github.com/open-telemetry/opentelemetry-collector-contrib" | \ xargs -t -I '{}' go get {}@$(OTEL_VER) diff --git a/exporter/googlemanagedprometheusexporter/config.go b/exporter/googlemanagedprometheusexporter/config.go index 9b76e0a80..b1c2193a7 100644 --- a/exporter/googlemanagedprometheusexporter/config.go +++ b/exporter/googlemanagedprometheusexporter/config.go @@ -10,7 +10,6 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/featuregate" - "go.opentelemetry.io/collector/pdata/pmetric" ) // Config defines configuration for Google Cloud Managed Service for Prometheus exporter. @@ -41,8 +40,9 @@ type GMPConfig struct { type MetricConfig struct { // Prefix configures the prefix of metrics sent to GoogleManagedPrometheus. Defaults to prometheus.googleapis.com. // Changing this prefix is not recommended, as it may cause metrics to not be queryable with promql in the Cloud Monitoring UI. - Prefix string `mapstructure:"prefix"` - ClientConfig collector.ClientConfig `mapstructure:",squash"` + Prefix string `mapstructure:"prefix"` + ClientConfig collector.ClientConfig `mapstructure:",squash"` + Config googlemanagedprometheus.Config `mapstructure:",squash"` } func (c *GMPConfig) toCollectorConfig() collector.Config { @@ -56,21 +56,17 @@ func (c *GMPConfig) toCollectorConfig() collector.Config { cfg.MetricConfig.InstrumentationLibraryLabels = false cfg.MetricConfig.ServiceResourceLabels = false // Update metric naming to match GMP conventions - cfg.MetricConfig.GetMetricName = googlemanagedprometheus.GetMetricName + cfg.MetricConfig.GetMetricName = c.MetricConfig.Config.GetMetricName // Map to the prometheus_target monitored resource - cfg.MetricConfig.MapMonitoredResource = googlemanagedprometheus.MapToPrometheusTarget + cfg.MetricConfig.MapMonitoredResource = c.MetricConfig.Config.MapToPrometheusTarget cfg.MetricConfig.EnableSumOfSquaredDeviation = true // map the GMP config's fields to the collector config cfg.ProjectID = c.ProjectID cfg.UserAgent = c.UserAgent cfg.MetricConfig.ClientConfig = c.MetricConfig.ClientConfig + cfg.MetricConfig.ExtraMetrics = c.MetricConfig.Config.ExtraMetrics if c.UntypedDoubleExport { - cfg.MetricConfig.ExtraMetrics = func(m pmetric.Metrics) pmetric.ResourceMetricsSlice { - //nolint:errcheck - featuregate.GlobalRegistry().Set("gcp.untyped_double_export", true) - googlemanagedprometheus.AddUntypedMetrics(m) - return m.ResourceMetrics() - } + featuregate.GlobalRegistry().Set("gcp.untyped_double_export", true) } return cfg diff --git a/exporter/googlemanagedprometheusexporter/config_test.go b/exporter/googlemanagedprometheusexporter/config_test.go index 4dca7df50..f24996f94 100644 --- a/exporter/googlemanagedprometheusexporter/config_test.go +++ b/exporter/googlemanagedprometheusexporter/config_test.go @@ -16,6 +16,7 @@ import ( "go.opentelemetry.io/collector/otelcol/otelcoltest" "github.com/GoogleCloudPlatform/opentelemetry-operations-collector/exporter/googlemanagedprometheusexporter/internal/metadata" + "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus" ) func TestLoadConfig(t *testing.T) { @@ -43,6 +44,9 @@ func TestLoadConfig(t *testing.T) { GMPConfig: GMPConfig{ ProjectID: "my-project", UserAgent: "opentelemetry-collector-contrib {{version}}", + MetricConfig: MetricConfig{ + Config: googlemanagedprometheus.DefaultConfig(), + }, }, RetrySettings: exporterhelper.RetrySettings{ Enabled: true, diff --git a/exporter/googlemanagedprometheusexporter/factory.go b/exporter/googlemanagedprometheusexporter/factory.go index f41ad85fb..a02881140 100644 --- a/exporter/googlemanagedprometheusexporter/factory.go +++ b/exporter/googlemanagedprometheusexporter/factory.go @@ -10,6 +10,7 @@ import ( "time" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" + "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -38,6 +39,11 @@ func createDefaultConfig() component.Config { TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout}, RetrySettings: retrySettings, QueueSettings: exporterhelper.NewDefaultQueueSettings(), + GMPConfig: GMPConfig{ + MetricConfig: MetricConfig{ + Config: googlemanagedprometheus.DefaultConfig(), + }, + }, } } diff --git a/go.mod b/go.mod index b6ce204be..5883e9af6 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0.44.0 - github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.42.0 + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.44.0 github.com/NVIDIA/go-dcgm v0.0.0-20230811193702-90bac724c747 github.com/NVIDIA/go-nvml v0.11.6-0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v0.87.0 @@ -142,13 +142,13 @@ require ( go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0 // indirect go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 // indirect go.opentelemetry.io/proto/otlp v1.0.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect ) require ( cloud.google.com/go/compute/metadata v0.2.4-0.20230617002413-005d2dfb6b68 // indirect - cloud.google.com/go/longrunning v0.5.1 // indirect + cloud.google.com/go/longrunning v0.5.2 // indirect github.com/aerospike/aerospike-client-go/v6 v6.13.0 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.87.0 // indirect; indir6.0 @@ -157,11 +157,11 @@ require ( ) require ( - cloud.google.com/go v0.110.7 // indirect - cloud.google.com/go/compute v1.23.0 // indirect - cloud.google.com/go/logging v1.7.0 // indirect - cloud.google.com/go/monitoring v1.15.1 // indirect - cloud.google.com/go/trace v1.10.1 // indirect + cloud.google.com/go v0.110.8 // indirect + cloud.google.com/go/compute v1.23.1 // indirect + cloud.google.com/go/logging v1.8.1 // indirect + cloud.google.com/go/monitoring v1.16.1 // indirect + cloud.google.com/go/trace v1.10.2 // indirect contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect github.com/Azure/azure-sdk-for-go v65.0.0+incompatible // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect @@ -351,8 +351,8 @@ require ( gonum.org/v1/gonum v0.14.0 // indirect google.golang.org/api v0.146.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect - google.golang.org/grpc v1.58.2 // indirect + google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect + google.golang.org/grpc v1.58.3 // indirect google.golang.org/protobuf v1.31.0 gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 3b2687c5e..4858912b4 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOY cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o= cloud.google.com/go v0.110.7/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= +cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME= +cloud.google.com/go v0.110.8/go.mod h1:Iz8AkXJf1qmxC3Oxoep8R1T36w8B92yU29PcBhHO5fk= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -23,16 +25,24 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY= cloud.google.com/go/compute v1.23.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= +cloud.google.com/go/compute v1.23.1 h1:V97tBoDaZHb6leicZ1G6DLK2BAaZLJ/7+9BB/En3hR0= +cloud.google.com/go/compute v1.23.1/go.mod h1:CqB3xpmPKKt3OJpW2ndFIXnA9A4xAy/F3Xp1ixncW78= cloud.google.com/go/compute/metadata v0.2.4-0.20230617002413-005d2dfb6b68 h1:aRVqY1p2IJaBGStWMsQMpkAa83cPkCDLl80eOj0Rbz4= cloud.google.com/go/compute/metadata v0.2.4-0.20230617002413-005d2dfb6b68/go.mod h1:1a3eRNYX12fs5UABBIXS8HXVvQbX9hRB/RkEBPORpe8= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/logging v1.7.0 h1:CJYxlNNNNAMkHp9em/YEXcfJg+rPDg7YfwoRpMU+t5I= cloud.google.com/go/logging v1.7.0/go.mod h1:3xjP2CjkM3ZkO73aj4ASA5wRPGGCRrPIAeNqVNkzY8M= +cloud.google.com/go/logging v1.8.1 h1:26skQWPeYhvIasWKm48+Eq7oUqdcdbwsCVwz5Ys0FvU= +cloud.google.com/go/logging v1.8.1/go.mod h1:TJjR+SimHwuC8MZ9cjByQulAMgni+RkXeI3wwctHJEI= cloud.google.com/go/longrunning v0.5.1 h1:Fr7TXftcqTudoyRJa113hyaqlGdiBQkp0Gq7tErFDWI= cloud.google.com/go/longrunning v0.5.1/go.mod h1:spvimkwdz6SPWKEt/XBij79E9fiTkHSQl/fRUUQJYJc= +cloud.google.com/go/longrunning v0.5.2 h1:u+oFqfEwwU7F9dIELigxbe0XVnBAo9wqMuQLA50CZ5k= +cloud.google.com/go/longrunning v0.5.2/go.mod h1:nqo6DQbNV2pXhGDbDMoN2bWz68MjZUzqv2YttZiveCs= cloud.google.com/go/monitoring v1.15.1 h1:65JhLMd+JiYnXr6j5Z63dUYCuOg770p8a/VC+gil/58= cloud.google.com/go/monitoring v1.15.1/go.mod h1:lADlSAlFdbqQuwwpaImhsJXu1QSdd3ojypXrFSMr2rM= +cloud.google.com/go/monitoring v1.16.1 h1:CTklIuUkS5nCricGojPwdkSgPsCTX2HmYTxFDg+UvpU= +cloud.google.com/go/monitoring v1.16.1/go.mod h1:6HsxddR+3y9j+o/cMJH6q/KJ/CBTvM/38L/1m7bTRJ4= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -44,6 +54,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/trace v1.10.1 h1:EwGdOLCNfYOOPtgqo+D2sDLZmRCEO1AagRTJCU6ztdg= cloud.google.com/go/trace v1.10.1/go.mod h1:gbtL94KE5AJLH3y+WVpfWILmqgc6dXcqgNXdOPAQTYk= +cloud.google.com/go/trace v1.10.2 h1:80Rh4JSqJLfe/xGNrpyO4MQxiFDXcHG1XrsevfmrIRQ= +cloud.google.com/go/trace v1.10.2/go.mod h1:NPXemMi6MToRFcSxRl2uDnu/qAlAQ3oULUphcHGh1vA= contrib.go.opencensus.io/exporter/prometheus v0.4.2 h1:sqfsYl5GIY/L570iT+l93ehxaWJs2/OwXtiWwew3oAg= contrib.go.opencensus.io/exporter/prometheus v0.4.2/go.mod h1:dvEHbiKmgvbr5pjaF9fpw1KeYcjrnC1J8B+JKjsZyRQ= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= @@ -100,6 +112,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0 github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0.44.0/go.mod h1:ap6zVvkSC/UkZG8wI5FKpPs4EFNbsXqO6yyYHD5v6mY= github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.42.0 h1:Fa7XySHYw2HdumRuo2TYiYK5LkGJuwzTiqAPFoZ7t1s= github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.42.0/go.mod h1:7BFtqicd8QzUKtbxBHq8/by6aMYL3mmnEEK0vLtVins= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.44.0 h1:pBusS51rwSCzbF49NXee3/+rnVS6ikhLd7EWfLvQDyI= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus v0.44.0/go.mod h1:XDVqFuWntVYBlXsjC0Dn7QZkmTyVNjY+VR2Cl771gWo= github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.20.0 h1:uY/4lpbbFG73TgzmJoB7XMyFIheII95hlfH62uC+oS0= github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.20.0/go.mod h1:qaUEgkhkSlCNIu9/XD4y19vnbwKskfz2ep6Utf2A57c= github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.44.0 h1:ew7SfeajMJ3I4iXA1LERYY62fGCKO4TjVPw5QTPt47k= @@ -1475,10 +1489,16 @@ google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb h1:XFBgcDwm7irdHTbz4Zk2h7Mh+eis4nfJEFQFYzJzuIA= google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA= +google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI= google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI= google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k= +google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870= google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 h1:N3bU/SQDCDyD6R528GJ/PwW9KjYcJA3dgyH+MovAkIM= google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:KSqppvjFjtoCI+KGd4PELB0qLNxdJHRGqRI09mB6pQA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -1498,6 +1518,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= +google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/receiver/mongodbreceiver/scraper.go b/receiver/mongodbreceiver/scraper.go index a702dc50f..9b722accc 100644 --- a/receiver/mongodbreceiver/scraper.go +++ b/receiver/mongodbreceiver/scraper.go @@ -131,7 +131,9 @@ func (s *mongodbScraper) collectDatabase(ctx context.Context, now pcommon.Timest } s.recordNormalServerStats(now, serverStatus, databaseName, errs) - s.mb.EmitForResource(metadata.WithDatabase(databaseName)) + rb := s.mb.NewResourceBuilder() + rb.SetDatabase(databaseName) + s.mb.EmitForResource(metadata.WithResource(rb.Emit())) } func (s *mongodbScraper) collectAdminDatabase(ctx context.Context, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) { diff --git a/receiver/prometheusreceiver/config.go b/receiver/prometheusreceiver/config.go index c82b543de..cc991957d 100644 --- a/receiver/prometheusreceiver/config.go +++ b/receiver/prometheusreceiver/config.go @@ -47,9 +47,10 @@ const ( // Config defines configuration for Prometheus receiver. type Config struct { - PrometheusConfig *promconfig.Config `mapstructure:"-"` - BufferPeriod time.Duration `mapstructure:"buffer_period"` - BufferCount int `mapstructure:"buffer_count"` + PrometheusConfig *promconfig.Config `mapstructure:"-"` + TrimMetricSuffixes bool `mapstructure:"trim_metric_suffixes"` + BufferPeriod time.Duration `mapstructure:"buffer_period"` + BufferCount int `mapstructure:"buffer_count"` // UseStartTimeMetric enables retrieving the start time of all counter metrics // from the process_start_time_seconds metric. This is only correct if all counters on that endpoint // started after the process start time, and the process is the only actor exporting the metric after diff --git a/receiver/prometheusreceiver/config_test.go b/receiver/prometheusreceiver/config_test.go index 1e40a9edb..415b07de7 100644 --- a/receiver/prometheusreceiver/config_test.go +++ b/receiver/prometheusreceiver/config_test.go @@ -49,6 +49,7 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, r1.PrometheusConfig.ScrapeConfigs[0].JobName, "demo") assert.Equal(t, time.Duration(r1.PrometheusConfig.ScrapeConfigs[0].ScrapeInterval), 5*time.Second) assert.Equal(t, r1.UseStartTimeMetric, true) + assert.Equal(t, r1.TrimMetricSuffixes, true) assert.Equal(t, r1.StartTimeMetricRegex, "^(.+_)*process_start_time_seconds$") assert.Equal(t, "http://my-targetallocator-service", r1.TargetAllocator.Endpoint) diff --git a/receiver/prometheusreceiver/factory.go b/receiver/prometheusreceiver/factory.go index 9195af93b..656f83cba 100644 --- a/receiver/prometheusreceiver/factory.go +++ b/receiver/prometheusreceiver/factory.go @@ -64,5 +64,5 @@ func createMetricsReceiver( cfg component.Config, nextConsumer consumer.Metrics, ) (receiver.Metrics, error) { - return newPrometheusReceiver(set, cfg.(*Config), nextConsumer, featuregate.GlobalRegistry()), nil + return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil } diff --git a/receiver/prometheusreceiver/internal/appendable.go b/receiver/prometheusreceiver/internal/appendable.go index 01142bd23..9b528f5da 100644 --- a/receiver/prometheusreceiver/internal/appendable.go +++ b/receiver/prometheusreceiver/internal/appendable.go @@ -22,9 +22,8 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/storage" "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/featuregate" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/receiver" + "go.opentelemetry.io/collector/receiver/receiverhelper" ) // appendable translates Prometheus scraping diffs into OpenTelemetry format. @@ -32,13 +31,13 @@ type appendable struct { sink consumer.Metrics metricAdjuster MetricsAdjuster useStartTimeMetric bool + trimSuffixes bool preserveUntyped bool startTimeMetricRegex *regexp.Regexp externalLabels labels.Labels settings receiver.CreateSettings - obsrecv *obsreport.Receiver - registry *featuregate.Registry + obsrecv *receiverhelper.ObsReport } // NewAppendable returns a storage.Appendable instance that emits metrics to the sink. @@ -51,7 +50,7 @@ func NewAppendable( startTimeMetricRegex *regexp.Regexp, useCreatedMetric bool, externalLabels labels.Labels, - registry *featuregate.Registry) (storage.Appendable, error) { + trimSuffixes bool) (storage.Appendable, error) { var metricAdjuster MetricsAdjuster if !useStartTimeMetric { metricAdjuster = NewInitialPointAdjuster(set.Logger, gcInterval, useCreatedMetric) @@ -59,7 +58,7 @@ func NewAppendable( metricAdjuster = NewStartTimeMetricAdjuster(set.Logger, startTimeMetricRegex) } - obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: set.ID, Transport: transport, ReceiverCreateSettings: set}) + obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ReceiverID: set.ID, Transport: transport, ReceiverCreateSettings: set}) if err != nil { return nil, err } @@ -69,14 +68,14 @@ func NewAppendable( settings: set, metricAdjuster: metricAdjuster, useStartTimeMetric: useStartTimeMetric, + trimSuffixes: trimSuffixes, startTimeMetricRegex: startTimeMetricRegex, externalLabels: externalLabels, obsrecv: obsrecv, - registry: registry, preserveUntyped: preserveUntyped, }, nil } func (o *appendable) Appender(ctx context.Context) storage.Appender { - return newTransaction(ctx, o.metricAdjuster, o.sink, o.externalLabels, o.settings, o.obsrecv, o.registry, o.preserveUntyped) + return newTransaction(ctx, o.metricAdjuster, o.sink, o.externalLabels, o.settings, o.obsrecv, o.trimSuffixes, o.preserveUntyped) } diff --git a/receiver/prometheusreceiver/internal/metricfamily.go b/receiver/prometheusreceiver/internal/metricfamily.go index 232208fe8..28f93c490 100644 --- a/receiver/prometheusreceiver/internal/metricfamily.go +++ b/receiver/prometheusreceiver/internal/metricfamily.go @@ -21,6 +21,7 @@ import ( "sort" "strings" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" "github.com/prometheus/prometheus/model/exemplar" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/textparse" @@ -29,8 +30,6 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" ) const ( @@ -326,10 +325,13 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels return nil } -func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, normalizer *prometheus.Normalizer) { +func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, trimSuffixes bool) { metric := pmetric.NewMetric() - // Trims type's and unit's suffixes from metric name - metric.SetName(normalizer.TrimPromSuffixes(mf.name, mf.mtype, mf.metadata.Unit)) + name := mf.name + if trimSuffixes { + name = prometheus.TrimPromSuffixes(name, mf.mtype, mf.metadata.Unit) + } + metric.SetName(name) metric.SetDescription(mf.metadata.Help) metric.SetUnit(mf.metadata.Unit) diff --git a/receiver/prometheusreceiver/internal/metricfamily_test.go b/receiver/prometheusreceiver/internal/metricfamily_test.go index 311f46e20..1a9446dbf 100644 --- a/receiver/prometheusreceiver/internal/metricfamily_test.go +++ b/receiver/prometheusreceiver/internal/metricfamily_test.go @@ -24,12 +24,9 @@ import ( "github.com/prometheus/prometheus/model/value" "github.com/prometheus/prometheus/scrape" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" ) type testMetadataStore map[string]scrape.MetricMetadata @@ -241,7 +238,7 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) { for i, tv := range tt.scrapes { var lbls labels.Labels if tv.extraLabel.Name != "" { - lbls = labels.NewBuilder(tt.labels).Set(tv.extraLabel.Name, tv.extraLabel.Value).Labels(nil) + lbls = labels.NewBuilder(tt.labels).Set(tv.extraLabel.Name, tv.extraLabel.Value).Labels() } else { lbls = tt.labels.Copy() } @@ -263,7 +260,7 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) { require.Len(t, mp.groups, 1) sl := pmetric.NewMetricSlice() - mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry())) + mp.appendMetric(sl, false) require.Equal(t, 1, sl.Len(), "Exactly one metric expected") metric := sl.At(0) @@ -551,7 +548,7 @@ func TestMetricGroupData_toSummaryUnitTest(t *testing.T) { require.Len(t, mp.groups, 1) sl := pmetric.NewMetricSlice() - mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry())) + mp.appendMetric(sl, false) require.Equal(t, 1, sl.Len(), "Exactly one metric expected") metric := sl.At(0) @@ -657,7 +654,7 @@ func TestMetricGroupData_toNumberDataUnitTest(t *testing.T) { require.Len(t, mp.groups, 1) sl := pmetric.NewMetricSlice() - mp.appendMetric(sl, prometheus.NewNormalizer(featuregate.GlobalRegistry())) + mp.appendMetric(sl, false) require.Equal(t, 1, sl.Len(), "Exactly one metric expected") metric := sl.At(0) diff --git a/receiver/prometheusreceiver/internal/transaction.go b/receiver/prometheusreceiver/internal/transaction.go index 148a8bad4..532af3b85 100644 --- a/receiver/prometheusreceiver/internal/transaction.go +++ b/receiver/prometheusreceiver/internal/transaction.go @@ -29,14 +29,11 @@ import ( "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/featuregate" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver" + "go.opentelemetry.io/collector/receiver/receiverhelper" "go.uber.org/zap" - - prometheustranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" ) const ( @@ -45,6 +42,7 @@ const ( type transaction struct { isNew bool + trimSuffixes bool ctx context.Context families map[string]*metricFamily mc scrape.MetricMetadataStore @@ -53,10 +51,9 @@ type transaction struct { nodeResource pcommon.Resource logger *zap.Logger metricAdjuster MetricsAdjuster - obsrecv *obsreport.Receiver + obsrecv *receiverhelper.ObsReport // Used as buffer to calculate series ref hash. bufBytes []byte - normalizer *prometheustranslator.Normalizer preserveUntyped bool } @@ -66,20 +63,20 @@ func newTransaction( sink consumer.Metrics, externalLabels labels.Labels, settings receiver.CreateSettings, - obsrecv *obsreport.Receiver, - registry *featuregate.Registry, + obsrecv *receiverhelper.ObsReport, + trimSuffixes bool, preserveUntyped bool) *transaction { return &transaction{ ctx: ctx, families: make(map[string]*metricFamily), isNew: true, + trimSuffixes: trimSuffixes, sink: sink, metricAdjuster: metricAdjuster, externalLabels: externalLabels, logger: settings.Logger, obsrecv: obsrecv, bufBytes: make([]byte, 0, 1024), - normalizer: prometheustranslator.NewNormalizer(registry), preserveUntyped: preserveUntyped, } } @@ -213,7 +210,7 @@ func (t *transaction) getMetrics(resource pcommon.Resource) (pmetric.Metrics, er metrics := rms.ScopeMetrics().AppendEmpty().Metrics() for _, mf := range t.families { - mf.appendMetric(metrics, t.normalizer) + mf.appendMetric(metrics, t.trimSuffixes) } return md, nil diff --git a/receiver/prometheusreceiver/internal/transaction_test.go b/receiver/prometheusreceiver/internal/transaction_test.go index f8719f201..f2119c963 100644 --- a/receiver/prometheusreceiver/internal/transaction_test.go +++ b/receiver/prometheusreceiver/internal/transaction_test.go @@ -29,10 +29,9 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/featuregate" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/collector/receiver/receiverhelper" "go.opentelemetry.io/collector/receiver/receivertest" ) @@ -63,24 +62,24 @@ var ( ) func TestTransactionCommitWithoutAdding(t *testing.T) { - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) assert.NoError(t, tr.Commit()) } func TestTransactionRollbackDoesNothing(t *testing.T) { - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) assert.NoError(t, tr.Rollback()) } func TestTransactionUpdateMetadataDoesNothing(t *testing.T) { - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.UpdateMetadata(0, labels.New(), metadata.Metadata{}) assert.NoError(t, err) } func TestTransactionAppendNoTarget(t *testing.T) { badLabels := labels.FromStrings(model.MetricNameLabel, "counter_test") - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.Append(0, badLabels, time.Now().Unix()*1000, 1.0) assert.Error(t, err) } @@ -90,7 +89,7 @@ func TestTransactionAppendNoMetricName(t *testing.T) { model.InstanceLabel: "localhost:8080", model.JobLabel: "test2", }) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.Append(0, jobNotFoundLb, time.Now().Unix()*1000, 1.0) assert.ErrorIs(t, err, errMetricNameNotFound) @@ -98,7 +97,7 @@ func TestTransactionAppendNoMetricName(t *testing.T) { } func TestTransactionAppendEmptyMetricName(t *testing.T) { - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, consumertest.NewNop(), nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.Append(0, labels.FromMap(map[string]string{ model.InstanceLabel: "localhost:8080", model.JobLabel: "test2", @@ -109,7 +108,7 @@ func TestTransactionAppendEmptyMetricName(t *testing.T) { func TestTransactionAppendResource(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.Append(0, labels.FromMap(map[string]string{ model.InstanceLabel: "localhost:8080", model.JobLabel: "test", @@ -138,7 +137,7 @@ func TestTransactionCommitErrorWhenAdjusterError(t *testing.T) { }) sink := new(consumertest.MetricsSink) adjusterErr := errors.New("adjuster error") - tr := newTransaction(scrapeCtx, &errorAdjuster{err: adjusterErr}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &errorAdjuster{err: adjusterErr}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.Append(0, goodLabels, time.Now().Unix()*1000, 1.0) assert.NoError(t, err) assert.ErrorIs(t, tr.Commit(), adjusterErr) @@ -147,7 +146,7 @@ func TestTransactionCommitErrorWhenAdjusterError(t *testing.T) { // Ensure that we reject duplicate label keys. See https://github.com/open-telemetry/wg-prometheus/issues/44. func TestTransactionAppendDuplicateLabels(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) dupLabels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -165,7 +164,7 @@ func TestTransactionAppendDuplicateLabels(t *testing.T) { func TestTransactionAppendHistogramNoLe(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) goodLabels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -179,7 +178,7 @@ func TestTransactionAppendHistogramNoLe(t *testing.T) { func TestTransactionAppendSummaryNoQuantile(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) goodLabels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -193,7 +192,7 @@ func TestTransactionAppendSummaryNoQuantile(t *testing.T) { func TestAppendExemplarWithNoMetricName(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) labels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -206,7 +205,7 @@ func TestAppendExemplarWithNoMetricName(t *testing.T) { func TestAppendExemplarWithEmptyMetricName(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) labels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -219,7 +218,7 @@ func TestAppendExemplarWithEmptyMetricName(t *testing.T) { func TestAppendExemplarWithDuplicateLabels(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) labels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -235,7 +234,7 @@ func TestAppendExemplarWithDuplicateLabels(t *testing.T) { func TestAppendExemplarWithoutAddingMetric(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) labels := labels.FromStrings( model.InstanceLabel, "0.0.0.0:8855", @@ -249,7 +248,7 @@ func TestAppendExemplarWithoutAddingMetric(t *testing.T) { func TestAppendExemplarWithNoLabels(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.AppendExemplar(0, nil, exemplar.Exemplar{Value: 0}) assert.Equal(t, errNoJobInstance, err) @@ -257,14 +256,14 @@ func TestAppendExemplarWithNoLabels(t *testing.T) { func TestAppendExemplarWithEmptyLabelArray(t *testing.T) { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) _, err := tr.AppendExemplar(0, []labels.Label{}, exemplar.Exemplar{Value: 0}) assert.Equal(t, errNoJobInstance, err) } -func nopObsRecv(t *testing.T) *obsreport.Receiver { - obsrecv, err := obsreport.NewReceiver(obsreport.ReceiverSettings{ +func nopObsRecv(t *testing.T) *receiverhelper.ObsReport { + obsrecv, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: component.NewID("prometheus"), Transport: transport, ReceiverCreateSettings: receivertest.NewNopCreateSettings(), @@ -1361,7 +1360,7 @@ func (tt buildTestData) run(t *testing.T) { st := ts for i, page := range tt.inputs { sink := new(consumertest.MetricsSink) - tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), featuregate.GlobalRegistry(), true) + tr := newTransaction(scrapeCtx, &startTimeAdjuster{startTime: startTimestamp}, sink, nil, receivertest.NewNopCreateSettings(), nopObsRecv(t), false, true) for _, pt := range page.pts { // set ts for testing pt.t = st diff --git a/receiver/prometheusreceiver/metrics_receiver.go b/receiver/prometheusreceiver/metrics_receiver.go index 6e43579f5..12e3d613b 100644 --- a/receiver/prometheusreceiver/metrics_receiver.go +++ b/receiver/prometheusreceiver/metrics_receiver.go @@ -35,7 +35,6 @@ import ( "github.com/prometheus/prometheus/scrape" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/receiver" "go.uber.org/zap" "gopkg.in/yaml.v2" @@ -58,20 +57,18 @@ type pReceiver struct { loadConfigOnce sync.Once settings receiver.CreateSettings - registry *featuregate.Registry scrapeManager *scrape.Manager discoveryManager *discovery.Manager } // New creates a new prometheus.Receiver reference. -func newPrometheusReceiver(set receiver.CreateSettings, cfg *Config, next consumer.Metrics, registry *featuregate.Registry) *pReceiver { +func newPrometheusReceiver(set receiver.CreateSettings, cfg *Config, next consumer.Metrics) *pReceiver { pr := &pReceiver{ cfg: cfg, consumer: next, settings: set, configLoaded: make(chan struct{}), targetAllocatorStop: make(chan struct{}), - registry: registry, } return pr } @@ -277,7 +274,7 @@ func (r *pReceiver) initPrometheusComponents(ctx context.Context, host component startTimeMetricRegex, useCreatedMetricGate.IsEnabled(), r.cfg.PrometheusConfig.GlobalConfig.ExternalLabels, - r.registry, + r.cfg.TrimMetricSuffixes, ) if err != nil { return err diff --git a/receiver/prometheusreceiver/metrics_receiver_helper_test.go b/receiver/prometheusreceiver/metrics_receiver_helper_test.go index d120a105d..9b11cd855 100644 --- a/receiver/prometheusreceiver/metrics_receiver_helper_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_helper_test.go @@ -36,7 +36,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" @@ -586,7 +585,7 @@ func compareSummary(count uint64, sum float64, quantiles [][]float64) summaryPoi } // starts prometheus receiver with custom config, retrieves metrics from MetricsSink -func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, startTimeMetricRegex string, registry *featuregate.Registry, cfgMuts ...func(*promcfg.Config)) { +func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, startTimeMetricRegex string, trimMetricSuffixes bool, cfgMuts ...func(*promcfg.Config)) { ctx := context.Background() mp, cfg, err := setupMockPrometheus(targets...) for _, cfgMut := range cfgMuts { @@ -601,7 +600,8 @@ func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, s UseStartTimeMetric: useStartTimeMetric, StartTimeMetricRegex: startTimeMetricRegex, PreserveUntyped: true, // This adds a metric label for untyped metrics. Enabling this allows testing for it. - }, cms, registry) + TrimMetricSuffixes: trimMetricSuffixes, + }, cms) require.NoError(t, receiver.Start(ctx, componenttest.NewNopHost())) // verify state after shutdown is called diff --git a/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go b/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go index 691c6d2c4..adf5ac438 100644 --- a/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_honor_timestamp_test.go @@ -22,7 +22,6 @@ import ( promcfg "github.com/prometheus/prometheus/config" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -162,7 +161,7 @@ func TestHonorTimeStampsWithTrue(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } // TestHonorTimeStampsWithFalse validates that with honor_timestamp config set to false, @@ -180,7 +179,7 @@ func TestHonorTimeStampsWithFalse(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.HonorTimestamps = false } diff --git a/receiver/prometheusreceiver/metrics_receiver_labels_test.go b/receiver/prometheusreceiver/metrics_receiver_labels_test.go index 59e84a736..44c1ec457 100644 --- a/receiver/prometheusreceiver/metrics_receiver_labels_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_labels_test.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/relabel" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -41,7 +40,7 @@ func TestExternalLabels(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { cfg.GlobalConfig.ExternalLabels = labels.FromStrings("key", "value") }) } @@ -131,7 +130,7 @@ func TestLabelLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { // set label limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelLimit = 5 @@ -254,7 +253,7 @@ func TestLabelNameLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { // set label limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelNameLengthLimit = 20 @@ -290,7 +289,7 @@ func TestLabelValueLimitConfig(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { // set label name limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.LabelValueLengthLimit = 25 @@ -462,7 +461,7 @@ func TestEmptyLabelValues(t *testing.T) { validateFunc: verifyEmptyLabelValuesTarget2, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } const honorLabelsTarget = ` @@ -553,7 +552,7 @@ func TestEmptyLabels(t *testing.T) { validateFunc: verifyEmptyLabelsTarget1, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func TestHonorLabelsFalseConfig(t *testing.T) { @@ -567,7 +566,7 @@ func TestHonorLabelsFalseConfig(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyHonorLabelsTrue(t *testing.T, td *testData, rms []pmetric.ResourceMetrics) { @@ -609,7 +608,7 @@ func TestHonorLabelsTrueConfig(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { // set label name limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { scrapeCfg.HonorLabels = true @@ -635,7 +634,7 @@ func TestRelabelJobInstance(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -704,7 +703,7 @@ func TestTargetInfoResourceAttributes(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyTargetInfoResourceAttributes(t *testing.T, td *testData, rms []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go b/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go index 255834cc2..9421971fe 100644 --- a/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_metric_name_normalize_test.go @@ -18,8 +18,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -57,11 +55,7 @@ func TestMetricNormalize(t *testing.T) { }, } - registry := featuregate.NewRegistry() - _, err := registry.Register("pkg.translator.prometheus.NormalizeName", featuregate.StageBeta) - require.NoError(t, err) - - testComponent(t, targets, false, "", registry) + testComponent(t, targets, false, "", true) } func verifyNormalizeMetric(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go b/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go index db942d193..746a45b4b 100644 --- a/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_non_numerical_test.go @@ -22,7 +22,6 @@ import ( "github.com/GoogleCloudPlatform/opentelemetry-operations-collector/receiver/prometheusreceiver/internal" "github.com/prometheus/prometheus/model/value" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -83,7 +82,7 @@ func TestStaleNaNs(t *testing.T) { validateScrapes: true, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyStaleNaNs(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { @@ -257,7 +256,7 @@ func TestNormalNaNs(t *testing.T) { validateFunc: verifyNormalNaNs, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyNormalNaNs(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { @@ -341,7 +340,7 @@ func TestInfValues(t *testing.T) { validateFunc: verifyInfValues, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyInfValues(t *testing.T, td *testData, resourceMetrics []pmetric.ResourceMetrics) { diff --git a/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go b/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go index 498d7dd14..42c8d33f7 100644 --- a/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_open_metrics_test.go @@ -24,7 +24,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -82,7 +81,7 @@ func TestOpenMetricsPositive(t *testing.T) { targets = append(targets, testData) } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } func verifyNegativeTarget(t *testing.T, td *testData, mds []pmetric.ResourceMetrics) { @@ -115,7 +114,7 @@ func TestOpenMetricsNegative(t *testing.T) { targets = append(targets, testData) } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } // reads test data from testdata/openmetrics directory @@ -185,7 +184,7 @@ func TestInfoStatesetMetrics(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } diff --git a/receiver/prometheusreceiver/metrics_receiver_target_allocator_test.go b/receiver/prometheusreceiver/metrics_receiver_target_allocator_test.go index 5cc7a7717..90909114f 100644 --- a/receiver/prometheusreceiver/metrics_receiver_target_allocator_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_target_allocator_test.go @@ -34,7 +34,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/receiver/receivertest" ) @@ -505,7 +504,7 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) { defer allocator.Stop() tc.cfg.TargetAllocator.Endpoint = allocator.srv.URL // set service URL with the automatic generated one - receiver := newPrometheusReceiver(receivertest.NewNopCreateSettings(), tc.cfg, cms, featuregate.GlobalRegistry()) + receiver := newPrometheusReceiver(receivertest.NewNopCreateSettings(), tc.cfg, cms) require.NoError(t, receiver.Start(ctx, componenttest.NewNopHost())) diff --git a/receiver/prometheusreceiver/metrics_receiver_test.go b/receiver/prometheusreceiver/metrics_receiver_test.go index 36e2ba59c..149e18950 100644 --- a/receiver/prometheusreceiver/metrics_receiver_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_test.go @@ -22,7 +22,6 @@ import ( "github.com/prometheus/common/model" promConfig "github.com/prometheus/prometheus/config" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -1277,7 +1276,7 @@ func TestCoreMetricsEndToEnd(t *testing.T) { validateScrapes: true, }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } var startTimeMetricPage = ` @@ -1363,7 +1362,7 @@ func TestStartTimeMetric(t *testing.T) { validateFunc: verifyStartTimeMetricPage, }, } - testComponent(t, targets, true, "", featuregate.GlobalRegistry()) + testComponent(t, targets, true, "", false) } var startTimeMetricRegexPage = ` @@ -1412,7 +1411,7 @@ func TestStartTimeMetricRegex(t *testing.T) { validateFunc: verifyStartTimeMetricPage, }, } - testComponent(t, targets, true, "^(.+_)*process_start_time_seconds$", featuregate.GlobalRegistry()) + testComponent(t, targets, true, "^(.+_)*process_start_time_seconds$", false) } // metric type is defined as 'untyped' in the first metric @@ -1441,7 +1440,7 @@ func TestUntypedMetrics(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry()) + testComponent(t, targets, false, "", false) } diff --git a/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go b/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go index 27629975b..2d8c04885 100644 --- a/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go +++ b/receiver/prometheusreceiver/metrics_reciever_metric_rename_test.go @@ -22,7 +22,6 @@ import ( promcfg "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/model/relabel" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -60,7 +59,7 @@ func TestMetricRenaming(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -103,7 +102,7 @@ func TestMetricRenamingKeepAction(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -243,7 +242,7 @@ func TestLabelRenaming(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { @@ -369,7 +368,7 @@ func TestLabelRenamingKeepAction(t *testing.T) { }, } - testComponent(t, targets, false, "", featuregate.GlobalRegistry(), func(cfg *promcfg.Config) { + testComponent(t, targets, false, "", false, func(cfg *promcfg.Config) { for _, scrapeConfig := range cfg.ScrapeConfigs { scrapeConfig.MetricRelabelConfigs = []*relabel.Config{ { diff --git a/receiver/prometheusreceiver/testdata/config.yaml b/receiver/prometheusreceiver/testdata/config.yaml index f767602af..345eabecd 100644 --- a/receiver/prometheusreceiver/testdata/config.yaml +++ b/receiver/prometheusreceiver/testdata/config.yaml @@ -3,6 +3,7 @@ prometheus/customname: buffer_period: 234 buffer_count: 45 use_start_time_metric: true + trim_metric_suffixes: true start_time_metric_regex: '^(.+_)*process_start_time_seconds$' target_allocator: endpoint: http://my-targetallocator-service diff --git a/receiver/varnishreceiver/scraper.go b/receiver/varnishreceiver/scraper.go index 91cfa053e..91a0cbc40 100644 --- a/receiver/varnishreceiver/scraper.go +++ b/receiver/varnishreceiver/scraper.go @@ -78,6 +78,10 @@ func (v *varnishScraper) scrape(context.Context) (pmetric.Metrics, error) { now := pcommon.NewTimestampFromTime(time.Now()) + rb := v.mb.NewResourceBuilder() + rb.SetVarnishCacheName(v.cacheName) + //v.mb.EmitForResource() + v.recordVarnishBackendConnectionsCountDataPoint(now, stats) v.recordVarnishCacheOperationsCountDataPoint(now, stats) v.recordVarnishThreadOperationsCountDataPoint(now, stats) @@ -91,5 +95,5 @@ func (v *varnishScraper) scrape(context.Context) (pmetric.Metrics, error) { v.mb.RecordVarnishObjectCountDataPoint(now, stats.MAINNObject.Value) v.mb.RecordVarnishBackendRequestCountDataPoint(now, stats.MAINBackendReq.Value) - return v.mb.Emit(metadata.WithVarnishCacheName(v.cacheName)), nil + return v.mb.Emit(metadata.WithResource(rb.Emit())), nil }