Skip to content

Commit 76b3828

Browse files
committed
Warn when protocolFilter matches no supported protocols
NewProtocolFilter logged the "nothing will be exported" warning only when the configured protocolFilter list was literally empty. When the list contained only invalid/unsupported protocol names (which the static agent config does not validate, unlike the CRD enum), the effective filter denied all protocols and dropped every flow, but the warning was not logged. Check the number of validated protocols instead of the raw input length, so the warning is emitted whenever the filter matches no supported protocols. Fixes #8158 Signed-off-by: Anand-240 <srivastavaanandprakash16@gmail.com>
1 parent 33e8881 commit 76b3828

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pkg/agent/flowexporter/filter/protocol_filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func NewProtocolFilter(protocols []string) ProtocolFilter {
6060
klog.InfoS("Found unsupported protocol(s) in protocolFilter, refer to the docs for supported protocols", "unsupportedProtocols", strings.Join(invalidProtocols, ","))
6161
}
6262

63-
if len(protocols) == 0 {
64-
klog.InfoS("protocolFilter is empty and nothing will be exported")
63+
if len(validatedProtocols) == 0 {
64+
klog.InfoS("protocolFilter matches no supported protocols, so no flows will be exported")
6565
}
6666

6767
return ProtocolFilter{

pkg/agent/flowexporter/filter/protocol_filter_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func TestNewProtocolFilter(t *testing.T) {
5454
[]string{"TCP", "udp", "sctp"},
5555
sets.New(tcp, udp, sctp),
5656
},
57+
{
58+
// A non-empty list of only invalid protocols results in an empty
59+
// (but non-nil) set, which denies all protocols.
60+
"Only invalid protocols",
61+
[]string{"tpc", "icmp"},
62+
sets.New[uint8](),
63+
},
5764
}
5865
for _, tc := range testCases {
5966
t.Run(tc.name, func(t *testing.T) {
@@ -100,6 +107,14 @@ func TestProtocolFilter_Allow(t *testing.T) {
100107
sctp,
101108
false,
102109
},
110+
{
111+
// When every configured protocol is invalid, the filter denies all
112+
// protocols rather than allowing all.
113+
"only invalid protocols deny everything",
114+
[]string{"tpc"},
115+
tcp,
116+
false,
117+
},
103118
}
104119
for _, tc := range testCases {
105120
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)