Skip to content

Commit ada5811

Browse files
authored
Merge pull request #52 from eranra/conn_tracing
add support for connection tracking
2 parents d7ca83d + d462138 commit ada5811

19 files changed

+398
-58
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ clean: ## Clean
8181
# note: to review coverage execute: go tool cover -html=/tmp/coverage.out
8282
.PHONY: test
8383
test: validate_go ## Test
84-
go test -race -covermode=atomic -coverprofile=/tmp/coverage.out ./...
84+
go test -p 1 -race -covermode=atomic -coverprofile=/tmp/coverage.out ./...
8585

8686
# note: to review profile execute: go tool pprof -web /tmp/flowlogs2metrics-cpu-profile.out (make sure graphviz is installed)
8787
.PHONY: benchmarks

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ pipeline:
275275
output: match-10.0
276276
type: add_regex_if
277277
parameters: 10.0.*
278+
- input: "{{.srcIP}},{{.srcPort}},{{.dstIP}},{{.dstPort}},{{.protocol}}"
279+
output: isNewFlow
280+
type: conn_tracking
281+
parameters: "1"
278282
```
279283

280284
The first rule `add_subnet` generates a new field named `srcSubnet` with the
@@ -306,11 +310,15 @@ All the kubernetes fields will be named by appending `output` value
306310
> 2. using `KUBECONFIG` environment variable
307311
> 3. using local `~/.kube/config`
308312

309-
The sixth `add_regex_if` generates a new field named `match-10.0` that contains
310-
the contents of the `srcSubnet` field for entries that match regex expression specified
313+
The sixth rule `add_regex_if` generates a new field named `match-10.0` that contains
314+
the contents of the `srcSubnet` field for entries that match regex expression specified
311315
in the `parameters` variable. In addition, the field `match-10.0_Matched` with
312316
value `true` is added to all matched entries
313317

318+
The seventh rule `conn_tracking` generates a new field named `isNewFlow` that contains
319+
the contents of the `parameters` variable **only for new entries** (first seen in 120 seconds)
320+
that match hash of template fields from the `input` variable.
321+
314322

315323
> Note: above example describes all available transform network `Type` options
316324
> Note: above transform is essential for the `aggregation` phase

contrib/kubernetes/flowlogs2metrics.conf.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pipeline:
135135
- name: dest_connection_subnet_count
136136
by:
137137
- dstSubnet
138-
operation: count
138+
operation: sum
139139
recordkey: ""
140140
- name: src_connection_count
141141
by:
@@ -203,16 +203,18 @@ pipeline:
203203
transform:
204204
- generic:
205205
rules:
206-
- input: DstAddr
207-
output: dstIP
208206
- input: SrcAddr
209207
output: srcIP
210-
- input: Bytes
211-
output: bytes
208+
- input: SrcPort
209+
output: srcPort
210+
- input: DstAddr
211+
output: dstIP
212212
- input: DstPort
213213
output: dstPort
214214
- input: Proto
215215
output: proto
216+
- input: Bytes
217+
output: bytes
216218
- input: TCPFlags
217219
output: TCPFlags
218220
- input: SrcAS
@@ -238,6 +240,10 @@ pipeline:
238240
output: srcSubnet
239241
type: add_subnet
240242
parameters: /16
243+
- input: '{{.srcIP}},{{.srcPort}},{{.dstIP}},{{.dstPort}},{{.proto}}'
244+
output: isNewFlow
245+
type: conn_tracking
246+
parameters: "1"
241247
- input: dstIP
242248
output: dstSubnet
243249
type: add_subnet

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Following is the supported API format for network transformations:
5050
input: entry input field
5151
output: entry output field
5252
type: (enum) one of the following:
53+
conn_tracking: set output field to value of parameters field only for new flows by matching template in input field
5354
add_regex_if: add output field if input field satisfies regex pattern from parameters field
5455
add_if: add output field if input field satisfies criteria from parameters field
5556
add_subnet: add output subnet field from input field and prefix length from parameters field

docs/metrics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ and the transformation to generate the exported metric.
5151
### connection rate per dest subnet
5252
| **Description** | This metric observes network connections rate per destination subnet |
5353
|:---|:---|
54-
| **Details** | Counts the number of connections per subnet with network prefix length /16 |
54+
| **Details** | Counts the number of connections per subnet with network prefix length /16 (using conn_tracking sum isNewFlow field) |
5555
| **Usage** | Evaluate network connections per subnet |
5656
| **Labels** | rate, subnet |
57-
| **Operation** | aggregate by `dstSubnet` and `count` |
57+
| **Operation** | aggregate by `dstSubnet` and `sum` |
5858
| **Exposed as** | `fl2m_connections_per_destination_subnet` of type `gauge` |
5959
| **Visualized as** | "Connections rate per destinationIP /16 subnets" on dashboard `details` |
6060
|||

network_definitions/bandwidth_per_network_service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extract:
2222
by:
2323
- service
2424
operation: sum
25-
RecordKey: bytes
25+
recordKey: bytes
2626
encode:
2727
type: prom
2828
prom:

network_definitions/bandwidth_per_src_dest_subnet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extract:
2727
- dstSubnet24
2828
- srcSubnet24
2929
operation: sum
30-
RecordKey: bytes
30+
recordKey: bytes
3131
encode:
3232
type: prom
3333
prom:

network_definitions/bandwidth_per_src_subnet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extract:
2222
by:
2323
- srcSubnet
2424
operation: sum
25-
RecordKey: bytes
25+
recordKey: bytes
2626
encode:
2727
type: prom
2828
prom:

network_definitions/config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ ingest:
1010
transform:
1111
generic:
1212
rules:
13-
- input: DstAddr
14-
output: dstIP
1513
- input: SrcAddr
1614
output: srcIP
17-
- input: Bytes
18-
output: bytes
15+
- input: SrcPort
16+
output: srcPort
17+
- input: DstAddr
18+
output: dstIP
1919
- input: DstPort
2020
output: dstPort
2121
- input: Proto
2222
output: proto
23+
- input: Bytes
24+
output: bytes
2325
- input: TCPFlags
2426
output: TCPFlags
2527
- input: SrcAS

network_definitions/connection_rate_per_dest_subnet.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
description:
33
This metric observes network connections rate per destination subnet
44
details:
5-
Counts the number of connections per subnet with network prefix length /16
5+
Counts the number of connections per subnet with network prefix length /16 (using conn_tracking sum isNewFlow field)
66
usage:
77
Evaluate network connections per subnet
88
labels:
99
- rate
1010
- subnet
1111
transform:
1212
rules:
13+
- input: "{{.srcIP}},{{.srcPort}},{{.dstIP}},{{.dstPort}},{{.proto}}"
14+
output: isNewFlow
15+
type: conn_tracking
16+
parameters: "1"
1317
- input: dstIP
1418
output: dstSubnet
1519
type: add_subnet
@@ -20,7 +24,8 @@ extract:
2024
- name: dest_connection_subnet_count
2125
by:
2226
- dstSubnet
23-
operation: count
27+
operation: sum
28+
recordKey: isNewFlow
2429
encode:
2530
type: prom
2631
prom:

0 commit comments

Comments
 (0)