-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathfactory.go
60 lines (51 loc) · 1.83 KB
/
factory.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package statsdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
import (
"context"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol"
)
const (
defaultBindEndpoint = "localhost:8125"
defaultAggregationInterval = 60 * time.Second
defaultEnableMetricType = false
defaultIsMonotonicCounter = false
)
var (
defaultTimerHistogramMapping = []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}, {StatsdType: "distribution", ObserverType: "gauge"}}
)
// NewFactory creates a factory for the StatsD receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
)
}
func createDefaultConfig() component.Config {
return &Config{
NetAddr: confignet.AddrConfig{
Endpoint: defaultBindEndpoint,
Transport: confignet.TransportTypeUDP,
},
AggregationInterval: defaultAggregationInterval,
EnableMetricType: defaultEnableMetricType,
IsMonotonicCounter: defaultIsMonotonicCounter,
TimerHistogramMapping: defaultTimerHistogramMapping,
}
}
func createMetricsReceiver(
_ context.Context,
params receiver.Settings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
c := cfg.(*Config)
return newReceiver(params, *c, consumer)
}