| 
2 | 2 | import { TFunction } from 'i18next';  | 
3 | 3 | import { RecordType } from '../model/flow-query';  | 
4 | 4 | 
 
  | 
5 |  | -// Please keep this file documented: it is used in doc generation  | 
6 |  | -// To regenerate doc, run `make generate-doc` - and also check this page:  | 
7 |  | -// https://github.com/netobserv/network-observability-operator/blob/main/docs/GeneratingAsciidocAPI.md#generate-asciidoc-for-flows-json-format-reference  | 
8 |  | - | 
9 | 5 | export interface Record {  | 
10 |  | -  labels: Labels;  | 
 | 6 | +  labels: Flow;  | 
11 | 7 |   key: number;  | 
12 |  | -  fields: Fields;  | 
 | 8 | +  fields: Flow;  | 
13 | 9 | }  | 
14 | 10 | 
 
  | 
15 |  | -export const getRecordValue = (record: Record, fieldOrLabel: string, defaultValue?: string | number) => {  | 
 | 11 | +export const getRecordValue = (record: Record, field: Field, defaultValue?: string | number) => {  | 
16 | 12 |   /* TODO: fix following behavior:  | 
17 | 13 |    * Check if field exists first since /flow endpoint return fields as labels when using filters  | 
18 | 14 |    * This is mandatory to ensure fields types  | 
19 | 15 |    */  | 
20 |  | -  if (record.fields[fieldOrLabel as keyof Fields] !== undefined) {  | 
21 |  | -    return record.fields[fieldOrLabel as keyof Fields];  | 
 | 16 | +  if (record.fields[field] !== undefined) {  | 
 | 17 | +    return record.fields[field];  | 
22 | 18 |   }  | 
23 | 19 |   // check if label exists  | 
24 |  | -  if (record.labels[fieldOrLabel as keyof Labels] !== undefined) {  | 
25 |  | -    return record.labels[fieldOrLabel as keyof Labels];  | 
 | 20 | +  if (record.labels[field] !== undefined) {  | 
 | 21 | +    return record.labels[field];  | 
26 | 22 |   }  | 
27 | 23 |   // fallback on default  | 
28 | 24 |   return defaultValue;  | 
29 | 25 | };  | 
30 | 26 | 
 
  | 
31 |  | -export interface Labels {  | 
32 |  | -  /** Source namespace */  | 
 | 27 | +export type Field = keyof Flow;  | 
 | 28 | + | 
 | 29 | +export interface Flow {  | 
33 | 30 |   SrcK8S_Namespace?: string;  | 
34 |  | -  /** Destination namespace */  | 
35 | 31 |   DstK8S_Namespace?: string;  | 
36 |  | -  /** Source owner, such as Deployment, StatefulSet, etc. */  | 
37 |  | -  SrcK8S_OwnerName?: string;  | 
38 |  | -  /** Destination owner, such as Deployment, StatefulSet, etc. */  | 
39 |  | -  DstK8S_OwnerName?: string;  | 
40 |  | -  /** Kind of the source matched Kubernetes object, such as Pod, Service, etc. */  | 
41 | 32 |   SrcK8S_Type?: string;  | 
42 |  | -  /** Kind of the destination matched Kubernetes object, such as Pod name, Service name, etc. */  | 
43 | 33 |   DstK8S_Type?: string;  | 
44 |  | -  /** Flow direction from the node observation point*/  | 
45 | 34 |   FlowDirection?: FlowDirection;  | 
46 |  | -  /** Type of record: 'flowLog' for regular flow logs, or 'allConnections',  | 
47 |  | -   * 'newConnection', 'heartbeat', 'endConnection' for conversation tracking */  | 
48 | 35 |   _RecordType?: RecordType;  | 
49 |  | -}  | 
50 |  | - | 
51 |  | -export enum FlowDirection {  | 
52 |  | -  /** Incoming traffic, from the node observation point */  | 
53 |  | -  Ingress = '0',  | 
54 |  | -  /** Outgoing traffic, from the node observation point */  | 
55 |  | -  Egress = '1',  | 
56 |  | -  /** Inner traffic, with the same source and destination node */  | 
57 |  | -  Inner = '2',  | 
58 |  | -  /** Both traffic (for Interface direction only), flow seen on both Ingress and Egress */  | 
59 |  | -  Both = '3'  | 
60 |  | -}  | 
61 |  | - | 
62 |  | -export const getDirectionDisplayString = (value: FlowDirection, t: TFunction) => {  | 
63 |  | -  return value === FlowDirection.Ingress  | 
64 |  | -    ? t('Ingress')  | 
65 |  | -    : value === FlowDirection.Egress  | 
66 |  | -    ? t('Egress')  | 
67 |  | -    : value === FlowDirection.Inner  | 
68 |  | -    ? t('Inner')  | 
69 |  | -    : value === FlowDirection.Both  | 
70 |  | -    ? t('Both')  | 
71 |  | -    : t('n/a');  | 
72 |  | -};  | 
73 |  | - | 
74 |  | -export enum IfDirection {  | 
75 |  | -  /** Incoming traffic, from the network interface observation point */  | 
76 |  | -  Ingress = '0',  | 
77 |  | -  /** Outgoing traffic, from the network interface observation point */  | 
78 |  | -  Egress = '1'  | 
79 |  | -}  | 
80 |  | - | 
81 |  | -export interface Fields {  | 
82 |  | -  /** Source IP address (ipv4 or ipv6) */  | 
83 | 36 |   SrcAddr?: string;  | 
84 |  | -  /** Destination IP address (ipv4 or ipv6) */  | 
85 | 37 |   DstAddr?: string;  | 
86 |  | -  /** Source MAC address */  | 
87 | 38 |   SrcMac?: string;  | 
88 |  | -  /** Destination MAC address */  | 
89 | 39 |   DstMac?: string;  | 
90 |  | -  /** Name of the source matched Kubernetes object, such as Pod name, Service name, etc. */  | 
91 | 40 |   SrcK8S_Name?: string;  | 
92 |  | -  /** Name of the destination matched Kubernetes object, such as Pod name, Service name, etc. */  | 
93 | 41 |   DstK8S_Name?: string;  | 
94 |  | -  /** Source port */  | 
95 | 42 |   SrcPort?: number;  | 
96 |  | -  /** Destination port */  | 
97 | 43 |   DstPort?: number;  | 
98 |  | -  /** Kind of the source Kubernetes owner, such as Deployment, StatefulSet, etc. */  | 
 | 44 | +  SrcK8S_OwnerName?: string;  | 
 | 45 | +  DstK8S_OwnerName?: string;  | 
99 | 46 |   SrcK8S_OwnerType?: string;  | 
100 |  | -  /** Kind of the destination Kubernetes owner, such as Deployment, StatefulSet, etc. */  | 
101 | 47 |   DstK8S_OwnerType?: string;  | 
102 |  | -  /** Source node IP */  | 
103 | 48 |   SrcK8S_HostIP?: string;  | 
104 |  | -  /** Destination node IP */  | 
105 | 49 |   DstK8S_HostIP?: string;  | 
106 |  | -  /** Source node name */  | 
107 | 50 |   SrcK8S_HostName?: string;  | 
108 |  | -  /** Destination node name */  | 
109 | 51 |   DstK8S_HostName?: string;  | 
110 |  | -  /** Source zone */  | 
111 | 52 |   SrcK8S_Zone?: string;  | 
112 |  | -  /** Destination zone */  | 
113 | 53 |   DstK8S_Zone?: string;  | 
114 |  | -  /** Source network name (e.g. secondary networks or UDN) */  | 
115 | 54 |   SrcK8S_NetworkName?: string;  | 
116 |  | -  /** Destination network name (e.g. secondary networks or UDN) */  | 
117 | 55 |   DstK8S_NetworkName?: string;  | 
118 |  | -  /** Cluster name */  | 
119 | 56 |   K8S_ClusterName?: string;  | 
120 |  | -  /** L4 protocol */  | 
121 | 57 |   Proto?: number;  | 
122 |  | -  /** Network interface array */  | 
123 | 58 |   Interfaces?: string[];  | 
124 |  | -  /** Flow direction array from the network interface observation point */  | 
125 | 59 |   IfDirections?: IfDirection[];  | 
126 |  | -  /** UDNs labels array */  | 
127 | 60 |   Udns?: string[];  | 
128 |  | -  /** Network Events */  | 
129 | 61 |   NetworkEvents?: string[];  | 
130 |  | -  /** Logical OR combination of unique TCP flags comprised in the flow, as per RFC-9293, with additional custom flags to represent the following per-packet combinations: SYN+ACK (0x100), FIN+ACK (0x200) and RST+ACK (0x400). */  | 
131 | 62 |   Flags?: string[];  | 
132 |  | -  /** Number of packets */  | 
133 | 63 |   Packets?: number;  | 
134 |  | -  /** In conversation tracking, A to B packets counter per conversation */  | 
135 | 64 |   Packets_AB?: number;  | 
136 |  | -  /** In conversation tracking, B to A packets counter per conversation */  | 
137 | 65 |   Packets_BA?: number;  | 
138 |  | -  /** Number of bytes */  | 
139 | 66 |   Bytes?: number;  | 
140 |  | -  /** In conversation tracking, A to B bytes counter per conversation */  | 
141 | 67 |   Bytes_AB?: number;  | 
142 |  | -  /** In conversation tracking, B to A bytes counter per conversation */  | 
143 | 68 |   Bytes_BA?: number;  | 
144 |  | -  /** Differentiated Services Code Point Value  */  | 
145 | 69 |   Dscp?: number;  | 
146 |  | -  /** ICMP type */  | 
147 | 70 |   IcmpType?: number;  | 
148 |  | -  /** ICMP code */  | 
149 | 71 |   IcmpCode?: number;  | 
150 |  | -  /** Pkt TCP state for drops */  | 
151 | 72 |   PktDropLatestState?: string;  | 
152 |  | -  /** Pkt cause for drops */  | 
153 | 73 |   PktDropLatestDropCause?: string;  | 
154 |  | -  /** Pkt TCP flags for drops */  | 
155 | 74 |   PktDropLatestFlags?: number;  | 
156 |  | -  /** Number of packets dropped by the kernel */  | 
157 | 75 |   PktDropPackets?: number;  | 
158 |  | -  /** In conversation tracking, A to B packets dropped counter per conversation */  | 
159 | 76 |   PktDropPackets_AB?: number;  | 
160 |  | -  /** In conversation tracking, B to A packets dropped counter per conversation */  | 
161 | 77 |   PktDropPackets_BA?: number;  | 
162 |  | -  /** Number of bytes dropped by the kernel */  | 
163 | 78 |   PktDropBytes?: number;  | 
164 |  | -  /** In conversation tracking, A to B bytes dropped counter per conversation */  | 
165 | 79 |   PktDropBytes_AB?: number;  | 
166 |  | -  /** In conversation tracking, B to A bytes dropped counter per conversation */  | 
167 | 80 |   PktDropBytes_BA?: number;  | 
168 |  | -  /** DNS record id */  | 
169 | 81 |   DnsId?: number;  | 
170 |  | -  /** DNS flags for DNS record */  | 
171 | 82 |   DnsFlags?: number;  | 
172 |  | -  /** Parsed DNS header RCODEs name */  | 
173 | 83 |   DnsFlagsResponseCode?: string;  | 
174 |  | -  /** Calculated time between response and request, in milliseconds */  | 
175 | 84 |   DnsLatencyMs?: number;  | 
176 |  | -  /** Error number returned from DNS tracker ebpf hook function */  | 
177 | 85 |   DnsErrno?: number;  | 
178 |  | -  /** Start timestamp of this flow, in milliseconds */  | 
179 | 86 |   TimeFlowStartMs?: number;  | 
180 |  | -  /** End timestamp of this flow, in milliseconds */  | 
181 | 87 |   TimeFlowEndMs?: number;  | 
182 |  | -  /** Timestamp when this flow was received and processed by the flow collector, in seconds */  | 
183 | 88 |   TimeReceived?: number;  | 
184 |  | -  /** TCP smoothed Round Trip Time (sRTT) in nanoseconds */  | 
185 | 89 |   TimeFlowRttNs?: number;  | 
186 |  | -  /** In conversation tracking, the conversation identifier */  | 
187 | 90 |   _HashId?: string;  | 
188 |  | -  /** In conversation tracking, a flag identifying the first flow */  | 
189 | 91 |   _IsFirst?: string;  | 
190 |  | -  /** In conversation tracking, a counter of flow logs per conversation */  | 
191 | 92 |   numFlowLogs?: number;  | 
192 |  | -  /** User Defined Network identifier */  | 
193 | 93 |   UdnId?: string;  | 
194 | 94 | }  | 
195 | 95 | 
 
  | 
196 |  | -export type Field = keyof Fields | keyof Labels;  | 
 | 96 | +export enum FlowDirection {  | 
 | 97 | +  Ingress = '0',  | 
 | 98 | +  Egress = '1',  | 
 | 99 | +  Inner = '2',  | 
 | 100 | +  Both = '3'  | 
 | 101 | +}  | 
 | 102 | + | 
 | 103 | +export const getDirectionDisplayString = (value: FlowDirection, t: TFunction) => {  | 
 | 104 | +  return value === FlowDirection.Ingress  | 
 | 105 | +    ? t('Ingress')  | 
 | 106 | +    : value === FlowDirection.Egress  | 
 | 107 | +    ? t('Egress')  | 
 | 108 | +    : value === FlowDirection.Inner  | 
 | 109 | +    ? t('Inner')  | 
 | 110 | +    : value === FlowDirection.Both  | 
 | 111 | +    ? t('Both')  | 
 | 112 | +    : t('n/a');  | 
 | 113 | +};  | 
 | 114 | + | 
 | 115 | +export enum IfDirection {  | 
 | 116 | +  Ingress = '0',  | 
 | 117 | +  Egress = '1'  | 
 | 118 | +}  | 
0 commit comments