Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func ParseNestedFields(fields []string) ([][]string, error) {
return result, nil
}

func SetDefaultValues(data interface{}) error {
func SetDefaultValues(data any) error {
t := reflect.TypeOf(data).Elem()
v := reflect.ValueOf(data).Elem()

Expand Down Expand Up @@ -686,9 +686,10 @@ func SetDefaultValues(data interface{}) error {
case reflect.Bool:
currentValue := vField.Bool()
if !currentValue {
if defaultValue == "true" {
switch defaultValue {
case "true":
vField.SetBool(true)
} else if defaultValue == "false" {
case "false":
vField.SetBool(false)
}
}
Expand Down Expand Up @@ -747,8 +748,8 @@ func mergeYAMLs(a, b map[interface{}]interface{}) map[interface{}]interface{} {
}
for k, v := range b {
if existingValue, exists := merged[k]; exists {
if existingMap, ok := existingValue.(map[interface{}]interface{}); ok {
if newMap, ok := v.(map[interface{}]interface{}); ok {
if existingMap, ok := existingValue.(map[any]any); ok {
if newMap, ok := v.(map[any]any); ok {
merged[k] = mergeYAMLs(existingMap, newMap)
continue
}
Expand Down
80 changes: 39 additions & 41 deletions cfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ func TestApplyEnvs(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
object, err := simplejson.NewJson([]byte(tt.json))
require.NoError(t, err)
Expand Down Expand Up @@ -736,41 +735,41 @@ func TestExpression_UnmarshalJSON(t *testing.T) {
func TestMergeYAMLs(t *testing.T) {
tests := []struct {
name string
a map[interface{}]interface{}
b map[interface{}]interface{}
expected map[interface{}]interface{}
a map[any]any
b map[any]any
expected map[any]any
}{
{
name: "simple merge",
a: map[interface{}]interface{}{
a: map[any]any{
"key1": "value1",
"key2": "value2",
},
b: map[interface{}]interface{}{
b: map[any]any{
"key2": "newValue2",
"key3": "value3",
},
expected: map[interface{}]interface{}{
expected: map[any]any{
"key1": "value1",
"key2": "newValue2",
"key3": "value3",
},
},
{
name: "nested maps",
a: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
a: map[any]any{
"key1": map[any]any{
"subkey1": "subvalue1",
},
},
b: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
b: map[any]any{
"key1": map[any]any{
"subkey2": "subvalue2",
},
"key2": "value2",
},
expected: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
expected: map[any]any{
"key1": map[any]any{
"subkey1": "subvalue1",
"subkey2": "subvalue2",
},
Expand All @@ -779,76 +778,76 @@ func TestMergeYAMLs(t *testing.T) {
},
{
name: "overwriting nested maps",
a: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
a: map[any]any{
"key1": map[any]any{
"subkey1": "subvalue1",
},
},
b: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
b: map[any]any{
"key1": map[any]any{
"subkey1": "newSubvalue1",
"subkey2": "subvalue2",
},
},
expected: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
expected: map[any]any{
"key1": map[any]any{
"subkey1": "newSubvalue1",
"subkey2": "subvalue2",
},
},
},
{
name: "empty maps",
a: map[interface{}]interface{}{},
b: map[interface{}]interface{}{},
expected: map[interface{}]interface{}{
a: map[any]any{},
b: map[any]any{},
expected: map[any]any{
// Expecting an empty map
},
},
{
name: "a is empty",
a: map[interface{}]interface{}{},
b: map[interface{}]interface{}{
a: map[any]any{},
b: map[any]any{
"key1": "value1",
},
expected: map[interface{}]interface{}{
expected: map[any]any{
"key1": "value1",
},
},
{
name: "b is empty",
a: map[interface{}]interface{}{
a: map[any]any{
"key1": "value1",
},
b: map[interface{}]interface{}{},
expected: map[interface{}]interface{}{
b: map[any]any{},
expected: map[any]any{
"key1": "value1",
},
},
{
name: "override slice",
a: map[interface{}]interface{}{
"key1": []interface{}{"value1", "value2"},
a: map[any]any{
"key1": []any{"value1", "value2"},
},
b: map[interface{}]interface{}{
"key1": []interface{}{"newValue1", "newValue2"},
b: map[any]any{
"key1": []any{"newValue1", "newValue2"},
},
expected: map[interface{}]interface{}{
"key1": []interface{}{"newValue1", "newValue2"},
expected: map[any]any{
"key1": []any{"newValue1", "newValue2"},
},
},
{
name: "merge slice with map",
a: map[interface{}]interface{}{
"key1": []interface{}{"value1", "value2"},
a: map[any]any{
"key1": []any{"value1", "value2"},
},
b: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
b: map[any]any{
"key1": map[any]any{
"subkey1": "subvalue1",
},
},
expected: map[interface{}]interface{}{
"key1": map[interface{}]interface{}{
expected: map[any]any{
"key1": map[any]any{
"subkey1": "subvalue1",
},
},
Expand Down Expand Up @@ -909,7 +908,6 @@ func TestBuildFieldSelector(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion cfg/matchrule/matchrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func TestRule_Match(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion cfg/substitution/regex_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *RegexFilter) compareArgs(args []any) error {
if len(wantGroups) != len(gotGroups) {
return fmt.Errorf("wrong regex filter groups, want=%v got=%v", wantGroups, gotGroups)
}
for i := 0; i < len(wantGroups); i++ {
for i := range wantGroups {
if wantGroups[i] != gotGroups[i] {
return fmt.Errorf("wrong regex filter groups, want=%v got=%v", wantGroups, gotGroups)
}
Expand Down
2 changes: 0 additions & 2 deletions cfg/substitution/substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ func TestParseSubstitution(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result, err := ParseSubstitution(tt.substitution, nil, lg)
Expand Down Expand Up @@ -526,7 +525,6 @@ func TestFilterApply(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
subOps, err := ParseSubstitution(tt.substitution, nil, lg)
Expand Down
16 changes: 7 additions & 9 deletions cmd/file.d/file.d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestEndToEnd(t *testing.T) {
fileCount := 8

// we are very deterministic :)
rand.Seed(0)
rnd := rand.New(rand.NewSource(0))

// disable k8s environment
meta.DisableMetaUpdates = true
Expand All @@ -96,8 +96,8 @@ func TestEndToEnd(t *testing.T) {

tm := time.Now()
for {
for i := 0; i < writerCount; i++ {
go runWriter(filesDir, fileCount)
for range writerCount {
go runWriter(filesDir, fileCount, rnd)
}

time.Sleep(iterationInterval)
Expand All @@ -107,7 +107,7 @@ func TestEndToEnd(t *testing.T) {
}
}

func runWriter(tempDir string, files int) {
func runWriter(tempDir string, files int, rnd *rand.Rand) {
format := `{"log":"%s\n","stream":"stderr"}`
panicLines := make([]string, 0)
for _, line := range strings.Split(panicContent, "\n") {
Expand All @@ -117,7 +117,7 @@ func runWriter(tempDir string, files int) {
panicLines = append(panicLines, fmt.Sprintf(format, line))
}

for i := 0; i < files; i++ {
for range files {
u1 := strings.ReplaceAll(uuid.NewV4().String(), "-", "")
u2 := strings.ReplaceAll(uuid.NewV4().String(), "-", "")
name := path.Join(tempDir, "pod_ns_container-"+u1+u2+".log")
Expand All @@ -131,10 +131,10 @@ func runWriter(tempDir string, files int) {
}

stream := "stderr"
if rand.Int()%3 == 0 {
if rnd.Int()%3 == 0 {
stream = "stderr"
}
if rand.Int()%100 == 0 {
if rnd.Int()%100 == 0 {
for k := 0; k < 8; k++ {
_, _ = fmt.Fprintf(logFile, multilineJSON, stream)
_, _ = logFile.Write([]byte{'\n'})
Expand Down Expand Up @@ -251,7 +251,6 @@ func TestConfigParseValid(t *testing.T) {
},
}
for _, tl := range testList {
tl := tl
t.Run(tl.name, func(t *testing.T) {
t.Parallel()
pluginInfo, err := fd.DefaultPluginRegistry.Get(tl.kind, tl.name)
Expand Down Expand Up @@ -291,7 +290,6 @@ func TestConfigParseInvalid(t *testing.T) {
},
}
for _, tl := range testList {
tl := tl
t.Run(tl.name, func(t *testing.T) {
t.Parallel()
pluginInfo, err := fd.DefaultPluginRegistry.Get(tl.kind, tl.name)
Expand Down
2 changes: 0 additions & 2 deletions decoder/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func TestDecodeCSV(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -161,7 +160,6 @@ func TestDecodeToJsonCSV(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
19 changes: 9 additions & 10 deletions decoder/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func TestJson(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -143,15 +142,15 @@ func TestJson(t *testing.T) {

func genBenchFields(count int) string {
var sb strings.Builder
for i := 0; i < count; i++ {
sb.WriteString(fmt.Sprintf(`"field_%d":"vaaaaaaaaaaaaaal_%d",`, i, i))
for i := range count {
fmt.Fprintf(&sb, `"field_%d":"vaaaaaaaaaaaaaal_%d",`, i, i)
}
return sb.String()
}

func genBenchParams(count, maxLen int) map[string]int {
m := map[string]int{}
for i := 0; i < count; i++ {
for i := range count {
m[fmt.Sprintf("field_%d", i)] = maxLen
}
return m
Expand All @@ -165,25 +164,25 @@ func BenchmarkCutFieldsBySize(b *testing.B) {
params map[string]int
}{
{
json: []byte(fmt.Sprintf(benchJsonFormat, genBenchFields(0))),
json: fmt.Appendf(nil, benchJsonFormat, genBenchFields(0)),
params: map[string]int{
"message": 7,
},
},
{
json: []byte(fmt.Sprintf(benchJsonFormat, genBenchFields(10))),
json: fmt.Appendf(nil, benchJsonFormat, genBenchFields(10)),
params: genBenchParams(9, 3),
},
{
json: []byte(fmt.Sprintf(benchJsonFormat, genBenchFields(100))),
json: fmt.Appendf(nil, benchJsonFormat, genBenchFields(100)),
params: genBenchParams(98, 5),
},
{
json: []byte(fmt.Sprintf(benchJsonFormat, genBenchFields(1000))),
json: fmt.Appendf(nil, benchJsonFormat, genBenchFields(1000)),
params: genBenchParams(997, 7),
},
{
json: []byte(fmt.Sprintf(benchJsonFormat, genBenchFields(10000))),
json: fmt.Appendf(nil, benchJsonFormat, genBenchFields(10000)),
params: genBenchParams(9996, 9),
},
}
Expand All @@ -199,7 +198,7 @@ func BenchmarkCutFieldsBySize(b *testing.B) {
cutPositions: make([]jsonCutPos, 0, len(benchCase.params)),
mu: &sync.Mutex{},
}
for i := 0; i < b.N; i++ {
for range b.N {
_ = d.cutFieldsBySize(benchCase.json)
}
})
Expand Down
1 change: 0 additions & 1 deletion decoder/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func TestNginxError(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading