From e7bda04577b1b260898a8dfb127303af0f1a4cd4 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Tue, 20 Feb 2024 13:54:54 -0500 Subject: [PATCH 01/13] add new field to ipfix exporter for flowRtt --- pkg/pipeline/write/write_ipfix.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 5cf78f8b5..2629bb7c7 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -111,6 +111,10 @@ func addKubeContextToTemplate(elements *[]entities.InfoElementWithValue, registr return err } } + err = addElementToTemplate("timeFlowRttNs", nil, elements, registryID) + if err != nil { + return err + } return nil } @@ -150,6 +154,11 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } + err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 13, EnterpriseID, 65535)), EnterpriseID) + if err != nil { + ilog.WithError(err).Errorf("Failed to register element") + return err + } return nil } @@ -379,7 +388,13 @@ func setKubeIEValue(record config.GenericMap, ieValPtr *entities.InfoElementWith } else { ieVal.SetStringValue("none") } - } + case "timeFlowRttNs": + if record["TimeFlowRttNs"] != nil { + ieVal.SetUnsigned64Value(record["TimeFlowRttNs"].(uint64)) + } else { + // nothing here for now + } + } } func setEntities(record config.GenericMap, enrichEnterpriseID uint32, elements *[]entities.InfoElementWithValue) error { for _, ieVal := range *elements { From 1cd023fa780ee3a37562c4f045a6c579ac170525 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Tue, 20 Feb 2024 14:01:12 -0500 Subject: [PATCH 02/13] go fmt --- pkg/pipeline/write/write_ipfix.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 2629bb7c7..5b76f787f 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -389,12 +389,12 @@ func setKubeIEValue(record config.GenericMap, ieValPtr *entities.InfoElementWith ieVal.SetStringValue("none") } case "timeFlowRttNs": - if record["TimeFlowRttNs"] != nil { + if record["TimeFlowRttNs"] != nil { ieVal.SetUnsigned64Value(record["TimeFlowRttNs"].(uint64)) - } else { - // nothing here for now - } - } + } else { + // nothing here for now + } + } } func setEntities(record config.GenericMap, enrichEnterpriseID uint32, elements *[]entities.InfoElementWithValue) error { for _, ieVal := range *elements { From 53080c28ffe8f9f39ff18e20760323fd009b4720 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Tue, 20 Feb 2024 15:50:14 -0500 Subject: [PATCH 03/13] fix type on timeFlowRttNs field --- pkg/pipeline/write/write_ipfix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 5b76f787f..22d588cbd 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -154,7 +154,7 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 13, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 4, EnterpriseID, 65535)), EnterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err From 030c6bb85279759ef8fa2b16a09716f3fdd96e0f Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Mon, 26 Feb 2024 06:03:30 -0500 Subject: [PATCH 04/13] rebase --- pkg/pipeline/write/write_ipfix.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 22d588cbd..eadb2ff09 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 IBM, Inc. + * Copyright (C) 2023 IBM, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ var ( "destinationNodeName", } CustomNetworkFields = []string{ - // TODO + "timeFlowRttNs", } ) @@ -111,10 +111,6 @@ func addKubeContextToTemplate(elements *[]entities.InfoElementWithValue, registr return err } } - err = addElementToTemplate("timeFlowRttNs", nil, elements, registryID) - if err != nil { - return err - } return nil } @@ -154,7 +150,7 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 4, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 4, EnterpriseID, 8)), EnterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err @@ -345,6 +341,12 @@ func setStandardIEValue(record config.GenericMap, ieValPtr *entities.InfoElement } else { return fmt.Errorf("unable to find interface in record") } + case "timeFlowRttNs": + if record["TimeFlowRttNs"] != nil { + ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) + } else { + return fmt.Errorf("unable to find timeflowrtt in record") + } } return nil } @@ -388,12 +390,6 @@ func setKubeIEValue(record config.GenericMap, ieValPtr *entities.InfoElementWith } else { ieVal.SetStringValue("none") } - case "timeFlowRttNs": - if record["TimeFlowRttNs"] != nil { - ieVal.SetUnsigned64Value(record["TimeFlowRttNs"].(uint64)) - } else { - // nothing here for now - } } } func setEntities(record config.GenericMap, enrichEnterpriseID uint32, elements *[]entities.InfoElementWithValue) error { From 7da51099eb12300e3da0e613edbf86e4e199c275 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 12:40:12 -0500 Subject: [PATCH 05/13] rebase --- pkg/pipeline/write/write_ipfix.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index eadb2ff09..68c6b8953 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -150,7 +150,11 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } +<<<<<<< HEAD err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 4, EnterpriseID, 8)), EnterpriseID) +======= + err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, entities.Unsigned64, EnterpriseID, 8)), EnterpriseID) +>>>>>>> af8980f4 (sync with jotak:test-ipfix and implement writing timeflowrttns in the new pattern) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err @@ -343,7 +347,11 @@ func setStandardIEValue(record config.GenericMap, ieValPtr *entities.InfoElement } case "timeFlowRttNs": if record["TimeFlowRttNs"] != nil { +<<<<<<< HEAD ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) +======= + ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) +>>>>>>> af8980f4 (sync with jotak:test-ipfix and implement writing timeflowrttns in the new pattern) } else { return fmt.Errorf("unable to find timeflowrtt in record") } From 45e9cb774bd2fd6e9b7efbde3a75e26d3f96c24f Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 12:41:30 -0500 Subject: [PATCH 06/13] add test case for timeflowrttns --- pkg/pipeline/write/testnorace/write_ipfix_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index f67ca993b..a8782ac9b 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -176,6 +176,8 @@ func matchElement(t *testing.T, element entities.InfoElementWithValue, flow conf assert.Equal(t, flow["SrcK8S_HostName"], element.GetStringValue()) case "destinationNodeName": assert.Equal(t, flow["DstK8S_HostName"], element.GetStringValue()) + case "timeFlowRttNs": + assert.Equal(t, flow["TimeFlowRttNs"], element.GetStringValue()) case "sourceMacAddress": case "destinationMacAddress": // Getting some discrepancies here, need to figure out why From 0e5e24aa9601dfd01a5e4a151b9fedcb404ed307 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 19:05:45 -0500 Subject: [PATCH 07/13] fix type in ipfix unit test --- pkg/pipeline/write/testnorace/write_ipfix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index a8782ac9b..eb4e77220 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -177,7 +177,7 @@ func matchElement(t *testing.T, element entities.InfoElementWithValue, flow conf case "destinationNodeName": assert.Equal(t, flow["DstK8S_HostName"], element.GetStringValue()) case "timeFlowRttNs": - assert.Equal(t, flow["TimeFlowRttNs"], element.GetStringValue()) + assert.Equal(t, flow["TimeFlowRttNs"], element.GetUnsigned64Value()) case "sourceMacAddress": case "destinationMacAddress": // Getting some discrepancies here, need to figure out why From effe6236dc9b78fea30f9b3872a0ccf93f13a79b Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 19:06:44 -0500 Subject: [PATCH 08/13] increase number of returned fields in ipfix test --- pkg/pipeline/write/testnorace/write_ipfix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index eb4e77220..0290bf174 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -119,7 +119,7 @@ func TestEnrichedIPFIXFlow(t *testing.T) { assert.Equal(t, uint16(10), tplv4Msg.GetVersion()) templateSet := tplv4Msg.GetSet() templateElements := templateSet.GetRecords()[0].GetOrderedElementList() - assert.Len(t, templateElements, 20) + assert.Len(t, templateElements, 21) assert.Equal(t, uint32(0), templateElements[0].GetInfoElement().EnterpriseId) // Check data From 3172f61de8afb15d63ba696b556c8d5606179a43 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 19:07:53 -0500 Subject: [PATCH 09/13] fix type in ipfix unit test --- pkg/pipeline/write/testnorace/write_ipfix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index 0290bf174..a798d41a0 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -177,7 +177,7 @@ func matchElement(t *testing.T, element entities.InfoElementWithValue, flow conf case "destinationNodeName": assert.Equal(t, flow["DstK8S_HostName"], element.GetStringValue()) case "timeFlowRttNs": - assert.Equal(t, flow["TimeFlowRttNs"], element.GetUnsigned64Value()) + assert.Equal(t, flow["TimeFlowRttNs"], element.GetSigned64Value()) case "sourceMacAddress": case "destinationMacAddress": // Getting some discrepancies here, need to figure out why From a109f34f3c25f0fcbafd9543e94dbbcb7c7d288e Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Fri, 23 Feb 2024 19:10:18 -0500 Subject: [PATCH 10/13] fix type in ipfix unit test --- pkg/pipeline/write/testnorace/write_ipfix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index a798d41a0..075764d4e 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -177,7 +177,7 @@ func matchElement(t *testing.T, element entities.InfoElementWithValue, flow conf case "destinationNodeName": assert.Equal(t, flow["DstK8S_HostName"], element.GetStringValue()) case "timeFlowRttNs": - assert.Equal(t, flow["TimeFlowRttNs"], element.GetSigned64Value()) + assert.Equal(t, uint64(flow["TimeFlowRttNs"].(int64)), element.GetUnsigned64Value()) case "sourceMacAddress": case "destinationMacAddress": // Getting some discrepancies here, need to figure out why From 28e20e8b640af71d218e32fb497eba2a345df16f Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Mon, 26 Feb 2024 06:20:38 -0500 Subject: [PATCH 11/13] fix --- pkg/pipeline/write/write_ipfix.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 68c6b8953..5bc6c3448 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -150,11 +150,7 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } -<<<<<<< HEAD - err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, 4, EnterpriseID, 8)), EnterpriseID) -======= err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, entities.Unsigned64, EnterpriseID, 8)), EnterpriseID) ->>>>>>> af8980f4 (sync with jotak:test-ipfix and implement writing timeflowrttns in the new pattern) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err @@ -347,13 +343,9 @@ func setStandardIEValue(record config.GenericMap, ieValPtr *entities.InfoElement } case "timeFlowRttNs": if record["TimeFlowRttNs"] != nil { -<<<<<<< HEAD - ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) -======= ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) ->>>>>>> af8980f4 (sync with jotak:test-ipfix and implement writing timeflowrttns in the new pattern) } else { - return fmt.Errorf("unable to find timeflowrtt in record") + return fmt.Errorf("unable to find timeflowrtt in record") } } return nil From 8bea993ad378ec626508463609b53f750d958f58 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Mon, 26 Feb 2024 06:22:32 -0500 Subject: [PATCH 12/13] fmt --- pkg/pipeline/write/write_ipfix.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 5bc6c3448..16cb11a2d 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -150,7 +150,7 @@ func loadCustomRegistry(EnterpriseID uint32) error { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, entities.Unsigned64, EnterpriseID, 8)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, entities.Unsigned64, EnterpriseID, 8)), EnterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err @@ -343,9 +343,9 @@ func setStandardIEValue(record config.GenericMap, ieValPtr *entities.InfoElement } case "timeFlowRttNs": if record["TimeFlowRttNs"] != nil { - ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) + ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64))) } else { - return fmt.Errorf("unable to find timeflowrtt in record") + return fmt.Errorf("unable to find timeflowrtt in record") } } return nil From 6dd553742b3e727c394bbcc6aced03db221ac9d2 Mon Sep 17 00:00:00 2001 From: Brandon Hale Date: Mon, 26 Feb 2024 07:05:30 -0500 Subject: [PATCH 13/13] year 2024 --- pkg/pipeline/write/write_ipfix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index 16cb11a2d..e76bb9e11 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 IBM, Inc. + * Copyright (C) 2024 IBM, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.