Skip to content

Commit

Permalink
chore(faro): prefix measurement values when parsing faro measurements (
Browse files Browse the repository at this point in the history
…#6810)

* chore(faro): prefix measurement values

* changelog

* pr: remove duplicated changelog entry

* pr: do not convert measurement values to strings

* extend unit test

---------

Co-authored-by: William Dumont <[email protected]>
  • Loading branch information
codecapitano and wildum authored Jun 6, 2024
1 parent 6ead6f7 commit 53d022d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ v0.41.0 (2024-05-31)

- 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

0 comments on commit 53d022d

Please sign in to comment.