Skip to content

Commit a167a91

Browse files
committed
fix: convert space indentation to tabs in upstream-added template files
Commits ccee642 and e4e58cd added versioned-metrics support with 2-space indentation in metrics.go.tmpl, metrics_test.go.tmpl, and config_test.go.tmpl. The check-template-tabs check added in this PR now catches these. Convert all leading spaces to tabs (2 spaces per tab) to pass the check. The generated code is unaffected because mdatagen runs go/format (gofmt) over all generated files. Assisted-by: Claude Sonnet 4.6
1 parent 1f03ae5 commit a167a91

4 files changed

Lines changed: 237 additions & 237 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ import (
191191
{{- end }}
192192

193193
{{ define "enumValidator" -}}
194-
if !slices.Contains({{ formatEnumSlice .Rules.Enum .FieldType }}, {{ template "fieldValue" . }}) {
195-
err = errors.Join(err, errors.New("{{ .FieldName }} must be one of {{ formatEnumValues .Rules.Enum }}"))
196-
}
194+
if !slices.Contains({{ formatEnumSlice .Rules.Enum .FieldType }}, {{ template "fieldValue" . }}) {
195+
err = errors.Join(err, errors.New("{{ .FieldName }} must be one of {{ formatEnumValues .Rules.Enum }}"))
196+
}
197197
{{- end }}
198198

199199
{{ define "valueValidators" }}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ func TestMetricsBuilderConfig(t *testing.T) {
9797
{{- range $name, $metric := .Metrics }}
9898
{{ if hasAggregatableAttributes $metric.Attributes -}}
9999
func Test{{ $name.Render }}MetricsConfig_Validate(t *testing.T) {
100-
cfg := DefaultMetricsConfig().{{ $name.Render }}
101-
require.NoError(t, cfg.Validate())
100+
cfg := DefaultMetricsConfig().{{ $name.Render }}
101+
require.NoError(t, cfg.Validate())
102102

103-
cfg.EnabledAttributes = []{{ $name.Render }}MetricAttributeKey{"invalid"}
104-
require.ErrorContains(t, cfg.Validate(), "metric {{ $name }} doesn't have an attribute invalid, valid attributes: [{{ range $index, $element := $metric.Attributes -}}{{ if $index }}, {{ end }}{{ (attributeInfo $element).Name }}{{ end }}]")
103+
cfg.EnabledAttributes = []{{ $name.Render }}MetricAttributeKey{"invalid"}
104+
require.ErrorContains(t, cfg.Validate(), "metric {{ $name }} doesn't have an attribute invalid, valid attributes: [{{ range $index, $element := $metric.Attributes -}}{{ if $index }}, {{ end }}{{ (attributeInfo $element).Name }}{{ end }}]")
105105

106-
cfg = DefaultMetricsConfig().{{ $name.Render }}
107-
cfg.AggregationStrategy = "invalid"
108-
require.ErrorContains(t, cfg.Validate(), "invalid aggregation strategy")
106+
cfg = DefaultMetricsConfig().{{ $name.Render }}
107+
cfg.AggregationStrategy = "invalid"
108+
require.ErrorContains(t, cfg.Validate(), "invalid aggregation strategy")
109109
}
110110
{{ end }}
111111
{{ end }}

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ const (
4343

4444
{{- if needsStrToIntConversion }}
4545
func mustParseInt64(s string) int64 {
46-
re := regexp.MustCompile(`-?\d+`)
47-
match := re.FindString(s)
48-
if match == "" {
49-
return 0
50-
}
46+
re := regexp.MustCompile(`-?\d+`)
47+
match := re.FindString(s)
48+
if match == "" {
49+
return 0
50+
}
5151
v, _ := strconv.ParseInt(match, 10, 64)
5252
return v
5353
}
@@ -405,36 +405,36 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings {{ .Status.Class }}.Se
405405
}
406406
{{- end }}
407407

408-
{{- range $name, $metric := .Metrics }}
409-
{{- if $metric.Migration }}
410-
if {{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar }}FeatureGate.IsEnabled() {
411-
if mb.metric{{ $name.Render }}.config.Enabled && mb.metric{{ $metric.Migration.To.Render }}.config.Enabled {
412-
var disable bool
413-
if mb.metric{{ $name.Render }}.data.Type() != mb.metric{{ $metric.Migration.To.Render }}.data.Type() {
414-
// Disable legacy metric if legacy and latest have same name but different types
415-
disable = true
416-
settings.Logger.Warn("[WARNING] Legacy metric `{{ $name }}` disabled: same emitted name as `{{ $metric.Migration.To }}` with different type; only latest will be emitted")
417-
}
418-
if !slices.Equal(MetricsInfo.{{ $name.Render }}.Attributes, MetricsInfo.{{ $metric.Migration.To.Render }}.Attributes) {
419-
// Disable legacy metric if legacy and latest have same name but different attributes
420-
// The latest metric will emit both attribute sets during migration
421-
disable = true
422-
settings.Logger.Warn("[WARNING] Legacy metric `{{ $name }}` disabled: same emitted name as `{{ $metric.Migration.To }}` with different attributes; only latest will be emitted with combined attributes",
423-
zap.Strings("legacy_attributes", MetricsInfo.{{ $name.Render }}.Attributes),
424-
zap.Strings("latest_attributes", MetricsInfo.{{ $metric.Migration.To.Render }}.Attributes))
425-
}
426-
if disable {
427-
mb.metric{{ $name.Render }}.config.Enabled = false
428-
}
429-
}
430-
} else {
431-
if !{{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar}}FeatureGate.IsEnabled() && mb.metric{{ $metric.Migration.To.Render }}.config.Enabled {
432-
mb.metric{{ $metric.Migration.To.Render }}.config.Enabled = false
433-
settings.Logger.Warn("[WARNING] metric `{{ $metric.Migration.To }}` requires feature gate `{{ $metric.Migration.ThroughGates.EnableNew }}` to be enabled, metric has been disabled")
434-
}
435-
}
436-
{{- end }}
437-
{{- end }}
408+
{{- range $name, $metric := .Metrics }}
409+
{{- if $metric.Migration }}
410+
if {{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar }}FeatureGate.IsEnabled() {
411+
if mb.metric{{ $name.Render }}.config.Enabled && mb.metric{{ $metric.Migration.To.Render }}.config.Enabled {
412+
var disable bool
413+
if mb.metric{{ $name.Render }}.data.Type() != mb.metric{{ $metric.Migration.To.Render }}.data.Type() {
414+
// Disable legacy metric if legacy and latest have same name but different types
415+
disable = true
416+
settings.Logger.Warn("[WARNING] Legacy metric `{{ $name }}` disabled: same emitted name as `{{ $metric.Migration.To }}` with different type; only latest will be emitted")
417+
}
418+
if !slices.Equal(MetricsInfo.{{ $name.Render }}.Attributes, MetricsInfo.{{ $metric.Migration.To.Render }}.Attributes) {
419+
// Disable legacy metric if legacy and latest have same name but different attributes
420+
// The latest metric will emit both attribute sets during migration
421+
disable = true
422+
settings.Logger.Warn("[WARNING] Legacy metric `{{ $name }}` disabled: same emitted name as `{{ $metric.Migration.To }}` with different attributes; only latest will be emitted with combined attributes",
423+
zap.Strings("legacy_attributes", MetricsInfo.{{ $name.Render }}.Attributes),
424+
zap.Strings("latest_attributes", MetricsInfo.{{ $metric.Migration.To.Render }}.Attributes))
425+
}
426+
if disable {
427+
mb.metric{{ $name.Render }}.config.Enabled = false
428+
}
429+
}
430+
} else {
431+
if !{{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar}}FeatureGate.IsEnabled() && mb.metric{{ $metric.Migration.To.Render }}.config.Enabled {
432+
mb.metric{{ $metric.Migration.To.Render }}.config.Enabled = false
433+
settings.Logger.Warn("[WARNING] metric `{{ $metric.Migration.To }}` requires feature gate `{{ $metric.Migration.ThroughGates.EnableNew }}` to be enabled, metric has been disabled")
434+
}
435+
}
436+
{{- end }}
437+
{{- end }}
438438

439439
for _, op := range options {
440440
op.apply(mb)
@@ -601,7 +601,7 @@ func (mb *MetricsBuilder) Record{{ $name.Render }}DataPoint(ts pcommon.Timestamp
601601
return fmt.Errorf("failed to parse {{ $metric.Data.MetricValueType.BasicType }} for {{ $name.Render }}, value was %s: %w", inputVal, err)
602602
}
603603
{{- end }}
604-
{{- if $metric.Migration }}
604+
{{- if $metric.Migration }}
605605
// Dual-schema emission controlled by feature gates
606606
{{- $targetLegacyAttrs := getLegacyAttributes $metric.Migration.To }}
607607
if !{{ printf "%s" $metric.Migration.ThroughGates.DisableOld | publicVar }}FeatureGate.IsEnabled() {
@@ -612,9 +612,9 @@ func (mb *MetricsBuilder) Record{{ $name.Render }}DataPoint(ts pcommon.Timestamp
612612
{{- end -}}
613613
{{- end -}}
614614
{{- if $metric.HasConditionalAttributes $.Attributes -}}
615-
, options...
616-
{{- end -}}
617-
)
615+
, options...
616+
{{- end -}}
617+
)
618618
}
619619
{{- $targetMetric := index $.Metrics $metric.Migration.To }}
620620
if {{ printf "%s" $metric.Migration.ThroughGates.EnableNew | publicVar }}FeatureGate.IsEnabled() {
@@ -659,11 +659,11 @@ func (mb *MetricsBuilder) Record{{ $name.Render }}DataPoint(ts pcommon.Timestamp
659659
{{- if $metric.HasConditionalAttributes $.Attributes -}}
660660
, options...
661661
{{- end -}}
662-
{{- if $selfLegacyAttrs -}}
662+
{{- if $selfLegacyAttrs -}}
663663
, false
664664
{{- end -}}
665665
)
666-
{{- end }}
666+
{{- end }}
667667
{{- if $metric.Data.HasMetricInputType }}
668668
return nil
669669
{{- end }}

0 commit comments

Comments
 (0)