-
Notifications
You must be signed in to change notification settings - Fork 24
/
lua_labels.go
41 lines (35 loc) · 1.76 KB
/
lua_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
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"
)
// AddLuaSpecificLabels adds labels specific to data source.
func AddLuaSpecificLabels(attributes pcommon.Map) {
treatAsMissing := []string{otelconsts.LuaMissingAttributeValue}
// 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)
}
flowStart, flowStartExists := otelcollector.GetFloat64(attributes, otelconsts.ApertureFlowStartTimestampLabel, treatAsMissing)
workloadStart, workloadStartExists := otelcollector.GetFloat64(attributes, otelconsts.ApertureWorkloadStartTimestampLabel, treatAsMissing)
flowEnd, flowEndExists := otelcollector.GetFloat64(attributes, otelconsts.ApertureFlowEndTimestampLabel, treatAsMissing)
// Add ResponseReceivedLabel based on whether flowEnd is present
if flowEndExists {
attributes.PutStr(otelconsts.ResponseReceivedLabel, otelconsts.ResponseReceivedTrue)
} else {
attributes.PutStr(otelconsts.ResponseReceivedLabel, otelconsts.ResponseReceivedFalse)
}
if flowStartExists && flowEndExists {
attributes.PutDouble(otelconsts.FlowDurationLabel, flowEnd-flowStart)
}
if workloadStartExists && flowEndExists {
attributes.PutDouble(otelconsts.WorkloadDurationLabel, flowEnd-workloadStart)
}
}