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

[mdatagen] allow filtering out metrics based on resource attributes #9660

Merged
merged 3 commits into from
Apr 12, 2024
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
25 changes: 25 additions & 0 deletions .chloggen/mdatagen-filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "support excluding some metrics based on string and regexes in resource_attributes"

# One or more tracking issues or pull requests related to the change
issues: [9661]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
3 changes: 3 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
go.opentelemetry.io/collector/confmap v0.98.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.98.0
go.opentelemetry.io/collector/consumer v0.98.0
go.opentelemetry.io/collector/filter v0.0.0-00010101000000-000000000000
go.opentelemetry.io/collector/pdata v1.5.0
go.opentelemetry.io/collector/receiver v0.98.0
go.opentelemetry.io/collector/semconv v0.98.0
Expand Down Expand Up @@ -62,6 +63,8 @@ replace go.opentelemetry.io/collector/confmap => ../../confmap

replace go.opentelemetry.io/collector/confmap/provider/fileprovider => ../../confmap/provider/fileprovider

replace go.opentelemetry.io/collector/filter => ../../filter

replace go.opentelemetry.io/collector/pdata => ../../pdata

replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata
Expand Down

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.

Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,85 @@ none_set:
enabled: false
string.resource.attr_to_be_removed:
enabled: false
filter_set_include:
metrics:
default.metric:
enabled: true
default.metric.to_be_removed:
enabled: true
metric.input_type:
enabled: true
optional.metric:
enabled: true
optional.metric.empty_unit:
enabled: true
resource_attributes:
map.resource.attr:
enabled: true
optional.resource.attr:
enabled: true
include:
- regexp: ".*"
slice.resource.attr:
enabled: true
string.enum.resource.attr:
enabled: true
include:
- regexp: ".*"
string.resource.attr:
enabled: true
include:
- regexp: ".*"
string.resource.attr_disable_warning:
enabled: true
include:
- regexp: ".*"
string.resource.attr_remove_warning:
enabled: true
include:
- regexp: ".*"
string.resource.attr_to_be_removed:
enabled: true
include:
- regexp: ".*"
filter_set_exclude:
metrics:
default.metric:
enabled: true
default.metric.to_be_removed:
enabled: true
metric.input_type:
enabled: true
optional.metric:
enabled: true
optional.metric.empty_unit:
enabled: true
resource_attributes:
map.resource.attr:
enabled: true
optional.resource.attr:
enabled: true
exclude:
- strict: "optional.resource.attr-val"
slice.resource.attr:
enabled: true
string.enum.resource.attr:
enabled: true
exclude:
- strict: "one"
string.resource.attr:
enabled: true
exclude:
- strict: "string.resource.attr-val"
string.resource.attr_disable_warning:
enabled: true
exclude:
- strict: "string.resource.attr_disable_warning-val"
string.resource.attr_remove_warning:
enabled: true
exclude:
- strict: "string.resource.attr_remove_warning-val"
string.resource.attr_to_be_removed:
enabled: true
exclude:
- strict: "string.resource.attr_to_be_removed-val"
5 changes: 5 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.opentelemetry.io/collector/filter"
"go.opentelemetry.io/collector/pdata/pcommon"
)

Expand Down Expand Up @@ -153,6 +154,10 @@ type attribute struct {
NameOverride string `mapstructure:"name_override"`
// Enabled defines whether the attribute is enabled by default.
Enabled bool `mapstructure:"enabled"`
// Include can be used to filter attributes.
Include []filter.Config `mapstructure:"include"`
// Include can be used to filter attributes.
Exclude []filter.Config `mapstructure:"exclude"`
// Enum can optionally describe the set of values to which the attribute can belong.
Enum []string `mapstructure:"enum"`
// Type is an attribute type.
Expand Down
6 changes: 5 additions & 1 deletion cmd/mdatagen/templates/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package {{ .Package }}
{{ if or .Metrics .ResourceAttributes -}}
import "go.opentelemetry.io/collector/confmap"
{{- end }}

{{ if .ResourceAttributes -}}
import "go.opentelemetry.io/collector/filter"
dmitryax marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
{{ if .Metrics -}}

// MetricConfig provides common config for a particular metric.
Expand Down Expand Up @@ -49,6 +51,8 @@ func DefaultMetricsConfig() MetricsConfig {
// ResourceAttributeConfig provides common config for a particular resource attribute.
type ResourceAttributeConfig struct {
Enabled bool `mapstructure:"enabled"`
Include []filter.Config `mapstructure:"include"`
Exclude []filter.Config `mapstructure:"exclude"`

enabledSetByUser bool
}
Expand Down
Loading
Loading