Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## main / unreleased

* [CHANGE] Expose metrics_generator.trace_id_label_name to user-configurable overrides API [#5972](https://github.com/grafana/tempo/pull/5972) (@carles-grafana)
* [CHANGE] Remove remaining aws-sdk-go references and migrate tests to MinIO [#5856](https://github.com/grafana/tempo/pull/5856) (@anglerfishlyy)
* [CHANGE] **BREAKING CHANGE** Validate tenant ID in frontend and distributor [#5786](https://github.com/grafana/tempo/pull/5786) (@carles-grafana)
* [CHANGE] Remove busybox from Tempo image to make it more minimal and prevent future vulnerabilities [#5717](https://github.com/grafana/tempo/pull/5717) (@carles-grafana)
Expand Down
6 changes: 6 additions & 0 deletions cmd/tempo/app/overrides_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,11 @@ func (v *overridesValidator) Validate(limits *client.Limits) error {
}
}

if traceIDLabelName, ok := limits.GetMetricsGenerator().GetTraceIDLabelName(); ok {
if err := validation.ValidateTraceIDLabelName(traceIDLabelName); err != nil {
return err
}
}

return nil
}
23 changes: 23 additions & 0 deletions cmd/tempo/app/overrides_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
filterconfig "github.com/grafana/tempo/pkg/spanfilter/config"
)

func strPtr(s string) *string {
return &s
}

func Test_runtimeOverridesValidator(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -208,6 +212,25 @@ func Test_overridesValidator(t *testing.T) {
},
expErr: "metrics_generator.collection_interval \"10m0s\" is outside acceptable range of 15s to 5m",
},
{
name: "metrics_generator.trace_id_label_name empty is allowed",
cfg: Config{},
limits: client.Limits{
MetricsGenerator: client.LimitsMetricsGenerator{
TraceIDLabelName: strPtr(""),
},
},
},
{
name: "metrics_generator.trace_id_label_name invalid",
cfg: Config{},
limits: client.Limits{
MetricsGenerator: client.LimitsMetricsGenerator{
TraceIDLabelName: strPtr("trace-id"),
},
},
expErr: "trace_id_label_name \"trace-id\" is not a valid Prometheus label name",
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ metrics_generator:

[processors: <list of strings>]
[collection_interval: <duration>]
[trace_id_label_name: <string>]
[disable_collection: <bool> | default = false]
[generate_native_histograms: <classic|native|both> | default = classic]
[native_histogram_max_bucket_number: <int> | default = 100]
Expand Down
2 changes: 1 addition & 1 deletion modules/generator/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m *mockOverrides) MetricsGeneratorGenerateNativeHistograms(string) histogr
return m.nativeHistograms
}

func (m *mockOverrides) MetricsGenerationTraceIDLabelName(string) string {
func (m *mockOverrides) MetricsGeneratorTraceIDLabelName(string) string {
return ""
}

Expand Down
2 changes: 1 addition & 1 deletion modules/generator/registry/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Overrides interface {
MetricsGeneratorCollectionInterval(userID string) time.Duration
MetricsGeneratorDisableCollection(userID string) bool
MetricsGeneratorGenerateNativeHistograms(userID string) histograms.HistogramMethod
MetricsGenerationTraceIDLabelName(userID string) string
MetricsGeneratorTraceIDLabelName(userID string) string
MetricsGeneratorNativeHistogramBucketFactor(userID string) float64
MetricsGeneratorNativeHistogramMaxBucketNumber(userID string) uint32
MetricsGeneratorNativeHistogramMinResetDuration(userID string) time.Duration
Expand Down
2 changes: 1 addition & 1 deletion modules/generator/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (r *ManagedRegistry) NewCounter(name string) Counter {
}

func (r *ManagedRegistry) NewHistogram(name string, buckets []float64, histogramOverride HistogramMode) (h Histogram) {
traceIDLabelName := r.overrides.MetricsGenerationTraceIDLabelName(r.tenant)
traceIDLabelName := r.overrides.MetricsGeneratorTraceIDLabelName(r.tenant)

// TODO: Temporary switch: use the old implementation when native histograms
// are disabled, eventually the new implementation can handle all cases
Expand Down
2 changes: 1 addition & 1 deletion modules/generator/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (m *mockOverrides) MetricsGeneratorGenerateNativeHistograms(_ string) histo
return m.generateNativeHistograms
}

func (m *mockOverrides) MetricsGenerationTraceIDLabelName(string) string {
func (m *mockOverrides) MetricsGeneratorTraceIDLabelName(string) string {
return ""
}

Expand Down
7 changes: 7 additions & 0 deletions modules/generator/validation/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ func ValidateDimensions(dimensions []string, intrinsicDimensions []string, dimen
}
return nil
}

func ValidateTraceIDLabelName(traceIDLabelName string) error {
if traceIDLabelName != SanitizeLabelName(traceIDLabelName) {
return fmt.Errorf("trace_id_label_name \"%s\" is not a valid Prometheus label name", traceIDLabelName)
}
return nil
}
2 changes: 1 addition & 1 deletion modules/overrides/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Interface interface {
MetricsGeneratorCollectionInterval(userID string) time.Duration
MetricsGeneratorDisableCollection(userID string) bool
MetricsGeneratorGenerateNativeHistograms(userID string) histograms.HistogramMethod
MetricsGenerationTraceIDLabelName(userID string) string
MetricsGeneratorTraceIDLabelName(userID string) string
MetricsGeneratorRemoteWriteHeaders(userID string) map[string]string
MetricsGeneratorForwarderQueueSize(userID string) int
MetricsGeneratorForwarderWorkers(userID string) int
Expand Down
4 changes: 2 additions & 2 deletions modules/overrides/runtime_config_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ func (o *runtimeConfigOverridesManager) MetricsGeneratorNativeHistogramMinResetD
return o.defaultLimits.MetricsGenerator.NativeHistogramMinResetDuration
}

// MetricsGenerationTraceIDLabelName is the label name used for the trace ID in metrics.
// MetricsGeneratorTraceIDLabelName is the label name used for the trace ID in metrics.
// "TraceID" is used if no value is provided.
func (o *runtimeConfigOverridesManager) MetricsGenerationTraceIDLabelName(userID string) string {
func (o *runtimeConfigOverridesManager) MetricsGeneratorTraceIDLabelName(userID string) string {
return o.getOverridesForUser(userID).MetricsGenerator.TraceIDLabelName
}

Expand Down
7 changes: 7 additions & 0 deletions modules/overrides/user_configurable_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ func (o *userConfigurableOverridesManager) MetricsGeneratorDisableCollection(use
return o.Interface.MetricsGeneratorDisableCollection(userID)
}

func (o *userConfigurableOverridesManager) MetricsGeneratorTraceIDLabelName(userID string) string {
if traceIDLabelName, ok := o.getTenantLimits(userID).GetMetricsGenerator().GetTraceIDLabelName(); ok {
return traceIDLabelName
}
return o.Interface.MetricsGeneratorTraceIDLabelName(userID)
}

func (o *userConfigurableOverridesManager) MetricsGeneratorGenerateNativeHistograms(userID string) histograms.HistogramMethod {
if method, ok := o.getTenantLimits(userID).GetMetricsGenerator().GetGenerateNativeHistograms(); ok {
return method
Expand Down
7 changes: 5 additions & 2 deletions modules/overrides/user_configurable_overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestUserConfigOverridesManager_allFields(t *testing.T) {
Processors: map[string]struct{}{"service-graphs": {}},
DisableCollection: boolPtr(true),
CollectionInterval: &userconfigurableoverrides.Duration{Duration: 60 * time.Second},
TraceIDLabelName: strPtr("trace_id"),
GenerateNativeHistograms: (*histograms.HistogramMethod)(strPtr("native")),
NativeHistogramMaxBucketNumber: func(u uint32) *uint32 { return &u }(101),
Processor: userconfigurableoverrides.LimitsMetricsGeneratorProcessor{
Expand Down Expand Up @@ -160,6 +161,7 @@ func TestUserConfigOverridesManager_allFields(t *testing.T) {
assert.Equal(t, uint32(101), mgr.MetricsGeneratorNativeHistogramMaxBucketNumber(tenant1))
assert.Equal(t, []string{"sg-dimension"}, mgr.MetricsGeneratorProcessorServiceGraphsDimensions(tenant1))
assert.Equal(t, 60*time.Second, mgr.MetricsGeneratorCollectionInterval(tenant1))
assert.Equal(t, "trace_id", mgr.MetricsGeneratorTraceIDLabelName(tenant1))
assert.Equal(t, true, mgr.MetricsGeneratorProcessorServiceGraphsEnableClientServerPrefix(tenant1))
enableVirtualNodeLabelValue, enableVirtualNodeLabelIsSet := mgr.MetricsGeneratorProcessorServiceGraphsEnableVirtualNodeLabel(tenant1)
assert.Equal(t, true, enableVirtualNodeLabelValue)
Expand Down Expand Up @@ -415,7 +417,8 @@ func TestUserConfigOverridesManager_MergeRuntimeConfig(t *testing.T) {
mgr.tenantLimits[tenantID] = &userconfigurableoverrides.Limits{
Forwarders: &[]string{"my-other-forwarder"},
MetricsGenerator: userconfigurableoverrides.LimitsMetricsGenerator{
Processors: map[string]struct{}{"local-blocks": {}},
Processors: map[string]struct{}{"local-blocks": {}},
TraceIDLabelName: strPtr("custom_trace_id"),
},
}

Expand Down Expand Up @@ -444,7 +447,7 @@ func TestUserConfigOverridesManager_MergeRuntimeConfig(t *testing.T) {
assert.Equal(t, mgr.MetricsGeneratorMaxActiveSeries(tenantID), baseMgr.MetricsGeneratorMaxActiveSeries(tenantID))
assert.Equal(t, mgr.MetricsGeneratorCollectionInterval(tenantID), baseMgr.MetricsGeneratorCollectionInterval(tenantID))
assert.Equal(t, mgr.MetricsGeneratorDisableCollection(tenantID), baseMgr.MetricsGeneratorDisableCollection(tenantID))
assert.Equal(t, mgr.MetricsGenerationTraceIDLabelName(tenantID), baseMgr.MetricsGenerationTraceIDLabelName(tenantID))
assert.Equal(t, "custom_trace_id", mgr.MetricsGeneratorTraceIDLabelName(tenantID))
assert.Equal(t, mgr.MetricsGeneratorForwarderQueueSize(tenantID), baseMgr.MetricsGeneratorForwarderQueueSize(tenantID))
assert.Equal(t, mgr.MetricsGeneratorForwarderWorkers(tenantID), baseMgr.MetricsGeneratorForwarderWorkers(tenantID))
assert.Equal(t, mgr.MetricsGeneratorProcessorServiceGraphsHistogramBuckets(tenantID), baseMgr.MetricsGeneratorProcessorServiceGraphsHistogramBuckets(tenantID))
Expand Down
1 change: 1 addition & 0 deletions modules/overrides/userconfigurable/api/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func limitsFromOverrides(overrides overrides.Interface, userID string) *client.L
Processors: overrides.MetricsGeneratorProcessors(userID),
DisableCollection: boolPtr(overrides.MetricsGeneratorDisableCollection(userID)),
CollectionInterval: timePtr(overrides.MetricsGeneratorCollectionInterval(userID)),
TraceIDLabelName: strPtr(overrides.MetricsGeneratorTraceIDLabelName(userID)),
GenerateNativeHistograms: histogramModePtr(overrides.MetricsGeneratorGenerateNativeHistograms(userID)),
NativeHistogramMaxBucketNumber: uint32Ptr(overrides.MetricsGeneratorNativeHistogramMaxBucketNumber(userID)),
Processor: client.LimitsMetricsGeneratorProcessor{
Expand Down
2 changes: 2 additions & 0 deletions modules/overrides/userconfigurable/api/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Test_limitsFromOverrides(t *testing.T) {
Processors: map[string]struct{}{"service-graphs": {}},
CollectionInterval: 15 * time.Second,
DisableCollection: true,
TraceIDLabelName: "trace_id",
GenerateNativeHistograms: histograms.HistogramMethodBoth,
NativeHistogramMaxBucketNumber: 160,
Processor: overrides.ProcessorOverrides{
Expand Down Expand Up @@ -78,6 +79,7 @@ func Test_limitsFromOverrides(t *testing.T) {
],
"disable_collection": true,
"collection_interval": "15s",
"trace_id_label_name": "trace_id",
"generate_native_histograms": "both",
"native_histogram_max_bucket_number": 160,
"processor": {
Expand Down
8 changes: 8 additions & 0 deletions modules/overrides/userconfigurable/client/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type LimitsMetricsGenerator struct {
Processors listtomap.ListToMap `yaml:"processors,omitempty" json:"processors,omitempty"`
DisableCollection *bool `yaml:"disable_collection,omitempty" json:"disable_collection,omitempty"`
CollectionInterval *Duration `yaml:"collection_interval,omitempty" json:"collection_interval,omitempty"`
TraceIDLabelName *string `yaml:"trace_id_label_name,omitempty" json:"trace_id_label_name,omitempty"`
GenerateNativeHistograms *histograms.HistogramMethod `yaml:"generate_native_histograms" json:"generate_native_histograms,omitempty"`
NativeHistogramMaxBucketNumber *uint32 `yaml:"native_histogram_max_bucket_number,omitempty" json:"native_histogram_max_bucket_number,omitempty"`

Expand Down Expand Up @@ -87,6 +88,13 @@ func (l *LimitsMetricsGenerator) GetCollectionInterval() (time.Duration, bool) {
return 0, false
}

func (l *LimitsMetricsGenerator) GetTraceIDLabelName() (string, bool) {
if l != nil && l.TraceIDLabelName != nil {
return *l.TraceIDLabelName, true
}
return "", false
}

type LimitsMetricsGeneratorProcessor struct {
ServiceGraphs LimitsMetricsGeneratorProcessorServiceGraphs `yaml:"service_graphs,omitempty" json:"service_graphs,omitempty"`
SpanMetrics LimitsMetricsGeneratorProcessorSpanMetrics `yaml:"span_metrics,omitempty" json:"span_metrics,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions modules/overrides/userconfigurable/client/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestLimits_parseJson(t *testing.T) {
"metrics_generator": {
"processors": ["service-graphs"],
"collection_interval": "30s",
"trace_id_label_name": "my_trace_id",
"native_histogram_max_bucket_number": 101,
"generate_native_histograms": "native",
"processor": {
Expand All @@ -54,6 +55,7 @@ func TestLimits_parseJson(t *testing.T) {
MetricsGenerator: LimitsMetricsGenerator{
Processors: map[string]struct{}{"service-graphs": {}},
CollectionInterval: &Duration{Duration: 30 * time.Second},
TraceIDLabelName: strPtr("my_trace_id"),
GenerateNativeHistograms: (*histograms.HistogramMethod)(strPtr("native")),
NativeHistogramMaxBucketNumber: func(u uint32) *uint32 { return &u }(101),
Processor: LimitsMetricsGeneratorProcessor{
Expand Down
Loading