forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
82 lines (67 loc) · 2.86 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package statsdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
import (
"fmt"
"time"
"github.com/lightstep/go-expohisto/structure"
"go.opentelemetry.io/collector/config/confignet"
"go.uber.org/multierr"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol"
)
// Config defines configuration for StatsD receiver.
type Config struct {
NetAddr confignet.NetAddr `mapstructure:",squash"`
AggregationInterval time.Duration `mapstructure:"aggregation_interval"`
EnableMetricType bool `mapstructure:"enable_metric_type"`
IsMonotonicCounter bool `mapstructure:"is_monotonic_counter"`
TimerHistogramMapping []protocol.TimerHistogramMapping `mapstructure:"timer_histogram_mapping"`
}
func (c *Config) Validate() error {
var errs error
if c.AggregationInterval <= 0 {
errs = multierr.Append(errs, fmt.Errorf("aggregation_interval must be a positive duration"))
}
var TimerHistogramMappingMissingObjectName bool
for _, eachMap := range c.TimerHistogramMapping {
if eachMap.StatsdType == "" {
TimerHistogramMappingMissingObjectName = true
break
}
switch eachMap.StatsdType {
case protocol.TimingTypeName, protocol.TimingAltTypeName, protocol.HistogramTypeName, protocol.DistributionTypeName:
// do nothing
case protocol.CounterTypeName, protocol.GaugeTypeName:
fallthrough
default:
errs = multierr.Append(errs, fmt.Errorf("statsd_type is not a supported mapping for histogram and timing metrics: %s", eachMap.StatsdType))
}
if eachMap.ObserverType == "" {
TimerHistogramMappingMissingObjectName = true
break
}
switch eachMap.ObserverType {
case protocol.GaugeObserver, protocol.SummaryObserver, protocol.HistogramObserver:
// do nothing
case protocol.DisableObserver:
fallthrough
default:
errs = multierr.Append(errs, fmt.Errorf("observer_type is not supported for histogram and timing metrics: %s", eachMap.ObserverType))
}
if eachMap.ObserverType == protocol.HistogramObserver {
if eachMap.Histogram.MaxSize != 0 && (eachMap.Histogram.MaxSize < structure.MinSize || eachMap.Histogram.MaxSize > structure.MaximumMaxSize) {
errs = multierr.Append(errs, fmt.Errorf("histogram max_size out of range: %v", eachMap.Histogram.MaxSize))
}
} else {
// Non-histogram observer w/ histogram config
var empty protocol.HistogramConfig
if eachMap.Histogram != empty {
errs = multierr.Append(errs, fmt.Errorf("histogram configuration requires observer_type: histogram"))
}
}
}
if TimerHistogramMappingMissingObjectName {
errs = multierr.Append(errs, fmt.Errorf("must specify object id for all TimerHistogramMappings"))
}
return errs
}