Skip to content

Commit 446bbc3

Browse files
authored
Merge pull request #93 from eranra/k8s_labels_configurable
adding k8s labels based on value and only if it is not empty
2 parents 7c792c6 + 99e1af5 commit 446bbc3

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,13 @@ All the geo-location fields will be named by appending `output` value
304304
(e.g., `CountryName`, `CountryLongName`, `RegionName`, `CityName` , `Longitude` and `Latitude`)
305305

306306
The fifth rule `add_kubernetes` generates new fields with kubernetes information by
307-
matching the `input` value (`srcIP` in the example above) with k8s `nodes`, `pods` and `services` IPs.
307+
matching the `input` value (`srcIP` in the example above) with kubernetes `nodes`, `pods` and `services` IPs.
308308
All the kubernetes fields will be named by appending `output` value
309309
(`srcK8S` in the example above) to the kubernetes metadata field names
310-
(e.g., `Namespace`, `Name`, `Type`, `OwnerName`, `OwnerType` )
310+
(e.g., `Namespace`, `Name`, `Type`, `OwnerName`, `OwnerType` )
311+
312+
In addition, if the `parameters` value is not empty, fields with kubernetes labels
313+
will be generated, and named by appending `parameters` value to the label keys.
311314

312315
> Note: kubernetes connection is done using the first available method:
313316
> 1. configuration parameter `KubeConfigPath` (in the example above `/tmp/config`) or

contrib/kubernetes/flowlogs2metrics.conf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pipeline:
251251
- input: srcIP
252252
output: srcK8S
253253
type: add_kubernetes
254-
parameters: ""
254+
parameters: srcK8S_labels
255255
- input: dstIP
256256
output: dstLocation
257257
type: add_location

network_definitions/egress_bandwidth_per_namespace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ transform:
1414
- input: srcIP
1515
output: srcK8S
1616
type: add_kubernetes
17+
parameters: srcK8S_labels
1718
extract:
1819
aggregates:
1920
- name: bandwidth_namespace

pkg/pipeline/transform/transform_network.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ func (n *Network) Transform(inputEntry config.GenericMap) config.GenericMap {
135135
outputEntries[rule.Output+"_Type"] = kubeInfo.Type
136136
outputEntries[rule.Output+"_OwnerName"] = kubeInfo.Owner.Name
137137
outputEntries[rule.Output+"_OwnerType"] = kubeInfo.Owner.Type
138-
for labelKey, labelValue := range kubeInfo.Labels {
139-
outputEntries[rule.Output+"_Labels_"+labelKey] = labelValue
138+
if rule.Parameters != "" {
139+
for labelKey, labelValue := range kubeInfo.Labels {
140+
outputEntries[rule.Parameters+"_"+labelKey] = labelValue
141+
}
140142
}
141143
default:
142144
log.Panicf("unknown type %s for transform.Network rule: %v", rule.Type, rule)

0 commit comments

Comments
 (0)