-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
factory.go
50 lines (42 loc) · 1.34 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package collectdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/collectdreceiver"
import (
"context"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/collectdreceiver/internal/metadata"
)
// This file implements factory for CollectD receiver.
const (
defaultBindEndpoint = "localhost:8081"
defaultEncodingFormat = "json"
)
// NewFactory creates a factory for collectd receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}
func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: defaultBindEndpoint,
},
Timeout: 30 * time.Second,
Encoding: defaultEncodingFormat,
}
}
func createMetricsReceiver(
_ context.Context,
cs receiver.CreateSettings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
c := cfg.(*Config)
return newCollectdReceiver(cs.Logger, c, c.AttributesPrefix, nextConsumer, cs)
}