From 088b74da4776b0cf817de21f7013b6b332c4795f Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Tue, 30 Jan 2024 15:20:40 +0000 Subject: [PATCH] Change the default value of disable_high_cardinality_metrics to "true". (#6255) --- CHANGELOG.md | 2 + component/otelcol/config_debug_metrics.go | 2 +- .../exporter/loadbalancing/loadbalancing.go | 3 +- .../loadbalancing/loadbalancing_test.go | 81 +++++++++++++++++++ component/otelcol/exporter/logging/logging.go | 1 + component/otelcol/exporter/otlp/otlp.go | 9 ++- component/otelcol/exporter/otlp/otlp_test.go | 59 ++++++++++++++ .../otelcol/exporter/otlphttp/otlphttp.go | 7 +- .../exporter/otlphttp/otlphttp_test.go | 59 ++++++++++++++ docs/sources/flow/release-notes.md | 5 ++ .../components/otelcol-debug-metrics-block.md | 2 +- 11 files changed, 220 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1886661ad21..0fd8586c33ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Main (unreleased) - Prohibit the configuration of services within modules. (@wildum) +- For `otelcol.exporter` components, change the default value of `disable_high_cardinality_metrics` to `true`. (@ptodev) + ### Features - A new `discovery.process` component for discovering Linux OS processes on the current host. (@korniltsev) diff --git a/component/otelcol/config_debug_metrics.go b/component/otelcol/config_debug_metrics.go index ca8575bee6de..f387f64cbfdf 100644 --- a/component/otelcol/config_debug_metrics.go +++ b/component/otelcol/config_debug_metrics.go @@ -7,7 +7,7 @@ type DebugMetricsArguments struct { // DefaultDebugMetricsArguments holds default settings for DebugMetricsArguments. var DefaultDebugMetricsArguments = DebugMetricsArguments{ - DisableHighCardinalityMetrics: false, + DisableHighCardinalityMetrics: true, } // SetToDefault implements river.Defaulter. diff --git a/component/otelcol/exporter/loadbalancing/loadbalancing.go b/component/otelcol/exporter/loadbalancing/loadbalancing.go index 3455318fef38..d4b8a87cf5f6 100644 --- a/component/otelcol/exporter/loadbalancing/loadbalancing.go +++ b/component/otelcol/exporter/loadbalancing/loadbalancing.go @@ -59,7 +59,8 @@ var ( Protocol: Protocol{ OTLP: DefaultOTLPConfig, }, - RoutingKey: "traceID", + RoutingKey: "traceID", + DebugMetrics: otelcol.DefaultDebugMetricsArguments, } DefaultOTLPConfig = OtlpConfig{ diff --git a/component/otelcol/exporter/loadbalancing/loadbalancing_test.go b/component/otelcol/exporter/loadbalancing/loadbalancing_test.go index 5e528dd373a3..abc37bc1703d 100644 --- a/component/otelcol/exporter/loadbalancing/loadbalancing_test.go +++ b/component/otelcol/exporter/loadbalancing/loadbalancing_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/grafana/agent/component/otelcol" "github.com/grafana/agent/component/otelcol/exporter/loadbalancing" "github.com/grafana/river" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter" @@ -268,3 +269,83 @@ func TestConfigConversion(t *testing.T) { }) } } + +func TestDebugMetricsConfig(t *testing.T) { + tests := []struct { + testName string + agentCfg string + expected otelcol.DebugMetricsArguments + }{ + { + testName: "default", + agentCfg: ` + resolver { + static { + hostnames = ["endpoint-1"] + } + } + protocol { + otlp { + client {} + } + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + { + testName: "explicit_false", + agentCfg: ` + resolver { + static { + hostnames = ["endpoint-1"] + } + } + protocol { + otlp { + client {} + } + } + debug_metrics { + disable_high_cardinality_metrics = false + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: false, + }, + }, + { + testName: "explicit_true", + agentCfg: ` + resolver { + static { + hostnames = ["endpoint-1"] + } + } + protocol { + otlp { + client {} + } + } + debug_metrics { + disable_high_cardinality_metrics = true + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.testName, func(t *testing.T) { + var args loadbalancing.Arguments + require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args)) + _, err := args.Convert() + require.NoError(t, err) + + require.Equal(t, tc.expected, args.DebugMetricsConfig()) + }) + } +} diff --git a/component/otelcol/exporter/logging/logging.go b/component/otelcol/exporter/logging/logging.go index 13d12fbf312e..3156309ab7cf 100644 --- a/component/otelcol/exporter/logging/logging.go +++ b/component/otelcol/exporter/logging/logging.go @@ -41,6 +41,7 @@ var DefaultArguments = Arguments{ Verbosity: configtelemetry.LevelNormal, SamplingInitial: 2, SamplingThereafter: 500, + DebugMetrics: otelcol.DefaultDebugMetricsArguments, } // SetToDefault implements river.Defaulter. diff --git a/component/otelcol/exporter/otlp/otlp.go b/component/otelcol/exporter/otlp/otlp.go index 7ca10d2c2c0b..f473c4722571 100644 --- a/component/otelcol/exporter/otlp/otlp.go +++ b/component/otelcol/exporter/otlp/otlp.go @@ -43,10 +43,11 @@ var _ exporter.Arguments = Arguments{} // DefaultArguments holds default values for Arguments. var DefaultArguments = Arguments{ - Timeout: otelcol.DefaultTimeout, - Queue: otelcol.DefaultQueueArguments, - Retry: otelcol.DefaultRetryArguments, - Client: DefaultGRPCClientArguments, + Timeout: otelcol.DefaultTimeout, + Queue: otelcol.DefaultQueueArguments, + Retry: otelcol.DefaultRetryArguments, + Client: DefaultGRPCClientArguments, + DebugMetrics: otelcol.DefaultDebugMetricsArguments, } // SetToDefault implements river.Defaulter. diff --git a/component/otelcol/exporter/otlp/otlp_test.go b/component/otelcol/exporter/otlp/otlp_test.go index 9c256ab94ba2..13bd8e56883d 100644 --- a/component/otelcol/exporter/otlp/otlp_test.go +++ b/component/otelcol/exporter/otlp/otlp_test.go @@ -143,3 +143,62 @@ func createTestTraces() ptrace.Traces { } return data } + +func TestDebugMetricsConfig(t *testing.T) { + tests := []struct { + testName string + agentCfg string + expected otelcol.DebugMetricsArguments + }{ + { + testName: "default", + agentCfg: ` + client { + endpoint = "tempo-xxx.grafana.net/tempo:443" + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + { + testName: "explicit_false", + agentCfg: ` + client { + endpoint = "tempo-xxx.grafana.net/tempo:443" + } + debug_metrics { + disable_high_cardinality_metrics = false + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: false, + }, + }, + { + testName: "explicit_true", + agentCfg: ` + client { + endpoint = "tempo-xxx.grafana.net/tempo:443" + } + debug_metrics { + disable_high_cardinality_metrics = true + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.testName, func(t *testing.T) { + var args otlp.Arguments + require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args)) + _, err := args.Convert() + require.NoError(t, err) + + require.Equal(t, tc.expected, args.DebugMetricsConfig()) + }) + } +} diff --git a/component/otelcol/exporter/otlphttp/otlphttp.go b/component/otelcol/exporter/otlphttp/otlphttp.go index 0508ec2e6289..b8d3aeaf6956 100644 --- a/component/otelcol/exporter/otlphttp/otlphttp.go +++ b/component/otelcol/exporter/otlphttp/otlphttp.go @@ -48,9 +48,10 @@ var _ exporter.Arguments = Arguments{} // DefaultArguments holds default values for Arguments. var DefaultArguments = Arguments{ - Queue: otelcol.DefaultQueueArguments, - Retry: otelcol.DefaultRetryArguments, - Client: DefaultHTTPClientArguments, + Queue: otelcol.DefaultQueueArguments, + Retry: otelcol.DefaultRetryArguments, + Client: DefaultHTTPClientArguments, + DebugMetrics: otelcol.DefaultDebugMetricsArguments, } // SetToDefault implements river.Defaulter. diff --git a/component/otelcol/exporter/otlphttp/otlphttp_test.go b/component/otelcol/exporter/otlphttp/otlphttp_test.go index 64e6328b2fb5..6a2449db6204 100644 --- a/component/otelcol/exporter/otlphttp/otlphttp_test.go +++ b/component/otelcol/exporter/otlphttp/otlphttp_test.go @@ -114,3 +114,62 @@ func createTestTraces() ptrace.Traces { } return data } + +func TestDebugMetricsConfig(t *testing.T) { + tests := []struct { + testName string + agentCfg string + expected otelcol.DebugMetricsArguments + }{ + { + testName: "default", + agentCfg: ` + client { + endpoint = "http://tempo:4317" + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + { + testName: "explicit_false", + agentCfg: ` + client { + endpoint = "http://tempo:4317" + } + debug_metrics { + disable_high_cardinality_metrics = false + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: false, + }, + }, + { + testName: "explicit_true", + agentCfg: ` + client { + endpoint = "http://tempo:4317" + } + debug_metrics { + disable_high_cardinality_metrics = true + } + `, + expected: otelcol.DebugMetricsArguments{ + DisableHighCardinalityMetrics: true, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.testName, func(t *testing.T) { + var args otlphttp.Arguments + require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args)) + _, err := args.Convert() + require.NoError(t, err) + + require.Equal(t, tc.expected, args.DebugMetricsConfig()) + }) + } +} diff --git a/docs/sources/flow/release-notes.md b/docs/sources/flow/release-notes.md index 7124b4a9bb28..06de96daafcf 100644 --- a/docs/sources/flow/release-notes.md +++ b/docs/sources/flow/release-notes.md @@ -36,6 +36,11 @@ Other release notes for the different {{< param "PRODUCT_ROOT_NAME" >}} variants Previously it was possible to configure the HTTP service via the [HTTP config block](https://grafana.com/docs/agent/v0.39/flow/reference/config-blocks/http/) inside of a module. This functionality is now only available in the main configuration. +### Breaking change: Change the default value of `disable_high_cardinality_metrics` to `true`. + +The `disable_high_cardinality_metrics` configuration argument is used by `otelcol.exporter` components such as `otelcol.exporter.otlp`. +If you need to see high cardinality metrics containing labels such as IP addresses and port numbers, you now have to explicitly set `disable_high_cardinality_metrics` to `false`. + ## v0.39 ### Breaking change: `otelcol.receiver.prometheus` will drop all `otel_scope_info` metrics when converting them to OTLP diff --git a/docs/sources/shared/flow/reference/components/otelcol-debug-metrics-block.md b/docs/sources/shared/flow/reference/components/otelcol-debug-metrics-block.md index f70facdf3541..2997d8c140e8 100644 --- a/docs/sources/shared/flow/reference/components/otelcol-debug-metrics-block.md +++ b/docs/sources/shared/flow/reference/components/otelcol-debug-metrics-block.md @@ -16,7 +16,7 @@ The following arguments are supported: Name | Type | Description | Default | Required -----------------------------------|-----------|------------------------------------------------------|---------|--------- -`disable_high_cardinality_metrics` | `boolean` | Whether to disable certain high cardinality metrics. | `false` | no +`disable_high_cardinality_metrics` | `boolean` | Whether to disable certain high cardinality metrics. | `true` | no `disable_high_cardinality_metrics` is the Grafana Agent equivalent to the `telemetry.disableHighCardinalityMetrics` feature gate in the OpenTelemetry Collector. It removes attributes that could cause high cardinality metrics.