Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(faro): prefix measurement values when parsing faro measurements #6810

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Main (unreleased)

- Added support for `otelcol` configuration conversion in `grafana-agent convert` and `grafana-agent run` commands. (@rfratto, @erikbaranowski, @tpaschalis, @hainenber)

- Prefix Faro measurement values with `value_` to align with the latest Faro cloud receiver updates. (@codecapitano)

- Added support for `static` configuration conversion of the `traces` subsystem. (@erikbaranowski, @wildum)

- Add automatic conversion for `legacy_positions_file` in component `loki.source.file`. (@mattdurham)
Expand Down
10 changes: 9 additions & 1 deletion internal/component/faro/receiver/internal/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type Measurement struct {
Context MeasurementContext `json:"context,omitempty"`
}

// KeyVal representation of the exception object
// KeyVal representation of the measurement object
func (m Measurement) KeyVal() *KeyVal {
kv := NewKeyVal()

Expand All @@ -238,6 +238,14 @@ func (m Measurement) KeyVal() *KeyVal {
}
MergeKeyVal(kv, m.Trace.KeyVal())
MergeKeyValWithPrefix(kv, KeyValFromMap(m.Context), "context_")

values := make(map[string]float64, len(m.Values))
for key, value := range m.Values {
values[key] = value
}

MergeKeyValWithPrefix(kv, KeyValFromFloatMap(values), "value_")

return kv
}

Expand Down
20 changes: 20 additions & 0 deletions internal/component/faro/receiver/internal/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,24 @@ func TestUnmarshalPayloadJSON(t *testing.T) {
},
},
}, payload.Measurements)

kv := payload.Measurements[0].KeyVal()
expectedKv := NewKeyVal()
expectedKv.Set("kind", "measurement")
expectedKv.Set("type", "foobar")
expectedKv.Set("ttfb", 14.000000)
expectedKv.Set("ttfcp", 22.120000)
expectedKv.Set("ttfp", 20.120000)
expectedKv.Set("traceID", "abcd")
expectedKv.Set("spanID", "def")
expectedKv.Set("context_hello", "world")
expectedKv.Set("value_ttfb", 14)
expectedKv.Set("value_ttfcp", 22.12)
expectedKv.Set("value_ttfp", 20.12)
expectedPair := kv.Oldest()
for pair := kv.Oldest(); pair != nil; pair = pair.Next() {
require.Equal(t, expectedPair.Key, pair.Key)
require.Equal(t, expectedPair.Value, pair.Value)
expectedPair = expectedPair.Next()
}
}
14 changes: 14 additions & 0 deletions internal/component/faro/receiver/internal/payload/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ func KeyValFromMap(m map[string]string) *KeyVal {
return kv
}

// KeyValFromMap will instantiate KeyVal from a map[string]float64
func KeyValFromFloatMap(m map[string]float64) *KeyVal {
kv := NewKeyVal()
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
kv.Set(k, m[k])
}
return kv
}

// MergeKeyVal will merge source in target
func MergeKeyVal(target *KeyVal, source *KeyVal) {
for el := source.Oldest(); el != nil; el = el.Next() {
Expand Down
Loading