Skip to content

Commit bcde0c1

Browse files
mdatagen Auto-enable v1 metrics when legacy is enabled
When the v1 feature gate is on and a legacy metric is enabled, programmatically enable the corresponding v1 metric so users don't need to update their config to get v1 metric emission.
1 parent ee490df commit bcde0c1

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
7+
component: cmd/mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Auto-enable v1 metrics when legacy metric is enabled and v1 feature gate is on
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [15650]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
When the v1 feature gate is enabled and a legacy metric is enabled, the corresponding
20+
v1 metric is now programmatically enabled so users don't need to add the v1 metric
21+
to their config.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: []

cmd/mdatagen/internal/samplemigrationscraper/internal/metadata/generated_metrics.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/templates/metrics.go.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings {{ .Status.Class }}.Se
408408
{{- range $name, $metric := .Metrics }}
409409
{{- if $metric.Migration }}
410410
if {{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar }}FeatureGate.IsEnabled() {
411+
{{- /* If a legacy metric is enabled, programmatically enable the v1 metric.
412+
The v1 metric may be disabled in metadata.yaml; when the v1 feature gate
413+
is on we need to enable it automatically so users don't have to update
414+
their config. */}}
415+
if mb.metric{{ $name.Render }}.config.Enabled && !mb.metric{{ $metric.Migration.To.Render }}.config.enabledSetByUser {
416+
mb.metric{{ $metric.Migration.To.Render }}.config.Enabled = true
417+
mb.metric{{ $metric.Migration.To.Render }}.data = pmetric.NewMetric()
418+
mb.metric{{ $metric.Migration.To.Render }}.init()
419+
}
411420
if mb.metric{{ $name.Render }}.config.Enabled && mb.metric{{ $metric.Migration.To.Render }}.config.Enabled {
412421
var disable bool
413422
if mb.metric{{ $name.Render }}.data.Type() != mb.metric{{ $metric.Migration.To.Render }}.data.Type() {

0 commit comments

Comments
 (0)