Skip to content

Commit

Permalink
[cmd/mdatagen] Don't expose empty resource_attributes config section
Browse files Browse the repository at this point in the history
If no resource_attributes defined in the metadata.yaml file, don't expose the corresponding empty config section
  • Loading branch information
dmitryax committed May 6, 2023
1 parent 6672679 commit d58a457
Show file tree
Hide file tree
Showing 33 changed files with 67 additions and 121 deletions.
11 changes: 11 additions & 0 deletions .chloggen/mdatagen-dont-expose-empty-resource-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Don't expose `resource_attributes` user config section if it's empty.

# One or more tracking issues related to the change
issues: [21519]
6 changes: 6 additions & 0 deletions cmd/mdatagen/templates/metrics.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func newMetric{{ $name.Render }}(settings MetricSettings) metric{{ $name.Render
// MetricsBuilderConfig is a structural subset of an otherwise 1-1 copy of metadata.yaml
type MetricsBuilderConfig struct {
Metrics MetricsSettings `mapstructure:"metrics"`
{{- if .ResourceAttributes }}
ResourceAttributes ResourceAttributesSettings `mapstructure:"resource_attributes"`
{{- end }}
}

// MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations
Expand Down Expand Up @@ -217,7 +219,9 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption {
func DefaultMetricsBuilderConfig() MetricsBuilderConfig {
return MetricsBuilderConfig {
Metrics: DefaultMetricsSettings(),
{{- if .ResourceAttributes }}
ResourceAttributes: DefaultResourceAttributesSettings(),
{{- end }}
}
}

Expand All @@ -243,7 +247,9 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting
startTime: pcommon.NewTimestampFromTime(time.Now()),
metricsBuffer: pmetric.NewMetrics(),
buildInfo: settings.BuildInfo,
{{- if .ResourceAttributes }}
resourceAttributesSettings: mbc.ResourceAttributes,
{{- end }}
{{- range $name, $metric := .Metrics }}
metric{{ $name.Render }}: newMetric{{ $name.Render }}(mbc.Metrics.{{ $name.Render }}),
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions cmd/mdatagen/templates/testdata/config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ all_set:
{{ $name }}:
enabled: true
{{- end }}
{{- if .ResourceAttributes }}
resource_attributes:
{{- range $name, $_ := .ResourceAttributes }}
{{ $name }}:
enabled: true
{{- end }}
{{- end }}
none_set:
metrics:
{{- range $name, $_ := .Metrics }}
{{ $name }}:
enabled: false
{{- end }}
{{- if .ResourceAttributes }}
resource_attributes:
{{- range $name, $_ := .ResourceAttributes }}
{{ $name }}:
enabled: false
{{- end }}
{{- end }}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ all_set:
enabled: true
active_directory.ds.thread.count:
enabled: true
resource_attributes:
none_set:
metrics:
active_directory.ds.bind.rate:
Expand Down Expand Up @@ -76,4 +75,3 @@ none_set:
enabled: false
active_directory.ds.thread.count:
enabled: false
resource_attributes:
27 changes: 12 additions & 15 deletions receiver/chronyreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ all_set:
enabled: true
ntp.time.root_delay:
enabled: true
resource_attributes:
none_set:
metrics:
ntp.frequency.offset:
Expand All @@ -32,4 +31,3 @@ none_set:
enabled: false
ntp.time.root_delay:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ all_set:
enabled: true
process.runtime.memstats.total_alloc:
enabled: true
resource_attributes:
none_set:
metrics:
process.runtime.memstats.buck_hash_sys:
Expand Down Expand Up @@ -108,4 +107,3 @@ none_set:
enabled: false
process.runtime.memstats.total_alloc:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ all_set:
enabled: true
system.cpu.utilization:
enabled: true
resource_attributes:
none_set:
metrics:
system.cpu.time:
enabled: false
system.cpu.utilization:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ all_set:
enabled: true
system.disk.weighted_io_time:
enabled: true
resource_attributes:
none_set:
metrics:
system.disk.io:
Expand All @@ -32,4 +31,3 @@ none_set:
enabled: false
system.disk.weighted_io_time:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ all_set:
enabled: true
system.filesystem.utilization:
enabled: true
resource_attributes:
none_set:
metrics:
system.filesystem.inodes.usage:
Expand All @@ -16,4 +15,3 @@ none_set:
enabled: false
system.filesystem.utilization:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ all_set:
enabled: true
system.cpu.load_average.5m:
enabled: true
resource_attributes:
none_set:
metrics:
system.cpu.load_average.15m:
Expand All @@ -16,4 +15,3 @@ none_set:
enabled: false
system.cpu.load_average.5m:
enabled: false
resource_attributes:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d58a457

Please sign in to comment.