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

[processor/cumulativetodelta] Add include/exclude configuration #8952

Merged
merged 34 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cf06c08
Added include/exclude config options
TylerHelmuth Mar 28, 2022
488ee76
Fixed linting issues
TylerHelmuth Mar 29, 2022
12a9e6b
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Mar 29, 2022
5a11b93
run go mod tidy
TylerHelmuth Mar 29, 2022
a5b59c2
Updated changelog
TylerHelmuth Mar 29, 2022
e8793b2
Update processor/cumulativetodeltaprocessor/processor.go
TylerHelmuth Mar 29, 2022
19cd02c
Added back Developement status
TylerHelmuth Mar 29, 2022
a7b6fd0
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Mar 29, 2022
3dd3cc1
Noop change to trigger pipeline
TylerHelmuth Mar 30, 2022
1240aef
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Mar 30, 2022
0bd12a8
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Mar 30, 2022
e610755
Added include/exclude config options
TylerHelmuth Mar 28, 2022
1c8f4dd
Fixed linting issues
TylerHelmuth Mar 29, 2022
84c9595
Updated changelog
TylerHelmuth Mar 29, 2022
b904638
Update processor/cumulativetodeltaprocessor/processor.go
TylerHelmuth Mar 29, 2022
fdafe5a
Added back Developement status
TylerHelmuth Mar 29, 2022
753b4bc
Noop change to trigger pipeline
TylerHelmuth Mar 30, 2022
38af8b4
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Apr 1, 2022
e7ded00
Merge branch 'issue-5877' of https://github.com/TylerHelmuth/opentele…
TylerHelmuth Apr 1, 2022
2b96ccb
fix changelog
TylerHelmuth Apr 1, 2022
3470a14
Merge branch 'main' into issue-5877
TylerHelmuth Apr 4, 2022
b4230c3
Merge branch 'main' into issue-5877
TylerHelmuth Apr 6, 2022
860f3f7
Merge branch 'main' into issue-5877
TylerHelmuth Apr 7, 2022
3c523c2
Merge branch 'main' into issue-5877
TylerHelmuth Apr 11, 2022
47062bd
Merge remote-tracking branch 'upstream/main' into issue-5877
TylerHelmuth Apr 12, 2022
a53f1df
Update CHANGELOG.md
TylerHelmuth Apr 13, 2022
9434162
Update processor/cumulativetodeltaprocessor/config.go
TylerHelmuth Apr 13, 2022
e10d7bc
added deprecation entry
TylerHelmuth Apr 13, 2022
0ef0357
Added config test for regexp
TylerHelmuth Apr 13, 2022
656ab92
Merge branch 'main' into issue-5877
TylerHelmuth Apr 13, 2022
540f7cc
Merge remote-tracking branch 'origin/main' into issue-5877
TylerHelmuth Apr 13, 2022
0ab487b
Merge remote-tracking branch 'upstream/main' into issue-5877
TylerHelmuth Apr 19, 2022
fac388d
updated changelog
TylerHelmuth Apr 19, 2022
ff3bc73
Merge branch 'main' into issue-5877
TylerHelmuth Apr 19, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@

### 🚩 Deprecations 🚩

- `cumulativetodeltaprocessor`: Deprecated `metrics` configuration option in favor of `include` and `exclude` (#8952)

### 🚀 New components 🚀

- `iisreceiver`: Add implementation of IIS Metric Receiver (#8832)
- `sqlserverreceiver`: Add implementation of SQL Server Metric Receiver (#8398)

### 💡 Enhancements 💡

- `pkg/translator/prometheusremotewrite`: Allow to disable sanitize metric labels (#8270)
- `basicauthextension`: Implement `configauth.ClientAuthenticator` so that the extension can also be used as HTTP client basic authenticator.(#8847)
- `cumulativetodeltaprocessor`: add new include/exclude configuration options with regex support (#8952)
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved

### 🧰 Bug fixes 🧰

- `fluentforwardreceiver`: Release port on shutdown (#9111)


## v0.49.0

### 🛑 Breaking changes 🛑
Expand Down
61 changes: 51 additions & 10 deletions processor/cumulativetodeltaprocessor/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,74 @@
# Cumulative to Delta Processor

**Status: under development; Not recommended for production usage.**
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved

Supported pipeline types: metrics

## Description

The cumulative to delta processor (`cumulativetodeltaprocessor`) converts cumulative sum metrics to cumulative delta.
The cumulative to delta processor (`cumulativetodeltaprocessor`) converts cumulative sum metrics to cumulative delta. Non-monotonic sums are excluded.

## Configuration

Configuration is specified through a list of metrics. The processor uses metric names to identify a set of cumulative metrics and converts them from cumulative to delta.

The following settings can be optionally configured:

- `metrics`: The processor uses metric names to identify a set of cumulative metrics and converts them to delta.
- `include`: List of metrics names or patterns to convert to delta.
- `exclude`: List of metrics names or patterns to not convert to delta. **If a metric name matches both include and exclude, exclude takes precedence.**
- `max_stale`: The total time a state entry will live past the time it was last seen. Set to 0 to retain state indefinitely. Default: 0
- `metrics`: Deprecated. The processor uses metric names to identify a set of cumulative metrics and converts them to delta.

If neither include nor exclude are supplied, no filtering is applied.

#### Examples

```yaml
processors:
# processor name: cumulativetodelta
cumulativetodelta:

# list the exact cumulative sum metrics to convert to delta
include:
metrics:
- <metric_1_name>
- <metric_2_name>
.
.
- <metric_n_name>
match_type: strict
```

```yaml
processors:
# processor name: cumulativetodelta
cumulativetodelta:

#### Example
# Convert cumulative sum metrics to delta
# if and only if 'metric' is in the name
include:
metrics:
- "*metric*"
match_type: regexp
```

```yaml
processors:
# processor name: cumulativetodelta
cumulativetodelta:

# list the cumulative sum metrics to convert to delta
metrics:
- <metric_1_name>
- <metric_2_name>
.
.
- <metric_n_name>
# Convert cumulative sum metrics to delta
# if and only if 'metric' is not in the name
exclude:
metrics:
- "*metric*"
match_type: regexp
```

```yaml
processors:
# processor name: cumulativetodelta
cumulativetodelta:
# If include/exclude are not specified
# convert all cumulative sum metrics to delta
```
34 changes: 29 additions & 5 deletions processor/cumulativetodeltaprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,50 @@ import (
"time"

"go.opentelemetry.io/collector/config"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset"
)

// Config defines the configuration for the processor.
type Config struct {
config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

// List of cumulative metrics to convert to delta.
Metrics []string `mapstructure:"metrics"`

// MaxStaleness is the total time a state entry will live past the time it was last seen. Set to 0 to retain state indefinitely.
MaxStaleness time.Duration `mapstructure:"max_staleness"`

// Deprecated: List of cumulative metrics to convert to delta.
// Cannot be used with Include/Exclude.
Metrics []string `mapstructure:"metrics"`

// Include specifies a filter on the metrics that should be converted.
// Exclude specifies a filter on the metrics that should not be converted.
// If neither `include` nor `exclude` are set, all metrics will be converted.
// Cannot be used with deprecated Metrics config option.
Include MatchMetrics `mapstructure:"include"`
Exclude MatchMetrics `mapstructure:"exclude"`
}

type MatchMetrics struct {
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
filterset.Config `mapstructure:",squash"`

Metrics []string `mapstructure:"metrics"`
}

var _ config.Processor = (*Config)(nil)

// Validate checks whether the input configuration has all of the required fields for the processor.
// An error is returned if there are any invalid inputs.
func (config *Config) Validate() error {
if len(config.Metrics) == 0 {
return fmt.Errorf("metric names are missing")
if len(config.Metrics) > 0 && (len(config.Include.Metrics) > 0 || len(config.Exclude.Metrics) > 0) {
return fmt.Errorf("metrics and include/exclude cannot be used at the same time")
}
if (len(config.Include.Metrics) > 0 && len(config.Include.MatchType) == 0) ||
(len(config.Exclude.Metrics) > 0 && len(config.Exclude.MatchType) == 0) {
return fmt.Errorf("match_type must be set if metrics are supplied")
}
if (len(config.Include.MatchType) > 0 && len(config.Include.Metrics) == 0) ||
(len(config.Exclude.MatchType) > 0 && len(config.Exclude.Metrics) == 0) {
return fmt.Errorf("metrics must be supplied if match_type is set")
}
return nil
}
44 changes: 40 additions & 4 deletions processor/cumulativetodeltaprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/service/servicetest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset"
)

const configFile = "config.yaml"
Expand All @@ -46,9 +48,25 @@ func TestLoadingFullConfig(t *testing.T) {
{
expCfg: &Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
Metrics: []string{
"metric1",
"metric2",
Include: MatchMetrics{
Metrics: []string{
"metric1",
"metric2",
},
Config: filterset.Config{
MatchType: "strict",
RegexpConfig: nil,
},
},
Exclude: MatchMetrics{
Metrics: []string{
"metric3",
"metric4",
},
Config: filterset.Config{
MatchType: "strict",
RegexpConfig: nil,
},
},
MaxStaleness: 10 * time.Second,
},
Expand All @@ -73,10 +91,28 @@ func TestValidateConfig(t *testing.T) {
configName: "config.yaml",
succeed: true,
},
{
configName: "config_invalid_combo.yaml",
succeed: false,
errorMessage: "metrics and include/exclude cannot be used at the same time",
},
{
configName: "config_missing_match_type.yaml",
succeed: false,
errorMessage: "match_type must be set if metrics are supplied",
},
{
configName: "config_missing_name.yaml",
succeed: false,
errorMessage: "metric names are missing",
errorMessage: "metrics must be supplied if match_type is set",
},
{
configName: "config_empty.yaml",
succeed: true,
},
{
configName: "config_regexp.yaml",
succeed: true,
},
}

Expand Down
13 changes: 8 additions & 5 deletions processor/cumulativetodeltaprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumul
go 1.17

require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.48.0
github.com/stretchr/testify v1.7.1
go.opentelemetry.io/collector v0.49.0
go.opentelemetry.io/collector/pdata v0.49.0
Expand All @@ -12,23 +13,25 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/knadh/koanf v1.4.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v1.6.3 // indirect
go.opentelemetry.io/otel/metric v0.29.0 // indirect
go.opentelemetry.io/otel/trace v1.6.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal

replace go.opentelemetry.io/collector/pdata => go.opentelemetry.io/collector/pdata v0.0.0-20220412005140-8eb68f40028d
Loading