From 5bb2146bee3220e6ef427c9a89cfa3322fc18793 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 8 Nov 2024 12:21:28 +0000 Subject: [PATCH] Bumped golangci-lint from v1.56.2 to v1.61.0 (#748) * Replace bingo with simpler bin management * Fix linter errors --------- Co-authored-by: Joel Takvorian --- .golangci.yml | 10 ++-- Makefile | 2 +- README.md | 3 ++ cmd/apitodoc/main.go | 16 ++++--- docs/operational-metrics.md | 2 +- pkg/api/encode_s3.go | 2 +- pkg/confgen/confgen.go | 2 +- pkg/confgen/doc.go | 8 ++-- pkg/confgen/grafana_jsonnet.go | 2 +- pkg/pipeline/encode/encode_prom.go | 2 +- pkg/pipeline/encode/encode_prom_metric.go | 2 +- pkg/pipeline/encode/metrics_common.go | 2 +- .../encode/opentelemetry/opentelemetry.go | 2 +- pkg/pipeline/extract/aggregate/aggregate.go | 48 +++++++++---------- pkg/pipeline/extract/aggregate/aggregates.go | 3 +- .../extract/conntrack/conntrack_test.go | 2 +- pkg/pipeline/extract/timebased/filters.go | 2 +- pkg/pipeline/extract/timebased/timebased.go | 6 +-- pkg/pipeline/transform/kubernetes/enrich.go | 4 +- .../transform/location/location_test.go | 12 ++--- pkg/pipeline/transform/transform_generic.go | 26 +++++----- pkg/pipeline/write/grpc/grpc_test.go | 2 +- .../write/testnorace/write_ipfix_test.go | 6 ++- pkg/pipeline/write/write_ipfix.go | 22 ++++----- pkg/pipeline/write/write_loki.go | 3 +- pkg/test/e2e/utils.go | 2 +- pkg/test/utils.go | 2 +- 27 files changed, 101 insertions(+), 94 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 370e1c36f..2bc5e4cc6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,7 @@ linters: - cyclop - errname - exhaustive - - exportloopref + - copyloopvar - gocritic - gofmt - gosimple @@ -16,15 +16,17 @@ linters: - stylecheck - typecheck - unused +run: + go: "1.22" linters-settings: - stylecheck: - go: "1.22" gocritic: enabled-checks: - hugeParam - rangeExprCopy - rangeValCopy - indexAlloc - - deprecatedComment + settings: + ifElseChain: + minThreshold: 3 cyclop: max-complexity: 20 diff --git a/Makefile b/Makefile index 4fc41de81..0cd56ac13 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ ifneq ($(CLEAN_BUILD),) LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}' endif -GOLANGCI_LINT_VERSION = v1.56.2 +GOLANGCI_LINT_VERSION = v1.61.0 FLP_BIN_FILE=flowlogs-pipeline CG_BIN_FILE=confgenerator diff --git a/README.md b/README.md index eb4dc339b..193e4e579 100644 --- a/README.md +++ b/README.md @@ -921,10 +921,13 @@ Usage: General help Display this help. + prereqs Check if prerequisites are met, and install missing dependencies + prereqs-kind Check if prerequisites are met for running kind, and install missing dependencies vendors Check go vendors Develop lint Lint the code + compile Compile main flowlogs-pipeline and config generator build Build flowlogs-pipeline executable and update the docs docs Update flowlogs-pipeline documentation clean Clean diff --git a/cmd/apitodoc/main.go b/cmd/apitodoc/main.go index 40134e35d..d1ad58a2c 100644 --- a/cmd/apitodoc/main.go +++ b/cmd/apitodoc/main.go @@ -36,12 +36,14 @@ func iterate(output io.Writer, data interface{}, indent int) { if err != nil { dataTypeName = "(unknown)" } - if dataType == reflect.Slice || dataType == reflect.Map { + //nolint:exhaustive + switch dataType { + case reflect.Slice, reflect.Map: // DEBUG code: fmt.Fprintf(output, "%s %s <-- %s \n",strings.Repeat(" ",4*indent),dataTypeName,dataType ) zeroElement := reflect.Zero(reflect.ValueOf(data).Type().Elem()).Interface() iterate(output, zeroElement, newIndent) return - } else if dataType == reflect.Struct { + case reflect.Struct: // DEBUG code: fmt.Fprintf(output,"%s %s <-- %s \n",strings.Repeat(" ",4*indent),dataTypeName,dataType ) for i := 0; i < d.NumField(); i++ { val := reflect.Indirect(reflect.ValueOf(data)) @@ -63,16 +65,18 @@ func iterate(output io.Writer, data interface{}, indent int) { } } return - } else if dataType == reflect.Ptr { + case reflect.Ptr: // DEBUG code: fmt.Fprintf(output, "%s %s <-- %s \n", strings.Repeat(" ", 4*indent), dataTypeName, dataType) elemType := reflect.TypeOf(data).Elem() zeroElement := reflect.Zero(elemType).Interface() // Since we only "converted" Ptr to Struct and the actual output is done in the next iteration, we call // iterate() with the same `indent` as the current level iterate(output, zeroElement, indent) - } else if strings.HasPrefix(dataTypeName, "api.") && strings.HasSuffix(dataTypeName, "Enum") { - // set placeholder for enum - fmt.Fprintf(output, "placeholder @%s:%d@\n", strings.TrimPrefix(dataTypeName, "api."), 4*newIndent) + default: + if strings.HasPrefix(dataTypeName, "api.") && strings.HasSuffix(dataTypeName, "Enum") { + // set placeholder for enum + fmt.Fprintf(output, "placeholder @%s:%d@\n", strings.TrimPrefix(dataTypeName, "api."), 4*newIndent) + } } } diff --git a/docs/operational-metrics.md b/docs/operational-metrics.md index e79e7e556..f229001fa 100644 --- a/docs/operational-metrics.md +++ b/docs/operational-metrics.md @@ -148,7 +148,7 @@ Each table below provides documentation for an exported flowlogs-pipeline operat |:---|:---| | **Description** | Counter of hits per secondary network index for Kubernetes enrichment | | **Type** | counter | -| **Labels** | kind, network, warning | +| **Labels** | kind, namespace, network, warning | ### stage_duration_ms diff --git a/pkg/api/encode_s3.go b/pkg/api/encode_s3.go index 346bbb1a6..71cc6d6fb 100644 --- a/pkg/api/encode_s3.go +++ b/pkg/api/encode_s3.go @@ -28,5 +28,5 @@ type EncodeS3 struct { Secure bool `yaml:"secure,omitempty" json:"secure,omitempty" doc:"true for https, false for http (default: false)"` ObjectHeaderParameters map[string]interface{} `yaml:"objectHeaderParameters,omitempty" json:"objectHeaderParameters,omitempty" doc:"parameters to include in object header (key/value pairs)"` // TBD: (TLS?) security parameters - //TLS *ClientTLS `yaml:"tls" json:"tls" doc:"TLS client configuration (optional)"` + // TLS *ClientTLS `yaml:"tls" json:"tls" doc:"TLS client configuration (optional)"` } diff --git a/pkg/confgen/confgen.go b/pkg/confgen/confgen.go index b4f111740..9db8e96d5 100644 --- a/pkg/confgen/confgen.go +++ b/pkg/confgen/confgen.go @@ -161,7 +161,7 @@ func (cg *ConfGen) ParseDefinition(name string, bytes []byte) error { return err } - //skip if their skip tag match + // skip if their skip tag match for _, skipTag := range cg.opts.SkipWithTags { for _, tag := range defFile.Tags { if skipTag == tag { diff --git a/pkg/confgen/doc.go b/pkg/confgen/doc.go index cb05514ab..bacbf432a 100644 --- a/pkg/confgen/doc.go +++ b/pkg/confgen/doc.go @@ -31,7 +31,7 @@ func (cg *ConfGen) generateVisualizeText(vgs []VisualizationGrafana) string { for _, vs := range vgs { title := vs.Title dashboard := vs.Dashboard - section = section + fmt.Sprintf("| **Visualized as** | \"%s\" on dashboard `%s` |\n", title, dashboard) + section += fmt.Sprintf("| **Visualized as** | \"%s\" on dashboard `%s` |\n", title, dashboard) } return section @@ -42,7 +42,7 @@ func (cg *ConfGen) generatePromEncodeText(metrics api.MetricsItems) string { for i := range metrics { mType := metrics[i].Type name := cg.config.Encode.Prom.Prefix + metrics[i].Name - section = section + fmt.Sprintf("| **Exposed as** | `%s` of type `%s` |\n", name, mType) + section += fmt.Sprintf("| **Exposed as** | `%s` of type `%s` |\n", name, mType) } return section @@ -57,7 +57,7 @@ func (cg *ConfGen) generateOperationText(definitions api.AggregateDefinitions) s if operationKey != "" { operationKey = fmt.Sprintf("field `%s`", operationKey) } - section = section + fmt.Sprintf("| **OperationType** | aggregate by `%s` and `%s` %s |\n", by, operation, operationKey) + section += fmt.Sprintf("| **OperationType** | aggregate by `%s` and `%s` %s |\n", by, operation, operationKey) } return section @@ -70,7 +70,7 @@ func (cg *ConfGen) generateDoc(fileName string) error { replacer := strings.NewReplacer("-", " ", "_", " ") name := replacer.Replace(filepath.Base(metric.FileName[:len(metric.FileName)-len(filepath.Ext(metric.FileName))])) - labels := strings.Join(metric.Tags[:], ", ") + labels := strings.Join(metric.Tags, ", ") // TODO: add support for multiple operations operation := cg.generateOperationText(metric.Aggregates.Rules) expose := cg.generatePromEncodeText(metric.PromEncode.Metrics) diff --git a/pkg/confgen/grafana_jsonnet.go b/pkg/confgen/grafana_jsonnet.go index 4dee6e925..2f447c7aa 100644 --- a/pkg/confgen/grafana_jsonnet.go +++ b/pkg/confgen/grafana_jsonnet.go @@ -359,7 +359,7 @@ func (cg *ConfGen) GenerateGrafanaJSON() (string, error) { if err != nil { return "", err } - panelsJSON = panelsJSON + jsonStr + panelsJSON += jsonStr } return panelsJSON, nil } diff --git a/pkg/pipeline/encode/encode_prom.go b/pkg/pipeline/encode/encode_prom.go index f90d0be5e..6a5be93d4 100644 --- a/pkg/pipeline/encode/encode_prom.go +++ b/pkg/pipeline/encode/encode_prom.go @@ -245,7 +245,7 @@ func (e *EncodeProm) checkConfUpdate() { break } default: - //Nothing to do + // Nothing to do return } } diff --git a/pkg/pipeline/encode/encode_prom_metric.go b/pkg/pipeline/encode/encode_prom_metric.go index d57112790..2e37dd11d 100644 --- a/pkg/pipeline/encode/encode_prom_metric.go +++ b/pkg/pipeline/encode/encode_prom_metric.go @@ -11,7 +11,7 @@ import ( type Predicate func(flow config.GenericMap) bool -var variableExtractor, _ = regexp.Compile(`\$\(([^\)]+)\)`) +var variableExtractor = regexp.MustCompile(`\$\(([^\)]+)\)`) type MetricInfo struct { *api.MetricsItem diff --git a/pkg/pipeline/encode/metrics_common.go b/pkg/pipeline/encode/metrics_common.go index e45f09257..f87e9a35c 100644 --- a/pkg/pipeline/encode/metrics_common.go +++ b/pkg/pipeline/encode/metrics_common.go @@ -179,7 +179,7 @@ func (m *MetricsCommonStruct) prepareMetric(mci MetricsCommonInterface, flow con return nil, 0, "" } if info.ValueScale != 0 { - floatVal = floatVal / info.ValueScale + floatVal /= info.ValueScale } entryLabels, key := extractLabelsAndKey(flow, info) diff --git a/pkg/pipeline/encode/opentelemetry/opentelemetry.go b/pkg/pipeline/encode/opentelemetry/opentelemetry.go index 246a9d767..2aebf1463 100644 --- a/pkg/pipeline/encode/opentelemetry/opentelemetry.go +++ b/pkg/pipeline/encode/opentelemetry/opentelemetry.go @@ -253,7 +253,7 @@ func (e *EncodeOtlpLogs) LogWrite(entry config.GenericMap) { msg := string(msgByteArray) // TODO: Decide whether the content should be delivered as Body or as Attributes lrc := logs.LogRecordConfig{ - //Timestamp: &now, // take timestamp from entry, if present? + // Timestamp: &now, // take timestamp from entry, if present? ObservedTimestamp: now, SeverityNumber: &sn, SeverityText: &st, diff --git a/pkg/pipeline/extract/aggregate/aggregate.go b/pkg/pipeline/extract/aggregate/aggregate.go index 7a7c2f817..308fa2d01 100644 --- a/pkg/pipeline/extract/aggregate/aggregate.go +++ b/pkg/pipeline/extract/aggregate/aggregate.go @@ -149,31 +149,29 @@ func (aggregate *Aggregate) UpdateByEntry(entry config.GenericMap, normalizedVal if operation == OperationCount { groupState.totalValue = float64(groupState.totalCount + 1) groupState.recentOpValue = float64(groupState.recentCount + 1) - } else { - if operationKey != "" { - value, ok := entry[operationKey] - if ok { - valueString := util.ConvertToString(value) - if valueFloat64, err := strconv.ParseFloat(valueString, 64); err != nil { - // Log as debug to avoid performance impact - log.Debugf("UpdateByEntry error when parsing float '%s': %v", valueString, err) - } else { - switch operation { - case OperationSum: - groupState.totalValue += valueFloat64 - groupState.recentOpValue += valueFloat64 - case OperationMax: - groupState.totalValue = math.Max(groupState.totalValue, valueFloat64) - groupState.recentOpValue = math.Max(groupState.recentOpValue, valueFloat64) - case OperationMin: - groupState.totalValue = math.Min(groupState.totalValue, valueFloat64) - groupState.recentOpValue = math.Min(groupState.recentOpValue, valueFloat64) - case OperationAvg: - groupState.totalValue = (groupState.totalValue*float64(groupState.totalCount) + valueFloat64) / float64(groupState.totalCount+1) - groupState.recentOpValue = (groupState.recentOpValue*float64(groupState.recentCount) + valueFloat64) / float64(groupState.recentCount+1) - case OperationRawValues: - groupState.recentRawValues = append(groupState.recentRawValues, valueFloat64) - } + } else if operationKey != "" { + value, ok := entry[operationKey] + if ok { + valueString := util.ConvertToString(value) + if valueFloat64, err := strconv.ParseFloat(valueString, 64); err != nil { + // Log as debug to avoid performance impact + log.Debugf("UpdateByEntry error when parsing float '%s': %v", valueString, err) + } else { + switch operation { + case OperationSum: + groupState.totalValue += valueFloat64 + groupState.recentOpValue += valueFloat64 + case OperationMax: + groupState.totalValue = math.Max(groupState.totalValue, valueFloat64) + groupState.recentOpValue = math.Max(groupState.recentOpValue, valueFloat64) + case OperationMin: + groupState.totalValue = math.Min(groupState.totalValue, valueFloat64) + groupState.recentOpValue = math.Min(groupState.recentOpValue, valueFloat64) + case OperationAvg: + groupState.totalValue = (groupState.totalValue*float64(groupState.totalCount) + valueFloat64) / float64(groupState.totalCount+1) + groupState.recentOpValue = (groupState.recentOpValue*float64(groupState.recentCount) + valueFloat64) / float64(groupState.recentCount+1) + case OperationRawValues: + groupState.recentRawValues = append(groupState.recentRawValues, valueFloat64) } } } diff --git a/pkg/pipeline/extract/aggregate/aggregates.go b/pkg/pipeline/extract/aggregate/aggregates.go index de092d5e4..848e9bf26 100644 --- a/pkg/pipeline/extract/aggregate/aggregates.go +++ b/pkg/pipeline/extract/aggregate/aggregates.go @@ -70,8 +70,7 @@ func (aggregates *Aggregates) addAggregate(aggregateDefinition *api.AggregateDef expiryTime: expiryTime.Duration, } - appendedAggregates := append(aggregates.Aggregates, aggregate) - return appendedAggregates + return append(aggregates.Aggregates, aggregate) } func (aggregates *Aggregates) cleanupExpiredEntriesLoop() { diff --git a/pkg/pipeline/extract/conntrack/conntrack_test.go b/pkg/pipeline/extract/conntrack/conntrack_test.go index 2e9541398..87c126396 100644 --- a/pkg/pipeline/extract/conntrack/conntrack_test.go +++ b/pkg/pipeline/extract/conntrack/conntrack_test.go @@ -927,7 +927,7 @@ func assertHashOrder(t *testing.T, expected []uint64, actualRecords []config.Gen func hex2int(hexStr string) uint64 { // remove 0x suffix if found in the input string - cleaned := strings.Replace(hexStr, "0x", "", -1) + cleaned := strings.ReplaceAll(hexStr, "0x", "") // base 16 for hexadecimal result, _ := strconv.ParseUint(cleaned, 16, 64) diff --git a/pkg/pipeline/extract/timebased/filters.go b/pkg/pipeline/extract/timebased/filters.go index cd47c2188..e753c3b31 100644 --- a/pkg/pipeline/extract/timebased/filters.go +++ b/pkg/pipeline/extract/timebased/filters.go @@ -102,7 +102,7 @@ func (fs *FilterStruct) CalculateValue(l *list.List, oldestValidTime time.Time) } } if fs.Rule.OperationType == api.FilterOperationAvg && nItems > 0 { - currentValue = currentValue / float64(nItems) + currentValue /= float64(nItems) } if fs.Rule.OperationType == api.FilterOperationCnt { currentValue = float64(nItems) diff --git a/pkg/pipeline/extract/timebased/timebased.go b/pkg/pipeline/extract/timebased/timebased.go index 0a003f57e..d6fded1d6 100644 --- a/pkg/pipeline/extract/timebased/timebased.go +++ b/pkg/pipeline/extract/timebased/timebased.go @@ -80,10 +80,8 @@ func CreateIndexKeysAndFilters(rules []api.TimebasedFilterRule) (map[string]*Ind } tmpIndexKeyStructs[filterRule.IndexKey] = rStruct log.Debugf("new IndexKeyTable: name = %s = %v", filterRule.IndexKey, *rStruct) - } else { - if filterRule.TimeInterval.Duration > rStruct.maxTimeInterval { - rStruct.maxTimeInterval = filterRule.TimeInterval.Duration - } + } else if filterRule.TimeInterval.Duration > rStruct.maxTimeInterval { + rStruct.maxTimeInterval = filterRule.TimeInterval.Duration } // verify the validity of the OperationType field in the filterRule switch filterRule.OperationType { diff --git a/pkg/pipeline/transform/kubernetes/enrich.go b/pkg/pipeline/transform/kubernetes/enrich.go index 899e2f2ca..b6a79df7a 100644 --- a/pkg/pipeline/transform/kubernetes/enrich.go +++ b/pkg/pipeline/transform/kubernetes/enrich.go @@ -96,7 +96,7 @@ const nodeZoneLabelName = "topology.kubernetes.io/zone" func fillInK8sZone(outputEntry config.GenericMap, rule *api.K8sRule, kubeInfo *inf.Info, zonePrefix string) { if !rule.AddZone { - //Nothing to do + // Nothing to do return } switch kubeInfo.Type { @@ -121,7 +121,7 @@ func fillInK8sZone(outputEntry config.GenericMap, rule *api.K8sRule, kubeInfo *i return case inf.TypeService: - //A service is not assigned to a dedicated zone, skipping + // A service is not assigned to a dedicated zone, skipping return } } diff --git a/pkg/pipeline/transform/location/location_test.go b/pkg/pipeline/transform/location/location_test.go index 35c393041..9fb1412d0 100644 --- a/pkg/pipeline/transform/location/location_test.go +++ b/pkg/pipeline/transform/location/location_test.go @@ -128,7 +128,7 @@ func Test_GetLocation(t *testing.T) { } func Test_unzip(t *testing.T) { - //success + // success buf := new(bytes.Buffer) zipWriter := zip.NewWriter(buf) _, _ = zipWriter.Create("test_file_in_zip") @@ -137,29 +137,29 @@ func Test_unzip(t *testing.T) { err := unzip("/tmp/test_zip.zip", "/tmp/") require.Nil(t, err) - //failed unzip + // failed unzip err = unzip("fake_test", "fake_test") require.Error(t, err) - //failed os.MkdirAll + // failed os.MkdirAll _osio.MkdirAll = func(string, os.FileMode) error { return fmt.Errorf("test") } err = unzip("/tmp/test_zip.zip", "/tmp/") require.Error(t, err) _osio.MkdirAll = os.MkdirAll - //failed os.OpenFile + // failed os.OpenFile _osio.OpenFile = func(string, int, os.FileMode) (*os.File, error) { return nil, fmt.Errorf("test") } err = unzip("/tmp/test_zip.zip", "/tmp/") require.Error(t, err) _osio.OpenFile = os.OpenFile - //failed io.Copy + // failed io.Copy _osio.Copy = func(io.Writer, io.Reader) (int64, error) { return 0, fmt.Errorf("test") } err = unzip("/tmp/test_zip.zip", "/tmp/") require.Error(t, err) _osio.Copy = io.Copy - //failed os.MkdirAll dir + // failed os.MkdirAll dir _osio.MkdirAll = func(string, os.FileMode) error { return fmt.Errorf("test") } buf = new(bytes.Buffer) zipWriter = zip.NewWriter(buf) diff --git a/pkg/pipeline/transform/transform_generic.go b/pkg/pipeline/transform/transform_generic.go index c1f2e4dcf..f30ca840d 100644 --- a/pkg/pipeline/transform/transform_generic.go +++ b/pkg/pipeline/transform/transform_generic.go @@ -53,31 +53,31 @@ func (g *Generic) Transform(entry config.GenericMap) (config.GenericMap, bool) { func (g *Generic) performMultiplier(entry config.GenericMap, transformRule api.GenericTransformRule, outputEntry config.GenericMap) bool { ok := true - switch entry[transformRule.Input].(type) { + switch val := entry[transformRule.Input].(type) { case int: - outputEntry[transformRule.Output] = transformRule.Multiplier * entry[transformRule.Input].(int) + outputEntry[transformRule.Output] = transformRule.Multiplier * val case uint: - outputEntry[transformRule.Output] = uint(transformRule.Multiplier) * entry[transformRule.Input].(uint) + outputEntry[transformRule.Output] = uint(transformRule.Multiplier) * val case int8: - outputEntry[transformRule.Output] = int8(transformRule.Multiplier) * entry[transformRule.Input].(int8) + outputEntry[transformRule.Output] = int8(transformRule.Multiplier) * val case uint8: - outputEntry[transformRule.Output] = uint8(transformRule.Multiplier) * entry[transformRule.Input].(uint8) + outputEntry[transformRule.Output] = uint8(transformRule.Multiplier) * val case int16: - outputEntry[transformRule.Output] = int16(transformRule.Multiplier) * entry[transformRule.Input].(int16) + outputEntry[transformRule.Output] = int16(transformRule.Multiplier) * val case uint16: - outputEntry[transformRule.Output] = uint16(transformRule.Multiplier) * entry[transformRule.Input].(uint16) + outputEntry[transformRule.Output] = uint16(transformRule.Multiplier) * val case int32: - outputEntry[transformRule.Output] = int32(transformRule.Multiplier) * entry[transformRule.Input].(int32) + outputEntry[transformRule.Output] = int32(transformRule.Multiplier) * val case uint32: - outputEntry[transformRule.Output] = uint32(transformRule.Multiplier) * entry[transformRule.Input].(uint32) + outputEntry[transformRule.Output] = uint32(transformRule.Multiplier) * val case int64: - outputEntry[transformRule.Output] = int64(transformRule.Multiplier) * entry[transformRule.Input].(int64) + outputEntry[transformRule.Output] = int64(transformRule.Multiplier) * val case uint64: - outputEntry[transformRule.Output] = uint64(transformRule.Multiplier) * entry[transformRule.Input].(uint64) + outputEntry[transformRule.Output] = uint64(transformRule.Multiplier) * val case float32: - outputEntry[transformRule.Output] = float32(transformRule.Multiplier) * entry[transformRule.Input].(float32) + outputEntry[transformRule.Output] = float32(transformRule.Multiplier) * val case float64: - outputEntry[transformRule.Output] = float64(transformRule.Multiplier) * entry[transformRule.Input].(float64) + outputEntry[transformRule.Output] = float64(transformRule.Multiplier) * val default: ok = false glog.Errorf("%s not of numerical type; cannot perform multiplication", transformRule.Output) diff --git a/pkg/pipeline/write/grpc/grpc_test.go b/pkg/pipeline/write/grpc/grpc_test.go index a64f9681f..ea6442377 100644 --- a/pkg/pipeline/write/grpc/grpc_test.go +++ b/pkg/pipeline/write/grpc/grpc_test.go @@ -55,7 +55,7 @@ func TestGRPCCommunication(t *testing.T) { case rs = <-serverOut: assert.Failf(t, "shouldn't have received any flow", "Got: %#v", rs) default: - //ok! + // ok! } } diff --git a/pkg/pipeline/write/testnorace/write_ipfix_test.go b/pkg/pipeline/write/testnorace/write_ipfix_test.go index f589f1491..6d8efe5c3 100644 --- a/pkg/pipeline/write/testnorace/write_ipfix_test.go +++ b/pkg/pipeline/write/testnorace/write_ipfix_test.go @@ -119,7 +119,8 @@ func TestEnrichedIPFIXFlow(t *testing.T) { cp.CloseMsgChan() cp.Stop() - expectedFields := append(write.IPv4IANAFields, write.KubeFields...) + expectedFields := write.IPv4IANAFields + expectedFields = append(expectedFields, write.KubeFields...) expectedFields = append(expectedFields, write.CustomNetworkFields...) // Check template @@ -180,7 +181,8 @@ func TestEnrichedIPFIXPartialFlow(t *testing.T) { cp.CloseMsgChan() cp.Stop() - expectedFields := append(write.IPv4IANAFields, write.KubeFields...) + expectedFields := write.IPv4IANAFields + expectedFields = append(expectedFields, write.KubeFields...) expectedFields = append(expectedFields, write.CustomNetworkFields...) // Check template diff --git a/pkg/pipeline/write/write_ipfix.go b/pkg/pipeline/write/write_ipfix.go index fd75575ad..49f8d4882 100644 --- a/pkg/pipeline/write/write_ipfix.go +++ b/pkg/pipeline/write/write_ipfix.go @@ -309,53 +309,53 @@ func addKubeContextToTemplate(elements *[]entities.InfoElementWithValue, registr return nil } -func loadCustomRegistry(EnterpriseID uint32) error { - err := registry.InitNewRegistry(EnterpriseID) +func loadCustomRegistry(enterpriseID uint32) error { + err := registry.InitNewRegistry(enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to initialize registry") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("sourcePodNamespace", 7733, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("sourcePodNamespace", 7733, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("sourcePodName", 7734, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("sourcePodName", 7734, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("destinationPodNamespace", 7735, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("destinationPodNamespace", 7735, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("destinationPodName", 7736, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("destinationPodName", 7736, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("sourceNodeName", 7737, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("sourceNodeName", 7737, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("destinationNodeName", 7738, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("destinationNodeName", 7738, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { 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 } - err = registry.PutInfoElement((*entities.NewInfoElement("interfaces", 7741, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("interfaces", 7741, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err } - err = registry.PutInfoElement((*entities.NewInfoElement("directions", 7742, entities.String, EnterpriseID, 65535)), EnterpriseID) + err = registry.PutInfoElement((*entities.NewInfoElement("directions", 7742, entities.String, enterpriseID, 65535)), enterpriseID) if err != nil { ilog.WithError(err).Errorf("Failed to register element") return err diff --git a/pkg/pipeline/write/write_loki.go b/pkg/pipeline/write/write_loki.go index 8b46db9b9..865c0d043 100644 --- a/pkg/pipeline/write/write_loki.go +++ b/pkg/pipeline/write/write_loki.go @@ -117,7 +117,8 @@ func (l *Loki) ProcessRecord(in config.GenericMap) error { l.addLabels(in, labels) // Remove labels and configured ignore list from record - ignoreList := append(l.apiConfig.IgnoreList, l.apiConfig.Labels...) + ignoreList := l.apiConfig.IgnoreList + ignoreList = append(ignoreList, l.apiConfig.Labels...) for _, label := range ignoreList { delete(out, label) } diff --git a/pkg/test/e2e/utils.go b/pkg/test/e2e/utils.go index c435376fe..d5566a362 100644 --- a/pkg/test/e2e/utils.go +++ b/pkg/test/e2e/utils.go @@ -153,7 +153,7 @@ func e2eRecreateNamespace(name string) env.Func { } } - //create namespace + // create namespace namespace = &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: name}} if err = client.Resources().Create(ctx, namespace); err != nil { return ctx, fmt.Errorf("create namespace func: %w", err) diff --git a/pkg/test/utils.go b/pkg/test/utils.go index 6dc66e795..e91f08991 100644 --- a/pkg/test/utils.go +++ b/pkg/test/utils.go @@ -135,7 +135,7 @@ func RunCommand(command string) string { fmt.Printf("error in running command: %v \n", err) } output := outBuf.Bytes() - //strip newline from end of output + // strip newline from end of output if len(output) > 0 && output[len(output)-1] == '\n' { output = output[0 : len(output)-1] }