Skip to content

Commit

Permalink
Fix telemetry labels propagation (#835)
Browse files Browse the repository at this point in the history
### Description of change
This fixes regression introduced in
#828.

Dynamic Telemetry Flow Labels were added before labels filtering, which
led them to be incorrectly filtered out.

##### Checklist

- [x] Tested in playground or other setup
- [x] Breaking changes
  • Loading branch information
kwapik authored and kklimonda-fn committed Oct 28, 2022
1 parent 750ce20 commit 4ec5b4b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcont
labels[otelcollector.ApertureFlowLabelKeysLabel].Slice().AppendEmpty().SetStr(flowLabelKey)
}

for key, value := range checkResponse.GetTelemetryFlowLabels() {
pcommon.NewValueStr(value).CopyTo(attributes.PutEmpty(key))
}

for _, classifier := range checkResponse.ClassifierInfos {
rawValue := []string{
fmt.Sprintf("%s:%v", metrics.PolicyNameLabel, classifier.PolicyName),
Expand All @@ -141,3 +137,10 @@ func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcont
value.CopyTo(attributes.PutEmpty(key))
}
}

// AddFlowLabels adds dynamic from labels.
func AddFlowLabels(attributes pcommon.Map, checkResponse *flowcontrolv1.CheckResponse) {
for key, value := range checkResponse.GetTelemetryFlowLabels() {
pcommon.NewValueStr(value).CopyTo(attributes.PutEmpty(key))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,6 @@ var _ = DescribeTable("Check Response labels", func(checkResponse *flowcontrolv1
map[string]interface{}{otelcollector.ApertureFlowLabelKeysLabel: []interface{}{"someLabel", "otherLabel"}},
),

Entry("Sets telemetry flow labels",
&flowcontrolv1.CheckResponse{
TelemetryFlowLabels: map[string]string{
"someLabel": "someValue",
"otherLabel": "otherValue",
},
},
map[string]interface{}{
"someLabel": "someValue",
"otherLabel": "otherValue",
},
),

Entry("Sets classifiers",
&flowcontrolv1.CheckResponse{
ClassifierInfos: []*flowcontrolv1.ClassifierInfo{
Expand All @@ -138,3 +125,16 @@ var _ = DescribeTable("Check Response labels", func(checkResponse *flowcontrolv1
},
),
)

var _ = Describe("AddFlowLabels", func() {
attributes := pcommon.NewMap()
checkResponse := &flowcontrolv1.CheckResponse{
TelemetryFlowLabels: map[string]string{
"someLabel": "someValue",
"otherLabel": "otherValue",
},
}
internal.AddFlowLabels(attributes, checkResponse)
Expect(attributes.AsRaw()).To(HaveKeyWithValue("someLabel", "someValue"))
Expect(attributes.AsRaw()).To(HaveKeyWithValue("otherLabel", "otherValue"))
})
3 changes: 3 additions & 0 deletions pkg/otelcollector/metricsprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func (p *metricsProcessor) ConsumeLogs(ctx context.Context, ld plog.Logs) (plog.
p.updateMetrics(attributes, checkResponse, []string{otelcollector.EnvoyMissingAttributeValue})
internal.EnforceIncludeListHTTP(attributes)
}

// This needs to be called **after** internal.EnforceIncludeList{HTTP,SDK}.
internal.AddFlowLabels(attributes, checkResponse)
return nil
})
return ld, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/otelcollector/metricsprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var _ = Describe("Metrics Processor", func() {
}}
baseCheckResp.FluxMeterInfos = []*flowcontrolv1.FluxMeterInfo{{FluxMeterName: "bar"}}
baseCheckResp.FlowLabelKeys = []string{"someLabel"}
baseCheckResp.TelemetryFlowLabels = map[string]string{"flowLabelKey": "flowLabelValue"}
baseCheckResp.Services = []string{"svc1", "svc2"}

// <split> is a workaround until PR https://github.com/prometheus/client_golang/pull/1143 is released
Expand Down Expand Up @@ -228,6 +229,7 @@ workload_latency_ms_count{component_index="1",decision_type="DECISION_TYPE_REJEC
oc.ApertureProcessingDurationLabel: float64(1000),
oc.ApertureServicesLabel: []interface{}{"svc1", "svc2"},
oc.ApertureControlPointLabel: "type:TYPE_INGRESS",
"flowLabelKey": "flowLabelValue",
}
source = oc.ApertureSourceEnvoy

Expand Down

0 comments on commit 4ec5b4b

Please sign in to comment.