Skip to content

Commit 9957abe

Browse files
authored
NETOBSERV-1565: review & fix some nolints; mostly renaming things for revive (#1046)
1 parent be0d651 commit 9957abe

25 files changed

+66
-73
lines changed

pkg/confgen/confgen_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func Test_RunShortConfGen(t *testing.T) {
9898
// Unmarshal output
9999
destCfgBytes, err := os.ReadFile(configOut)
100100
require.NoError(t, err)
101-
var out config.ConfigFileStruct
101+
var out config.Root
102102
err = yaml.UnmarshalStrict(destCfgBytes, &out)
103103
require.NoError(t, err)
104104
require.Len(t, out.Pipeline, 4)
@@ -191,7 +191,7 @@ func Test_RunConfGenNoAgg(t *testing.T) {
191191
// Unmarshal output
192192
destCfgBytes, err := os.ReadFile(configOut)
193193
require.NoError(t, err)
194-
var out config.ConfigFileStruct
194+
var out config.Root
195195
err = yaml.Unmarshal(destCfgBytes, &out)
196196
require.NoError(t, err)
197197
require.Len(t, out.Pipeline, 3)
@@ -276,7 +276,7 @@ func Test_RunLongConfGen(t *testing.T) {
276276
// Unmarshal output
277277
destCfgBytes, err := os.ReadFile(configOut)
278278
require.NoError(t, err)
279-
var out config.ConfigFileStruct
279+
var out config.Root
280280
err = yaml.UnmarshalStrict(destCfgBytes, &out)
281281
require.NoError(t, err)
282282
require.Len(t, out.Parameters, 6)

pkg/confgen/flowlogs2metrics_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"gopkg.in/yaml.v2"
2828
)
2929

30-
func (cg *ConfGen) GenerateFlowlogs2PipelineConfig() *config.ConfigFileStruct {
30+
func (cg *ConfGen) GenerateFlowlogs2PipelineConfig() *config.Root {
3131
pipeline, _ := config.NewPipeline("ingest_collector", &cg.config.Ingest)
3232
forkedNode := pipeline
3333
if cg.config.Transform.Generic != nil {
@@ -63,7 +63,7 @@ func (cg *ConfGen) GenerateFlowlogs2PipelineConfig() *config.ConfigFileStruct {
6363
if cg.config.Write.Loki != nil {
6464
forkedNode.WriteLoki("write_loki", *cg.config.Write.Loki)
6565
}
66-
return pipeline.IntoConfigFileStruct(&config.ConfigFileStruct{
66+
return pipeline.IntoRootConfig(&config.Root{
6767
LogLevel: "error",
6868
MetricsSettings: config.MetricsSettings{
6969
PromConnectionInfo: api.PromConnectionInfo{Port: 9102},

pkg/config/config.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ type Options struct {
3535
Profile Profile
3636
}
3737

38-
// (nolint => needs refactoring)
39-
//
40-
//nolint:revive
41-
type ConfigFileStruct struct {
38+
type Root struct {
4239
LogLevel string `yaml:"log-level,omitempty" json:"log-level,omitempty"`
4340
MetricsSettings MetricsSettings `yaml:"metricsSettings,omitempty" json:"metricsSettings,omitempty"`
4441
Pipeline []Stage `yaml:"pipeline,omitempty" json:"pipeline,omitempty"`
@@ -150,8 +147,8 @@ type Write struct {
150147
}
151148

152149
// ParseConfig creates the internal unmarshalled representation from the Pipeline and Parameters json
153-
func ParseConfig(opts *Options) (ConfigFileStruct, error) {
154-
out := ConfigFileStruct{}
150+
func ParseConfig(opts *Options) (Root, error) {
151+
out := Root{}
155152

156153
logrus.Debugf("opts.PipeLine = %v ", opts.PipeLine)
157154
err := JSONUnmarshalStrict([]byte(opts.PipeLine), &out.Pipeline)

pkg/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestJSONUnmarshalStrict(t *testing.T) {
4747

4848
func TestUnmarshalInline(t *testing.T) {
4949
cfg := `{"metricsSettings":{"port":9102,"prefix":"netobserv_"}}`
50-
var cfs ConfigFileStruct
50+
var cfs Root
5151
err := yaml.Unmarshal([]byte(cfg), &cfs)
5252
require.NoError(t, err)
5353
require.Equal(t, "netobserv_", cfs.MetricsSettings.Prefix)

pkg/config/pipeline_builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ func (b *PipelineBuilderStage) GetDynamicStageParams() []StageParam {
235235
return res
236236
}
237237

238-
// IntoConfigFileStruct injects the current pipeline and params in the provided ConfigFileStruct object.
239-
func (b *PipelineBuilderStage) IntoConfigFileStruct(cfs *ConfigFileStruct) *ConfigFileStruct {
238+
// IntoRootConfig injects the current pipeline and params in the provided config.Root object.
239+
func (b *PipelineBuilderStage) IntoRootConfig(cfs *Root) *Root {
240240
cfs.Pipeline = b.GetStages()
241241
cfs.Parameters = b.GetStageParams()
242242
return cfs
243243
}
244244

245-
// ToConfigFileStruct returns the current pipeline and params as a new ConfigFileStruct object.
246-
func (b *PipelineBuilderStage) ToConfigFileStruct() *ConfigFileStruct {
247-
return b.IntoConfigFileStruct(&ConfigFileStruct{})
245+
// ToRootConfig returns the current pipeline and params as a new config.Root object.
246+
func (b *PipelineBuilderStage) ToRootConfig() *Root {
247+
return b.IntoRootConfig(&Root{})
248248
}

pkg/pipeline/aggregate_prom_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ parameters:
177177
for _, aa := range actualAggs {
178178
promEncode.Encode(aa)
179179
}
180-
exposed := test.ReadExposedMetrics(t, promEncode.(*encode.EncodeProm).Gatherer())
180+
exposed := test.ReadExposedMetrics(t, promEncode.(*encode.Prometheus).Gatherer())
181181

182182
for _, expected := range tt.expectedEncode {
183183
require.Contains(t, exposed, expected)

pkg/pipeline/conntrack_integ_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func ingestFile(t *testing.T, in chan<- config.GenericMap, filepath string) int
167167
lines = append(lines, []byte(text))
168168
}
169169
submittedLines := 0
170-
decoder, err := decode.NewDecodeJSON()
170+
decoder, err := decode.NewJSON()
171171
require.NoError(t, err)
172172
for _, line := range lines {
173173
line, err := decoder.Decode(line)

pkg/pipeline/decode/decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Decoder interface {
3232
func GetDecoder(params api.Decoder) (Decoder, error) {
3333
switch params.Type {
3434
case api.DecoderJSON:
35-
return NewDecodeJSON()
35+
return NewJSON()
3636
case api.DecoderProtobuf:
3737
return decode.NewProtobuf()
3838
}

pkg/pipeline/decode/decode_json.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ import (
2525
log "github.com/sirupsen/logrus"
2626
)
2727

28-
//nolint:revive
29-
type DecodeJSON struct {
28+
type JSON struct {
3029
}
3130

3231
// Decode decodes input strings to a list of flow entries
33-
func (c *DecodeJSON) Decode(line []byte) (config.GenericMap, error) {
32+
func (c *JSON) Decode(line []byte) (config.GenericMap, error) {
3433

3534
if log.IsLevelEnabled(log.DebugLevel) {
3635
log.Debugf("decodeJSON: line = %v", string(line))
@@ -52,8 +51,8 @@ func (c *DecodeJSON) Decode(line []byte) (config.GenericMap, error) {
5251
return decodedLine2, nil
5352
}
5453

55-
// NewDecodeJSON create a new decode
56-
func NewDecodeJSON() (Decoder, error) {
57-
log.Debugf("entering NewDecodeJSON")
58-
return &DecodeJSON{}, nil
54+
// NewJSON create a new JSON decoder
55+
func NewJSON() (Decoder, error) {
56+
log.Debugf("entering decode.NewJSON")
57+
return &JSON{}, nil
5958
}

pkg/pipeline/decode/decode_json_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
)
2525

2626
func initNewDecodeJSON(t *testing.T) Decoder {
27-
newDecode, err := NewDecodeJSON()
27+
newDecode, err := NewJSON()
2828
require.Equal(t, nil, err)
2929
return newDecode
3030
}
3131

3232
func TestDecodeJSON(t *testing.T) {
3333
newDecode := initNewDecodeJSON(t)
34-
decodeJSON := newDecode.(*DecodeJSON)
34+
decodeJSON := newDecode.(*JSON)
3535

3636
out, err := decodeJSON.Decode([]byte(
3737
"{\"varInt\": 12, \"varString\":\"testString\", \"varBool\":false}"))
@@ -53,7 +53,7 @@ func TestDecodeJSON(t *testing.T) {
5353

5454
func TestDecodeJSONTimestamps(t *testing.T) {
5555
newDecode := initNewDecodeJSON(t)
56-
decodeJSON := newDecode.(*DecodeJSON)
56+
decodeJSON := newDecode.(*JSON)
5757
out, err := decodeJSON.Decode([]byte("{\"unixTime\": 1645104030 }"))
5858
require.NoError(t, err)
5959
require.Equal(t, float64(1645104030), out["unixTime"])

0 commit comments

Comments
 (0)