Skip to content

Commit

Permalink
NETOBSERV-2084: get nested data as native maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Jan 30, 2025
1 parent 9729cf1 commit 31ade5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions pkg/pipeline/encode/encode_prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,15 @@ func Test_WithObjectListField(t *testing.T) {
{
"namespace": "A",
"events": []any{
config.GenericMap{"type": "acl", "name": "my_policy"},
map[string]string{"type": "acl", "name": "my_policy"},
},
"bytes": 1,
},
{
"namespace": "A",
"events": []any{
config.GenericMap{"type": "egress", "name": "my_egress"},
config.GenericMap{"type": "acl", "name": "my_policy"},
map[string]string{"type": "egress", "name": "my_egress"},
map[string]string{"type": "acl", "name": "my_policy"},
},
"bytes": 10,
},
Expand Down Expand Up @@ -733,8 +733,8 @@ func Test_WithObjectListField_bis(t *testing.T) {
{
"namespace": "A",
"events": []any{
config.GenericMap{"type": "egress", "name": "my_egress"},
config.GenericMap{"type": "acl", "name": "my_policy"},
map[string]string{"type": "egress", "name": "my_egress"},
map[string]string{"type": "acl", "name": "my_policy"},
},
"bytes": 10,
},
Expand Down Expand Up @@ -774,8 +774,8 @@ func Test_WithObjectListField_ter(t *testing.T) {
{
"namespace": "A",
"events": []any{
config.GenericMap{"type": "egress", "name": "my_egress"},
config.GenericMap{"type": "acl", "name": "my_policy"},
map[string]string{"type": "egress", "name": "my_egress"},
map[string]string{"type": "acl", "name": "my_policy"},
},
"bytes": 10,
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/pipeline/encode/metrics/flattening.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func (p *Preprocessed) GenerateFlatParts(flow config.GenericMap) []config.Generi
prefix := fl + ">"
for _, vv := range v {
switch vvv := vv.(type) {
case config.GenericMap:
case map[string]string:
partsForLabel = append(partsForLabel, flattenNested(prefix, vvv))
default:
partsForLabel = append(partsForLabel, config.GenericMap{fl: vv})
}
}
case []config.GenericMap:
case []map[string]string:
prefix := fl + ">"
for _, vv := range v {
partsForLabel = append(partsForLabel, flattenNested(prefix, vv))
Expand Down Expand Up @@ -79,7 +79,7 @@ func distribute(allUnflat [][]config.GenericMap) []config.GenericMap {
return ret
}

func flattenNested(prefix string, nested config.GenericMap) config.GenericMap {
func flattenNested(prefix string, nested map[string]string) config.GenericMap {
subFlow := config.GenericMap{}
for k, v := range nested {
subFlow[prefix+k] = v
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/encode/metrics/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func Test_Flatten(t *testing.T) {
"namespace": "A",
"interfaces": []string{"eth0", "123456"},
"events": []any{
config.GenericMap{"type": "egress", "name": "my_egress"},
config.GenericMap{"type": "acl", "name": "my_policy"},
map[string]string{"type": "egress", "name": "my_egress"},
map[string]string{"type": "acl", "name": "my_policy"},
},
"bytes": 7,
})
Expand Down

0 comments on commit 31ade5f

Please sign in to comment.