Skip to content

Commit

Permalink
Merge pull request #11 from riemann/feat/int32-metric-type
Browse files Browse the repository at this point in the history
Add Int32 support for the metric field
  • Loading branch information
mcorbin authored Apr 6, 2017
2 parents 1f8ee67 + 87df24c commit 0f94ab1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func EventToProtocolBuffer(event *Event) (*proto.Event, error) {
}

switch reflect.TypeOf(event.Metric).Kind() {
case reflect.Int, reflect.Int64:
case reflect.Int, reflect.Int32, reflect.Int64:
e.MetricSint64 = pb.Int64((reflect.ValueOf(event.Metric).Int()))
case reflect.Float32:
e.MetricD = pb.Float64((reflect.ValueOf(event.Metric).Float()))
Expand Down
27 changes: 25 additions & 2 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

func TestEventToProtocolBuffer(t *testing.T) {
// simple event, metric int
// simple event, metric int32
var m int32 = 100
event := Event{
Host: "baz",
Service: "foobar",
Metric: 100,
Metric: m,
Tags: []string{"hello"},
Time: 100,
}
Expand All @@ -29,6 +30,28 @@ func TestEventToProtocolBuffer(t *testing.T) {
if !pb.Equal(protoRes, &protoTest) {
t.Error("Error during event to protobuf conversion")
}
// simple event, metric int
event = Event{
Host: "baz",
Service: "foobar",
Metric: 100,
Tags: []string{"hello"},
Time: 100,
}
protoRes, error = EventToProtocolBuffer(&event)
if error != nil {
t.Error("Error during EventToProtocolBuffer")
}
protoTest = proto.Event{
Host: pb.String("baz"),
Time: pb.Int64(100),
MetricSint64: pb.Int64(100),
Service: pb.String("foobar"),
Tags: []string{"hello"},
}
if !pb.Equal(protoRes, &protoTest) {
t.Error("Error during event to protobuf conversion")
}
// event with attributes, metric float
event = Event{
Host: "baz",
Expand Down

0 comments on commit 0f94ab1

Please sign in to comment.