Skip to content

Commit

Permalink
Add support for building sample keys from integer fields (#304)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
If an dynamic sampler is configured to user an event field that is an int, not int64, the field is ignored. This can lead to inconsistent dynamic keys being used.

In the case only integer fields are used, eg a status field, it would result in an key `""`.

## Short description of the changes
- Add support for int field types when building an event key to use with the dynamic sampler
- Add unit test
  • Loading branch information
MikeGoldsmith authored Nov 16, 2022
1 parent d68d2d6 commit d9aa587
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion processors/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ func makeDynSampleKey(ev *event.Event, keys []string) string {
switch val := val.(type) {
case bool:
key[i] = strconv.FormatBool(val)
case int:
key[i] = strconv.Itoa(val)
case int64:
key[i] = strconv.FormatInt(val, 10)
case float64:

key[i] = strconv.FormatFloat(val, 'E', -1, 64)
case string:
key[i] = val
Expand Down
17 changes: 17 additions & 0 deletions processors/sample_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package processors

import (
"testing"

"github.com/honeycombio/honeycomb-kubernetes-agent/event"
"github.com/stretchr/testify/assert"
)

func TestSamplerCanBuildsKeysWithInts(t *testing.T) {
key := makeDynSampleKey(&event.Event{
Data: map[string]interface{}{
"status": 200,
},
}, []string { "status"})
assert.Equal(t, "200", key)
}

0 comments on commit d9aa587

Please sign in to comment.