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

32669 sumconnector config #33994

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
57ae016
config function and testing
greatestusername Jul 8, 2024
d0ef23d
additional config and config test tweaks
greatestusername Jul 9, 2024
4fc3cd9
Merge branch 'open-telemetry:main' into 32669-sumconnector-config
greatestusername Jul 9, 2024
56f38bd
tidy etc
greatestusername Jul 9, 2024
c20b0f9
collect and report errors
greatestusername Jul 10, 2024
0f97989
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 10, 2024
1d40714
update order of tests, use join instead of multierr
greatestusername Jul 15, 2024
3adc1b2
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 15, 2024
f88ec6c
Merge branch '32669-sumconnector-config' of github.com:greatestuserna…
greatestusername Jul 15, 2024
15fd76b
gci fmt lint
greatestusername Jul 15, 2024
2142b50
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 15, 2024
4f43f72
revert attrkey change
greatestusername Jul 16, 2024
7d09dd3
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 16, 2024
e53e668
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 16, 2024
005fed1
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 16, 2024
3ccf4ef
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 17, 2024
68f473c
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 18, 2024
4083e69
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 19, 2024
dea1989
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 22, 2024
a972500
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 23, 2024
2975acf
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 24, 2024
b0224c1
Merge branch 'main' into 32669-sumconnector-config
greatestusername Jul 25, 2024
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
96 changes: 96 additions & 0 deletions connector/sumconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

package sumconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/sumconnector"

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/component"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
)

// Config for the connector
type Config struct {
Spans map[string]MetricInfo `mapstructure:"spans"`
Expand All @@ -24,3 +35,88 @@ type AttributeConfig struct {
Key string `mapstructure:"key"`
DefaultValue any `mapstructure:"default_value"`
}

func (c *Config) Validate() (combinedErrors error) {
for name, info := range c.Spans {
if name == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spans: metric name missing"))
}
if info.SourceAttribute == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spans: metric source_attribute missing"))
}
if _, err := filterottl.NewBoolExprForSpan(info.Conditions, filterottl.StandardSpanFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()}); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spans condition: metric %q: %w", name, err))
}
if err := info.validateAttributes(); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spans attributes: metric %q: %w", name, err))
}
}
for name, info := range c.SpanEvents {
if name == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spanevents: metric name missing"))
}
if info.SourceAttribute == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spanevents: metric source_attribute missing"))
}
if _, err := filterottl.NewBoolExprForSpanEvent(info.Conditions, filterottl.StandardSpanEventFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()}); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spanevents condition: metric %q: %w", name, err))
}
if err := info.validateAttributes(); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("spanevents attributes: metric %q: %w", name, err))
}
}
for name, info := range c.Metrics {
if name == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("metrics: metric name missing"))
}
if info.SourceAttribute == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("metrics: metric source_attribute missing"))
}
if _, err := filterottl.NewBoolExprForMetric(info.Conditions, filterottl.StandardMetricFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()}); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("metrics condition: metric %q: %w", name, err))
}
if len(info.Attributes) > 0 {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("metrics attributes not supported: metric %q", name))
}
}
for name, info := range c.DataPoints {
if name == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("datapoints: metric name missing"))
}
if info.SourceAttribute == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("datapoints: metric source_attribute missing"))
}
if _, err := filterottl.NewBoolExprForDataPoint(info.Conditions, filterottl.StandardDataPointFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()}); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("datapoints condition: metric %q: %w", name, err))
}
if err := info.validateAttributes(); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("datapoints attributes: metric %q: %w", name, err))
}
}
for name, info := range c.Logs {
if name == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("logs: metric name missing"))
}
if info.SourceAttribute == "" {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("logs: metric source_attribute missing"))
}
if _, err := filterottl.NewBoolExprForLog(info.Conditions, filterottl.StandardLogFuncs(), ottl.PropagateError, component.TelemetrySettings{Logger: zap.NewNop()}); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("logs condition: metric %q: %w", name, err))
}
if err := info.validateAttributes(); err != nil {
combinedErrors = errors.Join(combinedErrors, fmt.Errorf("logs attributes: metric %q: %w", name, err))
}
}
return combinedErrors
}

func (i *MetricInfo) validateAttributes() error {
for _, attr := range i.Attributes {
if attr.Key == "" {
return fmt.Errorf("attribute key missing")
crobert-1 marked this conversation as resolved.
Show resolved Hide resolved
}
}
return nil
}

var _ component.ConfigValidator = (*Config)(nil)
Loading