Skip to content

Commit

Permalink
[mdatagen] Rename include/exclude config options (#9960)
Browse files Browse the repository at this point in the history
The `include` and `exclude ` options in the resource attributes group
sound confusing. It's easy to assume that matching filters will include
or exclude resource attributes themselves while they control emitted
resource metrics.

The proposal is to change the include/exclude options to
`metrics_include`/`metrics_exclude` with detailed comments. These names
make it cleaner that matching rules limit the emitted metrics, not
resource attributes.

Updates
open-telemetry/opentelemetry-collector-contrib#25134
  • Loading branch information
dmitryax authored Apr 22, 2024
1 parent bb48107 commit cc9e3dd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 61 deletions.

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.

Original file line number Diff line number Diff line change
Expand Up @@ -61,67 +61,67 @@ filter_set_include:
resource_attributes:
map.resource.attr:
enabled: true
include:
metrics_include:
- regexp: ".*"
optional.resource.attr:
enabled: true
include:
metrics_include:
- regexp: ".*"
slice.resource.attr:
enabled: true
include:
metrics_include:
- regexp: ".*"
string.enum.resource.attr:
enabled: true
include:
metrics_include:
- regexp: ".*"
string.resource.attr:
enabled: true
include:
metrics_include:
- regexp: ".*"
string.resource.attr_disable_warning:
enabled: true
include:
metrics_include:
- regexp: ".*"
string.resource.attr_remove_warning:
enabled: true
include:
metrics_include:
- regexp: ".*"
string.resource.attr_to_be_removed:
enabled: true
include:
metrics_include:
- regexp: ".*"
filter_set_exclude:
resource_attributes:
map.resource.attr:
enabled: true
exclude:
metrics_exclude:
- regexp: ".*"
optional.resource.attr:
enabled: true
exclude:
metrics_exclude:
- strict: "optional.resource.attr-val"
slice.resource.attr:
enabled: true
exclude:
metrics_exclude:
- regexp: ".*"
string.enum.resource.attr:
enabled: true
exclude:
metrics_exclude:
- strict: "one"
string.resource.attr:
enabled: true
exclude:
metrics_exclude:
- strict: "string.resource.attr-val"
string.resource.attr_disable_warning:
enabled: true
exclude:
metrics_exclude:
- strict: "string.resource.attr_disable_warning-val"
string.resource.attr_remove_warning:
enabled: true
exclude:
metrics_exclude:
- strict: "string.resource.attr_remove_warning-val"
string.resource.attr_to_be_removed:
enabled: true
exclude:
metrics_exclude:
- strict: "string.resource.attr_to_be_removed-val"
9 changes: 7 additions & 2 deletions cmd/mdatagen/templates/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ func DefaultMetricsConfig() MetricsConfig {
type ResourceAttributeConfig struct {
Enabled bool `mapstructure:"enabled"`
{{- if .Metrics }}
Include []filter.Config `mapstructure:"include"`
Exclude []filter.Config `mapstructure:"exclude"`
// Experimental: MetricsInclude defines a list of filters for attribute values.
// If the list is not empty, only metrics with matching resource attribute values will be emitted.
MetricsInclude []filter.Config `mapstructure:"metrics_include"`
// Experimental: MetricsExclude defines a list of filters for attribute values.
// If the list is not empty, metrics with matching resource attribute values will not be emitted.
// MetricsInclude has higher priority than MetricsExclude.
MetricsExclude []filter.Config `mapstructure:"metrics_exclude"`
{{- end }}

enabledSetByUser bool
Expand Down
10 changes: 5 additions & 5 deletions cmd/mdatagen/templates/metrics.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting
}
{{- end }}
{{- if $attr.Warnings.IfConfigured }}
if mbc.ResourceAttributes.{{ $name.Render }}.enabledSetByUser || mbc.ResourceAttributes.{{ $name.Render }}.Include != nil || mbc.ResourceAttributes.{{ $name.Render }}.Exclude != nil {
if mbc.ResourceAttributes.{{ $name.Render }}.enabledSetByUser || mbc.ResourceAttributes.{{ $name.Render }}.MetricsInclude != nil || mbc.ResourceAttributes.{{ $name.Render }}.MetricsExclude != nil {
settings.Logger.Warn("[WARNING] `{{ $name }}` should not be configured: {{ $attr.Warnings.IfConfigured }}")
}
{{- end }}
Expand All @@ -203,11 +203,11 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSetting
{{- end }}
}
{{- range $name, $attr := .ResourceAttributes }}
if mbc.ResourceAttributes.{{ $name.Render }}.Include != nil {
mb.resourceAttributeIncludeFilter["{{ $name }}"] = filter.CreateFilter(mbc.ResourceAttributes.{{ $name.Render }}.Include)
if mbc.ResourceAttributes.{{ $name.Render }}.MetricsInclude != nil {
mb.resourceAttributeIncludeFilter["{{ $name }}"] = filter.CreateFilter(mbc.ResourceAttributes.{{ $name.Render }}.MetricsInclude)
}
if mbc.ResourceAttributes.{{ $name.Render }}.Exclude != nil {
mb.resourceAttributeExcludeFilter["{{ $name }}"] = filter.CreateFilter(mbc.ResourceAttributes.{{ $name.Render }}.Exclude)
if mbc.ResourceAttributes.{{ $name.Render }}.MetricsExclude != nil {
mb.resourceAttributeExcludeFilter["{{ $name }}"] = filter.CreateFilter(mbc.ResourceAttributes.{{ $name.Render }}.MetricsExclude)
}
{{- end }}

Expand Down
4 changes: 2 additions & 2 deletions cmd/mdatagen/templates/testdata/config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ filter_set_include:
{{- range $name, $attr := .ResourceAttributes }}
{{ $name }}:
enabled: true
include:
metrics_include:
- regexp: ".*"
{{- end }}
filter_set_exclude:
resource_attributes:
{{- range $name, $attr := .ResourceAttributes }}
{{ $name }}:
enabled: true
exclude:
metrics_exclude:
{{- if eq $attr.Type.String "Str" }}
- strict: {{ $attr.TestValue }}
{{- else }}
Expand Down

0 comments on commit cc9e3dd

Please sign in to comment.