Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix YAML config issues #220

Merged
merged 2 commits into from
Mar 11, 2021
Merged
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
25 changes: 25 additions & 0 deletions sample/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ const (
)

func compare(a, b interface{}) (int, bool) {
// a is the tracing data field value. This can be: float64, int64, bool, or string
// b is the Rule condition value. This can be: float64, int64, int, bool, or string
// Note: in YAML config parsing, the Value may be returned as int
// When comparing numeric values, we need to check across the 3 types: float64, int64, and int

if a == nil {
if b == nil {
return equal, true
Expand All @@ -161,6 +166,16 @@ func compare(a, b interface{}) (int, bool) {
switch at := a.(type) {
case int64:
switch bt := b.(type) {
case int:
i := int(at)
switch {
case i < bt:
return less, true
case i > bt:
return more, true
default:
return equal, true
}
case int64:
switch {
case at < bt:
Expand All @@ -183,6 +198,16 @@ func compare(a, b interface{}) (int, bool) {
}
case float64:
switch bt := b.(type) {
case int:
f := float64(bt)
switch {
case at < f:
return less, true
case at > f:
return more, true
default:
return equal, true
}
case int64:
f := float64(bt)
switch {
Expand Down
28 changes: 28 additions & 0 deletions sample/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,34 @@ func TestRules(t *testing.T) {
ExpectedKeep: true,
ExpectedRate: 4,
},
{
Rules: &config.RulesBasedSamplerConfig{
Rule: []*config.RulesBasedSamplerRule{
{
Name: "YAMLintgeaterthan",
SampleRate: 10,
Condition: []*config.RulesBasedSamplerCondition{
{
Field: "test",
Operator: ">",
Value: int(1),
},
},
},
},
},
Spans: []*types.Span{
{
Event: types.Event{
Data: map[string]interface{}{
"test": int64(2),
},
},
},
},
ExpectedKeep: true,
ExpectedRate: 10,
},
}

for _, d := range data {
Expand Down