-
Notifications
You must be signed in to change notification settings - Fork 23
/
envoy_labels.go
46 lines (39 loc) · 1.87 KB
/
envoy_labels.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
package internal
import (
"go.opentelemetry.io/collector/pdata/pcommon"
"github.com/fluxninja/aperture/v2/pkg/otelcollector"
otelconsts "github.com/fluxninja/aperture/v2/pkg/otelcollector/consts"
)
// AddEnvoySpecificLabels adds labels specific to Envoy data source.
func AddEnvoySpecificLabels(attributes pcommon.Map) {
treatAsMissing := []string{otelconsts.EnvoyMissingAttributeValue}
// Retrieve request length
requestLength, requestLengthFound := otelcollector.GetFloat64(attributes, otelconsts.BytesSentLabel, treatAsMissing)
if requestLengthFound {
attributes.PutDouble(otelconsts.HTTPRequestContentLength, requestLength)
}
// Retrieve response lengths
responseLength, responseLengthFound := otelcollector.GetFloat64(attributes, otelconsts.BytesReceivedLabel, treatAsMissing)
if responseLengthFound {
attributes.PutDouble(otelconsts.HTTPResponseContentLength, responseLength)
}
// Compute durations
responseDuration, responseDurationExists := otelcollector.GetFloat64(attributes, otelconsts.ResponseDurationLabel, treatAsMissing)
authzDuration, authzDurationExists := otelcollector.GetFloat64(attributes, otelconsts.EnvoyAuthzDurationLabel, treatAsMissing)
// Add ResponseReceivedLabel based on whether responseDuration is present and non-zero
if responseDurationExists && responseDuration > 0 {
attributes.PutStr(otelconsts.ResponseReceivedLabel, otelconsts.ResponseReceivedTrue)
} else {
attributes.PutStr(otelconsts.ResponseReceivedLabel, otelconsts.ResponseReceivedFalse)
}
if responseDurationExists {
attributes.PutDouble(otelconsts.FlowDurationLabel, responseDuration)
}
if responseDurationExists && authzDurationExists {
workloadDuration := responseDuration - authzDuration
// discard negative values which can happen in case of connection resets
if workloadDuration > 0 {
attributes.PutDouble(otelconsts.WorkloadDurationLabel, workloadDuration)
}
}
}