diff --git a/config/sample-config.yaml b/config/sample-config.yaml index b455e178d..33d619cf5 100644 --- a/config/sample-config.yaml +++ b/config/sample-config.yaml @@ -23,7 +23,7 @@ prometheus: url: https://localhost:9090 timeout: 30s skipTls: true - tokenPath: /tmp/oc-token.txt + # tokenPath: /tmp/oc-token.txt alertManager: # url: https://localhost:9094 metrics: @@ -944,6 +944,7 @@ frontend: name: Cluster component: autocomplete hint: Specify a cluster ID or name. + feature: multiCluster - id: namespace name: Namespace component: autocomplete @@ -1105,31 +1106,37 @@ frontend: component: autocomplete category: endpoint hint: Specify a single zone. + feature: zones - id: src_zone name: Zone component: autocomplete category: source hint: Specify a single zone. + feature: zones - id: dst_zone name: Zone component: autocomplete category: destination hint: Specify a single zone. + feature: zones - id: subnet_label name: Subnet Label component: autocomplete category: endpoint hint: Specify a subnet label, or an empty string to get unmatched sources. + feature: subnetLabels - id: src_subnet_label name: Subnet Label component: autocomplete category: source hint: Specify a subnet label, or an empty string to get unmatched sources. + feature: subnetLabels - id: dst_subnet_label name: Subnet Label component: autocomplete category: destination hint: Specify a subnet label, or an empty string to get unmatched destinations. + feature: subnetLabels - id: resource name: Resource component: autocomplete @@ -1329,14 +1336,17 @@ frontend: name: Network Name component: text category: endpoint + feature: multiNetworks - id: src_network name: Network Name component: text category: source + feature: multiNetworks - id: dst_network name: Network Name component: text category: destination + feature: multiNetworks - id: protocol name: Protocol component: autocomplete @@ -1393,6 +1403,7 @@ frontend: name: User Defined Network component: autocomplete hint: Specify a user defined network name. + feature: udnMapping - id: id name: Conversation Id component: text @@ -1407,6 +1418,7 @@ frontend: - A _LINUX_TCP_STATES_H number like 1, 2, 3 - A _LINUX_TCP_STATES_H TCP name like ESTABLISHED, SYN_SENT, SYN_RECV docUrl: https://github.com/torvalds/linux/blob/master/include/net/tcp_states.h + feature: pktDrop - id: pkt_drop_cause name: Packet drop latest cause component: autocomplete @@ -1417,18 +1429,22 @@ frontend: - A _LINUX_DROPREASON_CORE_H number like 2, 3, 4 - A _LINUX_DROPREASON_CORE_H SKB_DROP_REASON name like NOT_SPECIFIED, NO_SOCKET, PKT_TOO_SMALL docUrl: https://github.com/torvalds/linux/blob/master/include/net/dropreason-core.h + feature: pktDrop - id: dns_id name: DNS Id component: number hint: Specify a single DNS Id. + feature: dnsTracking - id: dns_name name: DNS Name component: text hint: Specify a single DNS name. + feature: dnsTracking - id: dns_latency name: DNS Latency component: number hint: Specify a DNS Latency in miliseconds. + feature: dnsTracking - id: dns_flag_response_code name: DNS Response Code component: autocomplete @@ -1439,46 +1455,56 @@ frontend: - A IANA RCODE number like 0, 3, 9 - A IANA RCODE name like NoError, NXDomain, NotAuth docUrl: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 + feature: dnsTracking - id: dns_errno name: DNS Error component: autocomplete hint: Specify a single DNS error number. + feature: dnsTracking - id: time_flow_rtt name: Flow RTT component: number hint: Specify a TCP smoothed Round Trip Time in nanoseconds. + feature: flowRTT - id: network_events name: Network Events component: text hint: Specify a single network event. + feature: networkEvents - id: xlat_zone_id name: Xlat Zone Id component: number + feature: packetTranslation - id: xlat_src_address name: Xlat source address component: text category: source hint: Specify a single IP or range. + feature: packetTranslation - id: xlat_dst_address name: Xlat destination address component: text category: destination hint: Specify a single IP or range. + feature: packetTranslation - id: xlat_src_port name: Xlat source port component: autocomplete category: source hint: Specify a single port number or name. + feature: packetTranslation - id: xlat_dst_port name: Xlat destination port component: autocomplete category: destination hint: Specify a single port number or name. + feature: packetTranslation - id: ipsec_status name: IPsec Status component: text placeholder: 'E.g: success, error' hint: Status of the IPsec encryption (on egress, provided by the kernel function xfrm_output) or decryption (on ingress, via xfrm_input). + feature: ipsec scopes: - id: cluster name: Cluster diff --git a/pkg/config/config.go b/pkg/config/config.go index ec11243b7..f8c0a2db4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -97,6 +97,7 @@ type Filter struct { Examples string `yaml:"examples,omitempty" json:"examples,omitempty"` DocURL string `yaml:"docUrl,omitempty" json:"docUrl,omitempty"` Placeholder string `yaml:"placeholder,omitempty" json:"placeholder,omitempty"` + Feature string `yaml:"feature,omitempty" json:"feature,omitempty"` } type Scope struct { diff --git a/web/src/components/__tests-data__/filters.ts b/web/src/components/__tests-data__/filters.ts index 7b7eb5a72..4125373e9 100644 --- a/web/src/components/__tests-data__/filters.ts +++ b/web/src/components/__tests-data__/filters.ts @@ -1,9 +1,9 @@ /* eslint-disable max-len */ -import { Filter, FilterCompare, FilterId, FilterValue } from '../../model/filters'; +import { Filter, FilterCompare, FilterConfigDef, FilterId, FilterValue } from '../../model/filters'; import { findFilter, getFilterDefinitions } from '../../utils/filter-definitions'; import { ColumnConfigSampleDefs } from './columns'; -export const FilterConfigSampleDefs = [ +export const FilterConfigSampleDefs: FilterConfigDef[] = [ { id: 'namespace', name: 'Namespace', @@ -275,19 +275,22 @@ export const FilterConfigSampleDefs = [ id: 'zone', name: 'Zone', component: 'autocomplete', - category: 'endpoint' + category: 'endpoint', + feature: 'zones' }, { id: 'src_zone', name: 'Zone', component: 'autocomplete', - category: 'source' + category: 'source', + feature: 'zones' }, { id: 'dst_zone', name: 'Zone', component: 'autocomplete', - category: 'destination' + category: 'destination', + feature: 'zones' }, { id: 'protocol', @@ -344,19 +347,22 @@ export const FilterConfigSampleDefs = [ id: 'dns_id', name: 'DNS Id', component: 'number', - hint: 'Specify a single DNS Id.' + hint: 'Specify a single DNS Id.', + feature: 'dnsTracking' }, { id: 'dns_name', name: 'DNS Name', component: 'text', - hint: 'Specify a single DNS Name.' + hint: 'Specify a single DNS Name.', + feature: 'dnsTracking' }, { id: 'dns_latency', name: 'DNS Latency', component: 'number', - hint: 'Specify a DNS Latency in miliseconds.' + hint: 'Specify a DNS Latency in miliseconds.', + feature: 'dnsTracking' }, { id: 'dns_flag_response_code', @@ -365,7 +371,8 @@ export const FilterConfigSampleDefs = [ hint: 'Specify a single DNS RCODE name.', examples: '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', - docUrl: 'https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6' + docUrl: 'https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6', + feature: 'dnsTracking' }, { id: 'time_flow_rtt', diff --git a/web/src/model/filters.ts b/web/src/model/filters.ts index 31fff7229..e69868b7e 100644 --- a/web/src/model/filters.ts +++ b/web/src/model/filters.ts @@ -2,6 +2,7 @@ import _ from 'lodash'; import { TFunction } from 'react-i18next'; import { isEqual } from '../utils/base-compare'; import { undefinedValue } from '../utils/filter-definitions'; +import { Feature } from './config'; import { Match } from './flow-query'; export type FiltersEncoder = (values: FilterValue[], compare: FilterCompare, matchAny: boolean) => string; @@ -88,6 +89,7 @@ export interface FilterConfigDef { examples?: string; docUrl?: string; placeholder?: string; + feature?: Feature; } export interface FilterDefinition { diff --git a/web/src/utils/__tests__/filter-definitions.spec.ts b/web/src/utils/__tests__/filter-definitions.spec.ts index 2c4b70a9a..f290c71f8 100644 --- a/web/src/utils/__tests__/filter-definitions.spec.ts +++ b/web/src/utils/__tests__/filter-definitions.spec.ts @@ -1,5 +1,5 @@ import { ColumnConfigSampleDefs } from '../../components/__tests-data__/columns'; -import { FilterDefinitionSample } from '../../components/__tests-data__/filters'; +import { FilterConfigSampleDefs, FilterDefinitionSample } from '../../components/__tests-data__/filters'; import { Config, Feature } from '../../model/config'; import { checkFilterAvailable, findFilter } from '../filter-definitions'; @@ -142,7 +142,12 @@ describe('Check availability for prometheus only', () => { describe('Check availability against features', () => { const getConfig = (feats: Feature[]): Config => { - return { features: feats, dataSources: ['loki'], columns: ColumnConfigSampleDefs } as Config; + return { + features: feats, + dataSources: ['loki'], + columns: ColumnConfigSampleDefs, + filters: FilterConfigSampleDefs + } as Config; }; it('with standard filters', () => { @@ -163,15 +168,25 @@ describe('Check availability against features', () => { }); it('with AZ filters', () => { - const azFilter = findFilter(FilterDefinitionSample, 'src_zone')!; + const srcZoneFilter = findFilter(FilterDefinitionSample, 'src_zone')!; + const zoneFilter = findFilter(FilterDefinitionSample, 'zone')!; - let available = checkFilterAvailable(azFilter, getConfig([]), 'auto'); + // Test that zone filters are unavailable without zones feature + let available = checkFilterAvailable(srcZoneFilter, getConfig([]), 'auto'); + expect(available).toBe(false); + available = checkFilterAvailable(zoneFilter, getConfig([]), 'auto'); expect(available).toBe(false); - available = checkFilterAvailable(azFilter, getConfig(['dnsTracking']), 'auto'); + // Test that zone filters are unavailable with other features + available = checkFilterAvailable(srcZoneFilter, getConfig(['dnsTracking']), 'auto'); + expect(available).toBe(false); + available = checkFilterAvailable(zoneFilter, getConfig(['dnsTracking']), 'auto'); expect(available).toBe(false); - available = checkFilterAvailable(azFilter, getConfig(['zones']), 'auto'); + // Test that zone filters are available with zones feature + available = checkFilterAvailable(srcZoneFilter, getConfig(['zones']), 'auto'); + expect(available).toBe(true); + available = checkFilterAvailable(zoneFilter, getConfig(['zones']), 'auto'); expect(available).toBe(true); }); diff --git a/web/src/utils/filter-definitions.ts b/web/src/utils/filter-definitions.ts index c84bbc6e1..f47347199 100644 --- a/web/src/utils/filter-definitions.ts +++ b/web/src/utils/filter-definitions.ts @@ -368,6 +368,11 @@ export const checkFilterAvailable = (fd: FilterDefinition, config: Config, dataS } // Check against enabled features + const filterConfig = config.filters.find(f => f.id === fd.id); + if (filterConfig?.feature) { + return config.features.includes(filterConfig.feature); + } + const colConfig = config.columns.find(c => c.filter === fd.id); if (colConfig?.feature) { return config.features.includes(colConfig?.feature);