Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle to inject the tenant ID to generated metrics #3638

Merged
merged 1 commit into from
May 28, 2024
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
Expand Up @@ -7,6 +7,7 @@

* [CHANGE] Update Alpine image version to 3.20 [#3710](https://github.com/grafana/tempo/pull/3710) (@joe-elliott)
* [ENHANCEMENT] TraceQL - Add support for trace:id and span:id [#3670](https://github.com/grafana/tempo/pull/3670) (@ie-pham)
* [ENHANCEMENT] Add toggle to inject the tenant ID to generated metrics [#3638](https://github.com/grafana/tempo/pull/3638) (@kvrhdn)
* [BUGFIX] Fix TraceQL queries involving non boolean operations between statics and attributes. [#3698](https://github.com/grafana/tempo/pull/3698) (@joe-elliott)

## v2.5.0-rc.0
Expand Down
3 changes: 3 additions & 0 deletions docs/sources/tempo/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ metrics_generator:
# A list of labels that will be added to all generated metrics.
[external_labels: <map>]

# If set, the tenant ID will added as label with the given label name to all generated metrics.
[inject_tenant_id_as: <string>]
Comment on lines +387 to +388
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I didn't really find a nice and concise way to describe this setting. Suggestion are welcome 😅

Also feedback about the name of the setting itself is welcome. It's a bit verbose now imo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's long, it's clear what it does.


# The maximum length of label names. Label names exceeding this limit will be truncated.
[max_label_name_length: <int> | default = 1024]

Expand Down
2 changes: 2 additions & 0 deletions modules/generator/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Config struct {
// ExternalLabels are added to any time series generated by this instance.
ExternalLabels map[string]string `yaml:"external_labels,omitempty"`

InjectTenantIDAs string `yaml:"inject_tenant_id_as,omitempty"`

// MaxLabelNameLength configures the maximum length of label names. Label names exceeding
// this limit will be truncated.
MaxLabelNameLength int `yaml:"max_label_name_length"`
Expand Down
4 changes: 4 additions & 0 deletions modules/generator/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func New(cfg *Config, overrides Overrides, tenant string, appendable storage.App
hostname, _ := os.Hostname()
externalLabels["__metrics_gen_instance"] = hostname

if cfg.InjectTenantIDAs != "" {
externalLabels[cfg.InjectTenantIDAs] = tenant
}

r := &ManagedRegistry{
onShutdown: cancel,

Expand Down
19 changes: 19 additions & 0 deletions modules/generator/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ func TestManagedRegistry_externalLabels(t *testing.T) {
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}

func TestManagedRegistry_injectTenantIDAs(t *testing.T) {
appender := &capturingAppender{}

cfg := &Config{
InjectTenantIDAs: "__tempo_tenant",
}
registry := New(cfg, &mockOverrides{}, "test", appender, log.NewNopLogger())
defer registry.Close()

counter := registry.NewCounter("my_counter")
counter.Inc(nil, 1.0)

expectedSamples := []sample{
newSample(map[string]string{"__name__": "my_counter", "__metrics_gen_instance": mustGetHostname(), "__tempo_tenant": "test"}, 0, 0),
newSample(map[string]string{"__name__": "my_counter", "__metrics_gen_instance": mustGetHostname(), "__tempo_tenant": "test"}, 0, 1),
}
collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
}

func TestManagedRegistry_maxSeries(t *testing.T) {
appender := &capturingAppender{}

Expand Down
Loading