signalfx / signalfx-go

Go client library and instrumentation bindings for SignalFx
https://www.signalfx.com
Apache License 2.0
14 stars 48 forks source link

payload.Float64() returns -Infinity #116

Closed stevenvachon closed 3 years ago

stevenvachon commented 3 years ago

For this SignalFlow query:

data('memory.used', filter=(not filter('agent', '*'))).count().publish()

It works fine when I use Int64(), though. So for now, I'm using Value() with type assertions to consistently return a float64:

v := float64(0)
plv := pl.Value()
if i32, ok := plv.(int32); ok {
  v = float64(i32)
} else if i64, ok := plv.(int64); ok {
  v = float64(i64)
} else if f, ok := plv.(float64); ok {
  v = f
}
// ignored nil type, as dealing with it is currently an unknown
keitwb commented 3 years ago

What you are doing is probably the easiest way to handle it. When you call pl.Float64() on a payload with pl.DataType != messages.ValTypeDouble then it will interpret the bytes as a double even though they are supposed to be interpreted as an integer, which results in the meaningless value. You could also switch on the pl.Type field, but what you did is slightly simpler. I suppose it could panic in the accessors if the data type was wrong to prevent bad data, but using the Value() method and type switching it is definitely the way to go.