From 31ade5ff113b9bf315803403e56d0d135b8077ef Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Thu, 30 Jan 2025 13:27:05 +0100 Subject: [PATCH] NETOBSERV-2084: get nested data as native maps --- pkg/pipeline/encode/encode_prom_test.go | 14 +++++++------- pkg/pipeline/encode/metrics/flattening.go | 6 +++--- pkg/pipeline/encode/metrics/preprocess_test.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/pipeline/encode/encode_prom_test.go b/pkg/pipeline/encode/encode_prom_test.go index 8c940f0cd..7bc77aa9c 100644 --- a/pkg/pipeline/encode/encode_prom_test.go +++ b/pkg/pipeline/encode/encode_prom_test.go @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/pkg/pipeline/encode/metrics/flattening.go b/pkg/pipeline/encode/metrics/flattening.go index e9f27ebbd..53e803ce7 100644 --- a/pkg/pipeline/encode/metrics/flattening.go +++ b/pkg/pipeline/encode/metrics/flattening.go @@ -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)) @@ -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 diff --git a/pkg/pipeline/encode/metrics/preprocess_test.go b/pkg/pipeline/encode/metrics/preprocess_test.go index 93be8bf26..3a5fe8a13 100644 --- a/pkg/pipeline/encode/metrics/preprocess_test.go +++ b/pkg/pipeline/encode/metrics/preprocess_test.go @@ -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, })