Skip to content

Commit

Permalink
Use converToString insted of Sprintf (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amoghrd committed Aug 20, 2024
1 parent f5d2cef commit 5034e92
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/confgenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

jsoniter "github.com/json-iterator/go"
"github.com/netobserv/flowlogs-pipeline/pkg/confgen"
"github.com/netobserv/flowlogs-pipeline/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -110,7 +111,7 @@ func bindFlags(cmd *cobra.Command, v *viper.Viper) {
val := v.Get(f.Name)
switch val.(type) {
case bool, uint, string, int32, int16, int8, int, uint32, uint64, int64, float64, float32, []string, []int:
_ = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
_ = cmd.Flags().Set(f.Name, utils.ConvertToString(val))
default:
var jsoniterJSON = jsoniter.ConfigCompatibleWithStandardLibrary
b, err := jsoniterJSON.Marshal(&val)
Expand Down
3 changes: 2 additions & 1 deletion pkg/pipeline/extract/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/netobserv/flowlogs-pipeline/pkg/api"
"github.com/netobserv/flowlogs-pipeline/pkg/config"
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/utils"
util "github.com/netobserv/flowlogs-pipeline/pkg/utils"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -152,7 +153,7 @@ func (aggregate *Aggregate) UpdateByEntry(entry config.GenericMap, normalizedVal
if operationKey != "" {
value, ok := entry[operationKey]
if ok {
valueString := fmt.Sprintf("%v", value)
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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/extract/conntrack/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ func (c *connType) isMatchSelector(selector map[string]interface{}) bool {
return false
}
case string:
selectorValue := fmt.Sprintf("%v", v)
selectorValue := utils.ConvertToString(v)
if connValue != selectorValue {
return false
}
default:
connValue = fmt.Sprintf("%v", connValue)
connValue = utils.ConvertToString(connValue)
selectorValue := fmt.Sprintf("%v", v)
if connValue != selectorValue {
return false
Expand Down
6 changes: 3 additions & 3 deletions pkg/pipeline/transform/kubernetes/enrich.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kubernetes

import (
"fmt"
"strings"

"github.com/netobserv/flowlogs-pipeline/pkg/api"
"github.com/netobserv/flowlogs-pipeline/pkg/config"
inf "github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/kubernetes/informers"
"github.com/netobserv/flowlogs-pipeline/pkg/utils"
"github.com/sirupsen/logrus"
)

Expand All @@ -22,7 +22,7 @@ func InitFromConfig(kubeConfigPath string) error {
}

func Enrich(outputEntry config.GenericMap, rule api.K8sRule) {
kubeInfo, err := informers.GetInfo(fmt.Sprintf("%s", outputEntry[rule.Input]))
kubeInfo, err := informers.GetInfo(utils.ConvertToString(outputEntry[rule.Input]))
if err != nil {
logrus.WithError(err).Tracef("can't find kubernetes info for IP %v", outputEntry[rule.Input])
return
Expand Down Expand Up @@ -123,7 +123,7 @@ func fillInK8sZone(outputEntry config.GenericMap, rule api.K8sRule, kubeInfo *in
func EnrichLayer(outputEntry config.GenericMap, rule *api.K8sInfraRule) {
outputEntry[rule.Output] = "infra"
for _, input := range rule.Inputs {
if objectIsApp(fmt.Sprintf("%s", outputEntry[input]), rule) {
if objectIsApp(utils.ConvertToString(outputEntry[input]), rule) {
outputEntry[rule.Output] = "app"
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/transform/transform_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func applyRule(entry config.GenericMap, labels map[string]string, rule *api.Tran
entry[rule.AddFieldIfDoesntExist.Input] = rule.AddFieldIfDoesntExist.Value
}
case api.AddRegExIf:
matched, err := regexp.MatchString(rule.AddRegExIf.Parameters, fmt.Sprintf("%s", entry[rule.AddRegExIf.Input]))
matched, err := regexp.MatchString(rule.AddRegExIf.Parameters, utils.ConvertToString(entry[rule.AddRegExIf.Input]))
if err != nil {
return true
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/pipeline/transform/transform_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/location"
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/transform/netdb"
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/utils"
util "github.com/netobserv/flowlogs-pipeline/pkg/utils"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func (n *Network) Transform(inputEntry config.GenericMap) (config.GenericMap, bo
continue
}
var locationInfo *location.Info
locationInfo, err := location.GetLocation(fmt.Sprintf("%s", outputEntry[rule.AddLocation.Input]))
locationInfo, err := location.GetLocation(util.ConvertToString(outputEntry[rule.AddLocation.Input]))
if err != nil {
log.Warningf("Can't find location for IP %v err %v", outputEntry[rule.AddLocation.Input], err)
continue
Expand Down

0 comments on commit 5034e92

Please sign in to comment.