From e484e8bb388f466f4670db1eb6bd1ccc71bb6603 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Wed, 28 Aug 2024 12:18:53 -0700 Subject: [PATCH] Fix template ID error in IPFIX exporter (#6630) (#6634) The template ID is only available after the exporter has been initialized. With this fix, we avoid the following error for the first data record to be exported: ``` error when sending IPFIX record: error when doing sanity check:process: templateID 0 does not exist in exporting process ``` Signed-off-by: Antonin Bas --- pkg/flowaggregator/exporter/ipfix.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/flowaggregator/exporter/ipfix.go b/pkg/flowaggregator/exporter/ipfix.go index 35f46a9ac17..53b533d4ef2 100644 --- a/pkg/flowaggregator/exporter/ipfix.go +++ b/pkg/flowaggregator/exporter/ipfix.go @@ -151,11 +151,6 @@ func (e *IPFIXExporter) UpdateOptions(opt *options.Options) { } func (e *IPFIXExporter) sendRecord(record ipfixentities.Record, isRecordIPv6 bool) error { - templateID := e.templateIDv4 - if isRecordIPv6 { - templateID = e.templateIDv6 - } - if e.exportingProcess == nil { if err := initIPFIXExportingProcess(e); err != nil { // in case of error, the FlowAggregator flowExportLoop will retry after activeFlowRecordTimeout @@ -163,6 +158,11 @@ func (e *IPFIXExporter) sendRecord(record ipfixentities.Record, isRecordIPv6 boo } } + templateID := e.templateIDv4 + if isRecordIPv6 { + templateID = e.templateIDv6 + } + // TODO: more records per data set will be supported when go-ipfix supports size check when adding records e.set.ResetSet() if err := e.set.PrepareSet(ipfixentities.Data, templateID); err != nil {