Skip to content

Commit 4591ecf

Browse files
committed
wip: adds support for hints in receiver_creator
Signed-off-by: ChrsMark <[email protected]>
1 parent 8f307f5 commit 4591ecf

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

receiver/receivercreator/observerhandler.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,47 @@ func (obs *observerHandler) OnAdd(added []observer.Endpoint) {
8383
continue
8484
}
8585

86-
obs.params.TelemetrySettings.Logger.Debug("handling added endpoint", zap.Any("env", env))
86+
obs.params.TelemetrySettings.Logger.Info("handling added endpoint", zap.Any("env", env))
87+
88+
ann := env["annotations"]
89+
if ann != nil {
90+
annotations, ok := ann.(map[string]string)
91+
if !ok {
92+
// Can't assert, handle error.
93+
}
94+
if len(annotations) > 0 {
95+
// detect if there are hints
96+
subreceiverKey := annotations["otel.hints/receiver"]
97+
if subreceiverKey == "" {
98+
break
99+
}
100+
obs.params.TelemetrySettings.Logger.Warn("handling added hinted receiver", zap.Any("subreceiverKey", subreceiverKey))
101+
102+
userConfigMap := userConfigMap{"collection_interval": "10s"}
103+
subreceiverEndpoint := annotations["otel.hints/endpoint"]
104+
if subreceiverEndpoint == "" {
105+
break
106+
}
107+
userConfigMap["endpoint"] = subreceiverEndpoint
108+
subreceiver, err := newReceiverTemplate(subreceiverKey, userConfigMap)
109+
if err != nil {
110+
// TODO: handle error here
111+
obs.params.TelemetrySettings.Logger.Debug("error adding subreceiver1", zap.Any("err", err))
112+
break
113+
}
114+
115+
subreceiver.Rule = "type == \"pod\""
116+
subreceiver.rule, err = newRule(subreceiver.Rule)
117+
if err != nil {
118+
// TODO: handle error here
119+
obs.params.TelemetrySettings.Logger.Debug("error adding subreceiver rule", zap.Any("err", err))
120+
break
121+
}
122+
123+
obs.config.receiverTemplates[subreceiverKey] = subreceiver
124+
}
125+
}
126+
obs.params.TelemetrySettings.Logger.Debug("handling added templates", zap.Any("templates", obs.config.receiverTemplates))
87127

88128
for _, template := range obs.config.receiverTemplates {
89129
if matches, e := template.rule.eval(env); e != nil {
@@ -96,7 +136,8 @@ func (obs *observerHandler) OnAdd(added []observer.Endpoint) {
96136
obs.params.TelemetrySettings.Logger.Info("starting receiver",
97137
zap.String("name", template.id.String()),
98138
zap.String("endpoint", e.Target),
99-
zap.String("endpoint_id", string(e.ID)))
139+
zap.String("endpoint_id", string(e.ID)),
140+
zap.Any("config", template.config))
100141

101142
resolvedConfig, err := expandConfig(template.config, env)
102143
if err != nil {

0 commit comments

Comments
 (0)