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

[cmd/mdatagen] Don't expose empty resource_attributes config section #21519

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
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]
2 changes: 1 addition & 1 deletion cmd/mdatagen/internal/metadata/generated_metrics.go

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

17 changes: 13 additions & 4 deletions cmd/mdatagen/templates/metrics.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func DefaultMetricsSettings() MetricsSettings {
}
}

{{ if .ResourceAttributes -}}
// ResourceAttributeSettings provides common settings for a particular resource attribute.
type ResourceAttributeSettings struct {
Enabled bool `mapstructure:"enabled"`
}


// ResourceAttributesSettings provides settings for {{ .Type }} resource attributes.
type ResourceAttributesSettings struct {
{{- range $name, $attr := .ResourceAttributes }}
Expand All @@ -77,6 +77,7 @@ func DefaultResourceAttributesSettings() ResourceAttributesSettings {
{{- end }}
}
}
{{- end }}

{{ range $name, $info := .Attributes }}
{{- if $info.Enum -}}
Expand Down Expand Up @@ -187,7 +188,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 All @@ -198,7 +201,9 @@ type MetricsBuilder struct {
resourceCapacity int // maximum observed number of resource attributes.
metricsBuffer pmetric.Metrics // accumulates metrics data before emitting.
buildInfo component.BuildInfo // contains version information
{{- if .ResourceAttributes }}
resourceAttributesSettings ResourceAttributesSettings
{{- end }}
{{- range $name, $metric := .Metrics }}
metric{{ $name.Render }} metric{{ $name.Render }}
{{- end }}
Expand All @@ -217,7 +222,9 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption {
func DefaultMetricsBuilderConfig() MetricsBuilderConfig {
return MetricsBuilderConfig {
Metrics: DefaultMetricsSettings(),
{{- if .ResourceAttributes }}
ResourceAttributes: DefaultResourceAttributesSettings(),
{{- end }}
}
}

Expand All @@ -243,7 +250,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 All @@ -265,7 +274,7 @@ func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) {
}

// ResourceMetricsOption applies changes to provided resource metrics.
type ResourceMetricsOption func(ResourceAttributesSettings, pmetric.ResourceMetrics)
type ResourceMetricsOption func({{ if .ResourceAttributes }}ResourceAttributesSettings, {{ end }}pmetric.ResourceMetrics)

{{- range $name, $attr := .ResourceAttributes }}
{{- range $attr.Enum }}
Expand Down Expand Up @@ -298,7 +307,7 @@ func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceMetricsOptio
// WithStartTimeOverride overrides start time for all the resource metrics data points.
// This option should be only used if different start time has to be set on metrics coming from different resources.
func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption {
return func(ras ResourceAttributesSettings, rm pmetric.ResourceMetrics) {
return func({{ if .ResourceAttributes }}_ ResourceAttributesSettings, {{ end }}rm pmetric.ResourceMetrics) {
var dps pmetric.NumberDataPointSlice
metrics := rm.ScopeMetrics().At(0).Metrics()
for i := 0; i < metrics.Len(); i++ {
Expand Down Expand Up @@ -335,7 +344,7 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) {
{{- end }}

for _, op := range rmo {
op(mb.resourceAttributesSettings, rm)
op({{ if .ResourceAttributes }}mb.resourceAttributesSettings, {{ end }}rm)
}
if ils.Metrics().Len() > 0 {
mb.updateCapacity(rm)
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:

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

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

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

71 changes: 27 additions & 44 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.

Loading
Loading