Skip to content

Commit

Permalink
Change label name for metrics generator instance (#1439)
Browse files Browse the repository at this point in the history
* Change label name for metrics generator instance

Signed-off-by: Joe Elliott <[email protected]>

* changelog

Signed-off-by: Joe Elliott <[email protected]>

* tests

Signed-off-by: Joe Elliott <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Koenraad Verheyden <[email protected]>

Co-authored-by: Koenraad Verheyden <[email protected]>
  • Loading branch information
joe-elliott and yvrhdn authored May 23, 2022
1 parent 5bfdb67 commit 8cd7dc7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
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] metrics-generator: Changed added metric label `instance` to `__metrics_gen_instance` to reduce collisions with custom dimensions. [#1439](https://github.com/grafana/tempo/pull/1439) (@joe-elliott)
* [FEATURE] metrics-generator: support per-tenant processor configuration [#1434](https://github.com/grafana/tempo/pull/1434) (@kvrhdn)
* [ENHANCEMENT] Added the ability to have a per tenant max search duration. [#1421](https://github.com/grafana/tempo/pull/1421) (@joe-elliott)

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 @@ -89,7 +89,7 @@ func New(cfg *Config, overrides Overrides, tenant string, appendable storage.App
externalLabels[k] = v
}
hostname, _ := os.Hostname()
externalLabels["instance"] = hostname
externalLabels["__metrics_gen_instance"] = hostname

r := &ManagedRegistry{
onShutdown: cancel,
Expand Down
22 changes: 11 additions & 11 deletions modules/generator/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestManagedRegistry_counter(t *testing.T) {
counter.Inc(NewLabelValues([]string{"value-1"}), 1.0)

expectedSamples := []sample{
newSample(map[string]string{"__name__": "my_counter", "label": "value-1", "instance": mustGetHostname()}, 0, 1.0),
newSample(map[string]string{"__name__": "my_counter", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 1.0),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}
Expand All @@ -80,11 +80,11 @@ func TestManagedRegistry_histogram(t *testing.T) {
histogram.ObserveWithExemplar(NewLabelValues([]string{"value-1"}), 1.0, "")

expectedSamples := []sample{
newSample(map[string]string{"__name__": "histogram_count", "label": "value-1", "instance": mustGetHostname()}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_sum", "label": "value-1", "instance": mustGetHostname()}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "instance": mustGetHostname(), "le": "1"}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "instance": mustGetHostname(), "le": "2"}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "instance": mustGetHostname(), "le": "+Inf"}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_count", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_sum", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "__metrics_gen_instance": mustGetHostname(), "le": "1"}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "__metrics_gen_instance": mustGetHostname(), "le": "2"}, 0, 1.0),
newSample(map[string]string{"__name__": "histogram_bucket", "label": "value-1", "__metrics_gen_instance": mustGetHostname(), "le": "+Inf"}, 0, 1.0),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}
Expand All @@ -107,8 +107,8 @@ func TestManagedRegistry_removeStaleSeries(t *testing.T) {
registry.removeStaleSeries(context.Background())

expectedSamples := []sample{
newSample(map[string]string{"__name__": "metric_1", "instance": mustGetHostname()}, 0, 1),
newSample(map[string]string{"__name__": "metric_2", "instance": mustGetHostname()}, 0, 2),
newSample(map[string]string{"__name__": "metric_1", "__metrics_gen_instance": mustGetHostname()}, 0, 1),
newSample(map[string]string{"__name__": "metric_2", "__metrics_gen_instance": mustGetHostname()}, 0, 2),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)

Expand All @@ -121,7 +121,7 @@ func TestManagedRegistry_removeStaleSeries(t *testing.T) {
registry.removeStaleSeries(context.Background())

expectedSamples = []sample{
newSample(map[string]string{"__name__": "metric_2", "instance": mustGetHostname()}, 0, 4),
newSample(map[string]string{"__name__": "metric_2", "__metrics_gen_instance": mustGetHostname()}, 0, 4),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}
Expand All @@ -141,7 +141,7 @@ func TestManagedRegistry_externalLabels(t *testing.T) {
counter.Inc(nil, 1.0)

expectedSamples := []sample{
newSample(map[string]string{"__name__": "my_counter", "instance": mustGetHostname(), "foo": "bar"}, 0, 1),
newSample(map[string]string{"__name__": "my_counter", "__metrics_gen_instance": mustGetHostname(), "foo": "bar"}, 0, 1),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}
Expand All @@ -165,7 +165,7 @@ func TestManagedRegistry_maxSeries(t *testing.T) {

assert.Equal(t, uint32(1), registry.activeSeries.Load())
expectedSamples := []sample{
newSample(map[string]string{"__name__": "metric_1", "label": "value-1", "instance": mustGetHostname()}, 0, 1),
newSample(map[string]string{"__name__": "metric_1", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 1),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}
Expand Down

0 comments on commit 8cd7dc7

Please sign in to comment.