Skip to content

Commit

Permalink
Disable high cardinality metrics in receivers. (#6475)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev authored Feb 22, 2024
1 parent 90557a8 commit d476c52
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 2 deletions.
7 changes: 7 additions & 0 deletions component/otelcol/receiver/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ type Arguments struct {

var _ receiver.Arguments = Arguments{}

// SetToDefault implements river.Defaulter.
func (args *Arguments) SetToDefault() {
*args = Arguments{
DebugMetrics: otelcol.DefaultDebugMetricsArguments,
}
}

// Validate implements river.Validator.
func (args *Arguments) Validate() error {
if args.Protocols.GRPC == nil &&
Expand Down
57 changes: 57 additions & 0 deletions component/otelcol/receiver/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/receiver/jaeger"
"github.com/grafana/agent/pkg/flow/componenttest"
"github.com/grafana/agent/pkg/util"
Expand Down Expand Up @@ -130,3 +131,59 @@ func getFreeAddr(t *testing.T) string {

return fmt.Sprintf("localhost:%d", portNumber)
}

func TestDebugMetricsConfig(t *testing.T) {
tests := []struct {
testName string
agentCfg string
expected otelcol.DebugMetricsArguments
}{
{
testName: "default",
agentCfg: `
protocols { thrift_compact {} }
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
{
testName: "explicit_false",
agentCfg: `
protocols { thrift_compact {} }
debug_metrics {
disable_high_cardinality_metrics = false
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: false,
},
},
{
testName: "explicit_true",
agentCfg: `
protocols { thrift_compact {} }
debug_metrics {
disable_high_cardinality_metrics = true
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
}

for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {
var args jaeger.Arguments
require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args))
_, err := args.Convert()
require.NoError(t, err)

require.Equal(t, tc.expected, args.DebugMetricsConfig())
})
}
}
1 change: 1 addition & 0 deletions component/otelcol/receiver/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var DefaultArguments = Arguments{
ExtractHeaders: false,
Headers: []string{},
},
DebugMetrics: otelcol.DefaultDebugMetricsArguments,
}

// SetToDefault implements river.Defaulter.
Expand Down
60 changes: 60 additions & 0 deletions component/otelcol/receiver/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/receiver/kafka"
"github.com/grafana/river"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -373,3 +374,62 @@ func TestArguments_Auth(t *testing.T) {
})
}
}

func TestDebugMetricsConfig(t *testing.T) {
tests := []struct {
testName string
agentCfg string
expected otelcol.DebugMetricsArguments
}{
{
testName: "default",
agentCfg: `
brokers = ["10.10.10.10:9092"]
protocol_version = "2.0.0"
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
{
testName: "explicit_false",
agentCfg: `
brokers = ["10.10.10.10:9092"]
protocol_version = "2.0.0"
debug_metrics {
disable_high_cardinality_metrics = false
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: false,
},
},
{
testName: "explicit_true",
agentCfg: `
brokers = ["10.10.10.10:9092"]
protocol_version = "2.0.0"
debug_metrics {
disable_high_cardinality_metrics = true
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
}

for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {
var args kafka.Arguments
require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args))
_, err := args.Convert()
require.NoError(t, err)

require.Equal(t, tc.expected, args.DebugMetricsConfig())
})
}
}
1 change: 1 addition & 0 deletions component/otelcol/receiver/opencensus/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var DefaultArguments = Arguments{
ReadBufferSize: 512 * units.Kibibyte,
// We almost write 0 bytes, so no need to tune WriteBufferSize.
},
DebugMetrics: otelcol.DefaultDebugMetricsArguments,
}

// SetToDefault implements river.Defaulter.
Expand Down
54 changes: 54 additions & 0 deletions component/otelcol/receiver/opencensus/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/receiver/opencensus"
"github.com/grafana/agent/pkg/flow/componenttest"
"github.com/grafana/agent/pkg/util"
Expand Down Expand Up @@ -97,3 +98,56 @@ func getFreeAddr(t *testing.T) string {

return fmt.Sprintf("localhost:%d", portNumber)
}

func TestDebugMetricsConfig(t *testing.T) {
tests := []struct {
testName string
agentCfg string
expected otelcol.DebugMetricsArguments
}{
{
testName: "default",
agentCfg: `
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
{
testName: "explicit_false",
agentCfg: `
debug_metrics {
disable_high_cardinality_metrics = false
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: false,
},
},
{
testName: "explicit_true",
agentCfg: `
debug_metrics {
disable_high_cardinality_metrics = true
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
}

for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {
var args opencensus.Arguments
require.NoError(t, river.Unmarshal([]byte(tc.agentCfg), &args))
_, err := args.Convert()
require.NoError(t, err)

require.Equal(t, tc.expected, args.DebugMetricsConfig())
})
}
}
7 changes: 7 additions & 0 deletions component/otelcol/receiver/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func (args *HTTPConfigArguments) Convert() *otlpreceiver.HTTPConfig {

var _ receiver.Arguments = Arguments{}

// SetToDefault implements river.Defaulter.
func (args *Arguments) SetToDefault() {
*args = Arguments{
DebugMetrics: otelcol.DefaultDebugMetricsArguments,
}
}

// Convert implements receiver.Arguments.
func (args Arguments) Convert() (otelcomponent.Config, error) {
return &otlpreceiver.Config{
Expand Down
62 changes: 62 additions & 0 deletions component/otelcol/receiver/otlp/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,65 @@ func TestUnmarshalHttpUrls(t *testing.T) {
assert.Equal(t, "custom/metrics", args.HTTP.MetricsURLPath)
assert.Equal(t, "custom/traces", args.HTTP.TracesURLPath)
}

func TestDebugMetricsConfig(t *testing.T) {
tests := []struct {
testName string
agentCfg string
expected otelcol.DebugMetricsArguments
}{
{
testName: "default",
agentCfg: `
grpc {
endpoint = "/v1/traces"
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: true,
},
},
{
testName: "explicit_false",
agentCfg: `
grpc {
endpoint = "/v1/traces"
}
debug_metrics {
disable_high_cardinality_metrics = false
}
output {}
`,
expected: otelcol.DebugMetricsArguments{
DisableHighCardinalityMetrics: false,
},
},
{
testName: "explicit_true",
agentCfg: `
grpc {
endpoint = "/v1/traces"
}
debug_metrics {
disable_high_cardinality_metrics = true
}
output {}
`,
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())
})
}
}
1 change: 1 addition & 0 deletions component/otelcol/receiver/vcenter/vcenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ var (
VcenterVMName: ResourceAttributeConfig{Enabled: true},
},
},
DebugMetrics: otelcol.DefaultDebugMetricsArguments,
}
)

Expand Down
Loading

0 comments on commit d476c52

Please sign in to comment.