Skip to content

Commit aee8a07

Browse files
authored
NETOBSERV-2405: fix missing subnet labels from otel (#1988)
* NETOBSERV-2405: fix missing subnet labels from otel * Add test to prevent this occuring again
1 parent ce8a74e commit aee8a07

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

internal/pkg/helper/otel/otel-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"SrcK8S_HostIP": "source.k8s.host.address",
1111
"SrcK8S_HostName": "source.k8s.host.name",
1212
"SrcK8S_Zone": "source.zone",
13+
"SrcSubnetLabel": "source.subnet.label",
1314
"DstAddr": "destination.address",
1415
"DstMac": "destination.mac",
1516
"DstPort": "destination.port",
@@ -21,6 +22,7 @@
2122
"DstK8S_HostIP": "destination.k8s.host.address",
2223
"DstK8S_HostName": "destination.k8s.host.name",
2324
"DstK8S_Zone": "destination.zone",
25+
"DstSubnetLabel": "destination.subnet.label",
2426
"Bytes": "bytes",
2527
"Packets": "packets",
2628
"Proto": "protocol",
@@ -47,4 +49,4 @@
4749
"TimeFlowEndMs": "timeflowend",
4850
"TimeFlowStartMs": "timeflowstart",
4951
"TimeReceived": "timereceived"
50-
}
52+
}

internal/pkg/helper/otel/otel_config_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/netobserv/flowlogs-pipeline/pkg/api"
77
flowslatest "github.com/netobserv/network-observability-operator/api/flowcollector/v1beta2"
8+
"github.com/netobserv/network-observability-operator/internal/pkg/metrics"
9+
"github.com/netobserv/network-observability-operator/internal/pkg/test/util"
810
"github.com/stretchr/testify/assert"
911
)
1012

@@ -31,6 +33,7 @@ func TestOtelTransformConfig(t *testing.T) {
3133
{Input: "DstK8S_Zone", Output: "destination.zone", Multiplier: 0},
3234
{Input: "DstMac", Output: "destination.mac", Multiplier: 0},
3335
{Input: "DstPort", Output: "destination.port", Multiplier: 0},
36+
{Input: "DstSubnetLabel", Output: "destination.subnet.label", Multiplier: 0},
3437
{Input: "Flags", Output: "tcp.flags", Multiplier: 0},
3538
{Input: "FlowDirection", Output: "host.direction", Multiplier: 0},
3639
{Input: "IcmpCode", Output: "icmp.code", Multiplier: 0},
@@ -57,12 +60,27 @@ func TestOtelTransformConfig(t *testing.T) {
5760
{Input: "SrcK8S_Zone", Output: "source.zone", Multiplier: 0},
5861
{Input: "SrcMac", Output: "source.mac", Multiplier: 0},
5962
{Input: "SrcPort", Output: "source.port", Multiplier: 0},
63+
{Input: "SrcSubnetLabel", Output: "source.subnet.label", Multiplier: 0},
6064
{Input: "TimeFlowEndMs", Output: "timeflowend", Multiplier: 0},
6165
{Input: "TimeFlowRttNs", Output: "tcp.rtt", Multiplier: 0},
6266
{Input: "TimeFlowStartMs", Output: "timeflowstart", Multiplier: 0},
6367
{Input: "TimeReceived", Output: "timereceived", Multiplier: 0},
6468
}, m.Rules)
6569

70+
// Make sure default metric labels are all covered
71+
defs := metrics.GetDefinitions(util.SpecForMetrics(), false)
72+
for _, metric := range defs {
73+
for _, label := range metric.Spec.Labels {
74+
assert.True(t, fieldFound(label, m.Rules), "missing label '%s' found in metric '%s'", label, metric.Spec.MetricName)
75+
}
76+
for _, filter := range metric.Spec.Filters {
77+
assert.True(t, fieldFound(filter.Field, m.Rules), "missing label '%s' found in filters for metric '%s'", filter.Field, metric.Spec.MetricName)
78+
}
79+
if metric.Spec.ValueField != "" {
80+
assert.True(t, fieldFound(metric.Spec.ValueField, m.Rules), "missing '%s' used as ValueField for metric '%s'", metric.Spec.ValueField, metric.Spec.MetricName)
81+
}
82+
}
83+
6684
// override with custom rules
6785
m, err = GetOtelTransformConfig(&[]flowslatest.GenericTransformRule{{
6886
Input: "Test",
@@ -76,6 +94,15 @@ func TestOtelTransformConfig(t *testing.T) {
7694
assert.Equal(t, 1234, m.Rules[0].Multiplier)
7795
}
7896

97+
func fieldFound(name string, rules []api.GenericTransformRule) bool {
98+
for _, r := range rules {
99+
if name == r.Input {
100+
return true
101+
}
102+
}
103+
return false
104+
}
105+
79106
func TestOtelMetrics(t *testing.T) {
80107
metrics, err := GetOtelMetrics([]api.MetricsItem{{
81108
Name: "SrcK8S_Name",

0 commit comments

Comments
 (0)