-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
factory.go
68 lines (58 loc) · 2.16 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
61
62
63
64
65
66
67
68
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package wavefrontreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver"
import (
"context"
"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/carbonreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver/internal/metadata"
)
// This file implements factory for the Wavefront receiver.
// NewFactory creates a factory for WaveFront receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}
func createDefaultConfig() component.Config {
return &Config{
TCPAddr: confignet.TCPAddr{
Endpoint: "localhost:2003",
},
TCPIdleTimeout: transport.TCPIdleTimeoutDefault,
}
}
func createMetricsReceiver(
_ context.Context,
params receiver.CreateSettings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
rCfg := cfg.(*Config)
// Wavefront is very similar to Carbon: it is TCP based in which each received
// text line represents a single metric data point. They differ on the format
// of their textual representation.
//
// The Wavefront receiver leverages the Carbon receiver code by implementing
// a dedicated parser for its format.
carbonCfg := carbonreceiver.Config{
NetAddr: confignet.NetAddr{
Endpoint: rCfg.Endpoint,
Transport: "tcp",
},
TCPIdleTimeout: rCfg.TCPIdleTimeout,
Parser: &protocol.Config{
Type: "plaintext", // TODO: update after other parsers are implemented for Carbon receiver.
Config: &WavefrontParser{
ExtractCollectdTags: rCfg.ExtractCollectdTags,
},
},
}
return carbonreceiver.New(params, carbonCfg, consumer)
}