This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
factory.go
95 lines (84 loc) · 2.46 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package receiver
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"github.com/cilium/hubble-otel/common"
"github.com/cilium/hubble-otel/trace"
)
const (
typeStr = "hubble"
)
var receivers = make(map[config.Receiver]*hubbleReceiver)
func getReceiver(cfg config.Receiver, settings component.ReceiverCreateSettings) *hubbleReceiver {
if r, ok := receivers[cfg]; ok {
return r
}
r := newHubbleReceiver(cfg.(*Config), settings)
receivers[cfg] = r
return r
}
func NewFactory() component.ReceiverFactory {
return receiverhelper.NewFactory(
typeStr,
createDefaultConfig,
receiverhelper.WithTraces(createTracesReceiver),
receiverhelper.WithLogs(createLogsReceiver))
}
func createDefaultConfig() config.Receiver {
_true, _false := new(bool), new(bool)
*_true, *_false = true, false
defaultTraceEncoding, defaultLogEncoding := common.DefaultTraceEncoding, common.DefaultLogEncoding
return &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
BufferSize: 2048,
FallbackServiceNamePrefix: common.OTelAttrServiceNameDefaultPrefix,
TraceCacheWindow: trace.DefaultTraceCacheWindow,
ParseTraceHeaders: true,
FlowEncodingOptions: FlowEncodingOptions{
Traces: common.EncodingOptions{
Encoding: &defaultTraceEncoding,
LabelsAsMaps: _true,
HeadersAsMaps: _true,
TopLevelKeys: _true,
},
Logs: common.EncodingOptions{
Encoding: &defaultLogEncoding,
LabelsAsMaps: _true,
HeadersAsMaps: _true,
TopLevelKeys: _false,
LogPayloadAsBody: _false,
},
},
IncludeFlowTypes: IncludeFlowTypes{
Traces: common.IncludeFlowTypes{},
Logs: common.IncludeFlowTypes{},
},
}
}
func createTracesReceiver(
_ context.Context,
settings component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Traces,
) (component.TracesReceiver, error) {
r := getReceiver(cfg, settings)
if err := r.registerTraceConsumer(nextConsumer); err != nil {
return nil, err
}
return r, nil
}
func createLogsReceiver(
_ context.Context,
settings component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Logs,
) (component.LogsReceiver, error) {
r := getReceiver(cfg, settings)
if err := r.registerLogsConsumer(nextConsumer); err != nil {
return nil, err
}
return r, nil
}