Skip to content

Commit daf09af

Browse files
NETOBSERV-2555 Filters observed even when features not enabled in flowcollector (#1256)
* add features on filters * add missing Feature field * oc token not needed for testing --------- Co-authored-by: Leandro Beretta <lea.beretta@gmail.com>
1 parent fa0368b commit daf09af

6 files changed

Lines changed: 72 additions & 16 deletions

File tree

config/sample-config.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ prometheus:
2323
url: https://localhost:9090
2424
timeout: 30s
2525
skipTls: true
26-
tokenPath: /tmp/oc-token.txt
26+
# tokenPath: /tmp/oc-token.txt
2727
alertManager:
2828
# url: https://localhost:9094
2929
metrics:
@@ -944,6 +944,7 @@ frontend:
944944
name: Cluster
945945
component: autocomplete
946946
hint: Specify a cluster ID or name.
947+
feature: multiCluster
947948
- id: namespace
948949
name: Namespace
949950
component: autocomplete
@@ -1105,31 +1106,37 @@ frontend:
11051106
component: autocomplete
11061107
category: endpoint
11071108
hint: Specify a single zone.
1109+
feature: zones
11081110
- id: src_zone
11091111
name: Zone
11101112
component: autocomplete
11111113
category: source
11121114
hint: Specify a single zone.
1115+
feature: zones
11131116
- id: dst_zone
11141117
name: Zone
11151118
component: autocomplete
11161119
category: destination
11171120
hint: Specify a single zone.
1121+
feature: zones
11181122
- id: subnet_label
11191123
name: Subnet Label
11201124
component: autocomplete
11211125
category: endpoint
11221126
hint: Specify a subnet label, or an empty string to get unmatched sources.
1127+
feature: subnetLabels
11231128
- id: src_subnet_label
11241129
name: Subnet Label
11251130
component: autocomplete
11261131
category: source
11271132
hint: Specify a subnet label, or an empty string to get unmatched sources.
1133+
feature: subnetLabels
11281134
- id: dst_subnet_label
11291135
name: Subnet Label
11301136
component: autocomplete
11311137
category: destination
11321138
hint: Specify a subnet label, or an empty string to get unmatched destinations.
1139+
feature: subnetLabels
11331140
- id: resource
11341141
name: Resource
11351142
component: autocomplete
@@ -1329,14 +1336,17 @@ frontend:
13291336
name: Network Name
13301337
component: text
13311338
category: endpoint
1339+
feature: multiNetworks
13321340
- id: src_network
13331341
name: Network Name
13341342
component: text
13351343
category: source
1344+
feature: multiNetworks
13361345
- id: dst_network
13371346
name: Network Name
13381347
component: text
13391348
category: destination
1349+
feature: multiNetworks
13401350
- id: protocol
13411351
name: Protocol
13421352
component: autocomplete
@@ -1393,6 +1403,7 @@ frontend:
13931403
name: User Defined Network
13941404
component: autocomplete
13951405
hint: Specify a user defined network name.
1406+
feature: udnMapping
13961407
- id: id
13971408
name: Conversation Id
13981409
component: text
@@ -1407,6 +1418,7 @@ frontend:
14071418
- A _LINUX_TCP_STATES_H number like 1, 2, 3
14081419
- A _LINUX_TCP_STATES_H TCP name like ESTABLISHED, SYN_SENT, SYN_RECV
14091420
docUrl: https://github.com/torvalds/linux/blob/master/include/net/tcp_states.h
1421+
feature: pktDrop
14101422
- id: pkt_drop_cause
14111423
name: Packet drop latest cause
14121424
component: autocomplete
@@ -1417,18 +1429,22 @@ frontend:
14171429
- A _LINUX_DROPREASON_CORE_H number like 2, 3, 4
14181430
- A _LINUX_DROPREASON_CORE_H SKB_DROP_REASON name like NOT_SPECIFIED, NO_SOCKET, PKT_TOO_SMALL
14191431
docUrl: https://github.com/torvalds/linux/blob/master/include/net/dropreason-core.h
1432+
feature: pktDrop
14201433
- id: dns_id
14211434
name: DNS Id
14221435
component: number
14231436
hint: Specify a single DNS Id.
1437+
feature: dnsTracking
14241438
- id: dns_name
14251439
name: DNS Name
14261440
component: text
14271441
hint: Specify a single DNS name.
1442+
feature: dnsTracking
14281443
- id: dns_latency
14291444
name: DNS Latency
14301445
component: number
14311446
hint: Specify a DNS Latency in miliseconds.
1447+
feature: dnsTracking
14321448
- id: dns_flag_response_code
14331449
name: DNS Response Code
14341450
component: autocomplete
@@ -1439,46 +1455,56 @@ frontend:
14391455
- A IANA RCODE number like 0, 3, 9
14401456
- A IANA RCODE name like NoError, NXDomain, NotAuth
14411457
docUrl: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
1458+
feature: dnsTracking
14421459
- id: dns_errno
14431460
name: DNS Error
14441461
component: autocomplete
14451462
hint: Specify a single DNS error number.
1463+
feature: dnsTracking
14461464
- id: time_flow_rtt
14471465
name: Flow RTT
14481466
component: number
14491467
hint: Specify a TCP smoothed Round Trip Time in nanoseconds.
1468+
feature: flowRTT
14501469
- id: network_events
14511470
name: Network Events
14521471
component: text
14531472
hint: Specify a single network event.
1473+
feature: networkEvents
14541474
- id: xlat_zone_id
14551475
name: Xlat Zone Id
14561476
component: number
1477+
feature: packetTranslation
14571478
- id: xlat_src_address
14581479
name: Xlat source address
14591480
component: text
14601481
category: source
14611482
hint: Specify a single IP or range.
1483+
feature: packetTranslation
14621484
- id: xlat_dst_address
14631485
name: Xlat destination address
14641486
component: text
14651487
category: destination
14661488
hint: Specify a single IP or range.
1489+
feature: packetTranslation
14671490
- id: xlat_src_port
14681491
name: Xlat source port
14691492
component: autocomplete
14701493
category: source
14711494
hint: Specify a single port number or name.
1495+
feature: packetTranslation
14721496
- id: xlat_dst_port
14731497
name: Xlat destination port
14741498
component: autocomplete
14751499
category: destination
14761500
hint: Specify a single port number or name.
1501+
feature: packetTranslation
14771502
- id: ipsec_status
14781503
name: IPsec Status
14791504
component: text
14801505
placeholder: 'E.g: success, error'
14811506
hint: Status of the IPsec encryption (on egress, provided by the kernel function xfrm_output) or decryption (on ingress, via xfrm_input).
1507+
feature: ipsec
14821508
scopes:
14831509
- id: cluster
14841510
name: Cluster

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type Filter struct {
9797
Examples string `yaml:"examples,omitempty" json:"examples,omitempty"`
9898
DocURL string `yaml:"docUrl,omitempty" json:"docUrl,omitempty"`
9999
Placeholder string `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
100+
Feature string `yaml:"feature,omitempty" json:"feature,omitempty"`
100101
}
101102

102103
type Scope struct {

web/src/components/__tests-data__/filters.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable max-len */
2-
import { Filter, FilterCompare, FilterId, FilterValue } from '../../model/filters';
2+
import { Filter, FilterCompare, FilterConfigDef, FilterId, FilterValue } from '../../model/filters';
33
import { findFilter, getFilterDefinitions } from '../../utils/filter-definitions';
44
import { ColumnConfigSampleDefs } from './columns';
55

6-
export const FilterConfigSampleDefs = [
6+
export const FilterConfigSampleDefs: FilterConfigDef[] = [
77
{
88
id: 'namespace',
99
name: 'Namespace',
@@ -275,19 +275,22 @@ export const FilterConfigSampleDefs = [
275275
id: 'zone',
276276
name: 'Zone',
277277
component: 'autocomplete',
278-
category: 'endpoint'
278+
category: 'endpoint',
279+
feature: 'zones'
279280
},
280281
{
281282
id: 'src_zone',
282283
name: 'Zone',
283284
component: 'autocomplete',
284-
category: 'source'
285+
category: 'source',
286+
feature: 'zones'
285287
},
286288
{
287289
id: 'dst_zone',
288290
name: 'Zone',
289291
component: 'autocomplete',
290-
category: 'destination'
292+
category: 'destination',
293+
feature: 'zones'
291294
},
292295
{
293296
id: 'protocol',
@@ -344,19 +347,22 @@ export const FilterConfigSampleDefs = [
344347
id: 'dns_id',
345348
name: 'DNS Id',
346349
component: 'number',
347-
hint: 'Specify a single DNS Id.'
350+
hint: 'Specify a single DNS Id.',
351+
feature: 'dnsTracking'
348352
},
349353
{
350354
id: 'dns_name',
351355
name: 'DNS Name',
352356
component: 'text',
353-
hint: 'Specify a single DNS Name.'
357+
hint: 'Specify a single DNS Name.',
358+
feature: 'dnsTracking'
354359
},
355360
{
356361
id: 'dns_latency',
357362
name: 'DNS Latency',
358363
component: 'number',
359-
hint: 'Specify a DNS Latency in miliseconds.'
364+
hint: 'Specify a DNS Latency in miliseconds.',
365+
feature: 'dnsTracking'
360366
},
361367
{
362368
id: 'dns_flag_response_code',
@@ -365,7 +371,8 @@ export const FilterConfigSampleDefs = [
365371
hint: 'Specify a single DNS RCODE name.',
366372
examples:
367373
'Specify a single DNS RCODE name like:\n - A IANA RCODE number like 0, 3, 9\n - A IANA RCODE name like NoError, NXDomain, NotAuth',
368-
docUrl: 'https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6'
374+
docUrl: 'https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6',
375+
feature: 'dnsTracking'
369376
},
370377
{
371378
id: 'time_flow_rtt',

web/src/model/filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22
import { TFunction } from 'react-i18next';
33
import { isEqual } from '../utils/base-compare';
44
import { undefinedValue } from '../utils/filter-definitions';
5+
import { Feature } from './config';
56
import { Match } from './flow-query';
67

78
export type FiltersEncoder = (values: FilterValue[], compare: FilterCompare, matchAny: boolean) => string;
@@ -88,6 +89,7 @@ export interface FilterConfigDef {
8889
examples?: string;
8990
docUrl?: string;
9091
placeholder?: string;
92+
feature?: Feature;
9193
}
9294

9395
export interface FilterDefinition {

web/src/utils/__tests__/filter-definitions.spec.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ColumnConfigSampleDefs } from '../../components/__tests-data__/columns';
2-
import { FilterDefinitionSample } from '../../components/__tests-data__/filters';
2+
import { FilterConfigSampleDefs, FilterDefinitionSample } from '../../components/__tests-data__/filters';
33
import { Config, Feature } from '../../model/config';
44
import { checkFilterAvailable, findFilter } from '../filter-definitions';
55

@@ -142,7 +142,12 @@ describe('Check availability for prometheus only', () => {
142142

143143
describe('Check availability against features', () => {
144144
const getConfig = (feats: Feature[]): Config => {
145-
return { features: feats, dataSources: ['loki'], columns: ColumnConfigSampleDefs } as Config;
145+
return {
146+
features: feats,
147+
dataSources: ['loki'],
148+
columns: ColumnConfigSampleDefs,
149+
filters: FilterConfigSampleDefs
150+
} as Config;
146151
};
147152

148153
it('with standard filters', () => {
@@ -163,15 +168,25 @@ describe('Check availability against features', () => {
163168
});
164169

165170
it('with AZ filters', () => {
166-
const azFilter = findFilter(FilterDefinitionSample, 'src_zone')!;
171+
const srcZoneFilter = findFilter(FilterDefinitionSample, 'src_zone')!;
172+
const zoneFilter = findFilter(FilterDefinitionSample, 'zone')!;
167173

168-
let available = checkFilterAvailable(azFilter, getConfig([]), 'auto');
174+
// Test that zone filters are unavailable without zones feature
175+
let available = checkFilterAvailable(srcZoneFilter, getConfig([]), 'auto');
176+
expect(available).toBe(false);
177+
available = checkFilterAvailable(zoneFilter, getConfig([]), 'auto');
169178
expect(available).toBe(false);
170179

171-
available = checkFilterAvailable(azFilter, getConfig(['dnsTracking']), 'auto');
180+
// Test that zone filters are unavailable with other features
181+
available = checkFilterAvailable(srcZoneFilter, getConfig(['dnsTracking']), 'auto');
182+
expect(available).toBe(false);
183+
available = checkFilterAvailable(zoneFilter, getConfig(['dnsTracking']), 'auto');
172184
expect(available).toBe(false);
173185

174-
available = checkFilterAvailable(azFilter, getConfig(['zones']), 'auto');
186+
// Test that zone filters are available with zones feature
187+
available = checkFilterAvailable(srcZoneFilter, getConfig(['zones']), 'auto');
188+
expect(available).toBe(true);
189+
available = checkFilterAvailable(zoneFilter, getConfig(['zones']), 'auto');
175190
expect(available).toBe(true);
176191
});
177192

web/src/utils/filter-definitions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ export const checkFilterAvailable = (fd: FilterDefinition, config: Config, dataS
368368
}
369369

370370
// Check against enabled features
371+
const filterConfig = config.filters.find(f => f.id === fd.id);
372+
if (filterConfig?.feature) {
373+
return config.features.includes(filterConfig.feature);
374+
}
375+
371376
const colConfig = config.columns.find(c => c.filter === fd.id);
372377
if (colConfig?.feature) {
373378
return config.features.includes(colConfig?.feature);

0 commit comments

Comments
 (0)