Skip to content

Commit

Permalink
fix: hack a fix for adjustmentinterval not converting inside rules ba…
Browse files Browse the repository at this point in the history
…sed samples (#768)

## Which problem is this PR solving?

- closes #766

## Short description of the changes

- hacks away at an issue where the convert tool couldnt handle the
[]Rules in the rules based sampler.
  • Loading branch information
TylerHelmuth authored Jul 10, 2023
1 parent 31b3ec6 commit 3076db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/convert/ruleconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func transformSamplerMap(m map[string]any) map[string]any {
switch val := v.(type) {
case map[string]any:
v = transformSamplerMap(val)
case []any:
for i, x := range val {
if m, ok := x.(map[string]any); ok {
m = transformSamplerMap(m)
val[i] = m
}
}
v = val
}

k = strings.ToLower(k)
Expand All @@ -31,7 +39,16 @@ func transformSamplerMap(m map[string]any) map[string]any {
k = "clearfrequency"
v = config.Duration(v.(int64)) * config.Duration(time.Second)
case "adjustmentinterval":
v = config.Duration(v.(int64)) * config.Duration(time.Second)
if _, ok := v.(config.Duration); !ok {
var i64 int64
switch i := v.(type) {
case int64:
i64 = i
case int:
i64 = int64(i)
}
v = config.Duration(i64) * config.Duration(time.Second)
}
}
newmap[k] = v
}
Expand Down
1 change: 1 addition & 0 deletions tools/convert/ruleconvert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func Test_keysToLowercase(t *testing.T) {
{"one", map[string]any{"A": "b"}, map[string]any{"a": "b"}},
{"two", map[string]any{"A": "b", "C": "d"}, map[string]any{"a": "b", "c": "d"}},
{"recursive", map[string]any{"A": "b", "C": map[string]any{"D": "e"}}, map[string]any{"a": "b", "c": map[string]any{"d": "e"}}},
{"slices", map[string]any{"A": "b", "C": []any{map[string]any{"D": "e"}, "F"}}, map[string]any{"a": "b", "c": []any{map[string]any{"d": "e"}, "F"}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3076db2

Please sign in to comment.