mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Azure: Handle real type nan/inf values in Log/Insights Analytics (#26342)
Before this, if the user were to divide by 0.0, "Infinity" would be returned in the result and the user would get an error: "unexpected type, expected json.Number but got string". Now these values are properly set as Inf values (and also made sure to handle NaN as well).
This commit is contained in:
parent
3fd810417f
commit
590702c497
@ -3,6 +3,7 @@ package azuremonitor
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -115,7 +116,21 @@ var realConverter = data.FieldConverter{
|
||||
}
|
||||
jN, ok := v.(json.Number)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected type, expected json.Number but got %T", v)
|
||||
s, sOk := v.(string)
|
||||
if sOk {
|
||||
switch s {
|
||||
case "Infinity":
|
||||
f := math.Inf(0)
|
||||
return &f, nil
|
||||
case "-Infinity":
|
||||
f := math.Inf(-1)
|
||||
return &f, nil
|
||||
case "NaN":
|
||||
f := math.NaN()
|
||||
return &f, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected type, expected json.Number but got type %T for value %v", v, v)
|
||||
}
|
||||
f, err := jN.Float64()
|
||||
if err != nil {
|
||||
|
@ -2,6 +2,7 @@ package azuremonitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -119,6 +120,21 @@ func TestLogTableToFrame(t *testing.T) {
|
||||
return frame
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nan and infinity in real response",
|
||||
testFile: "loganalytics/8-log-analytics-response-nan-inf.json",
|
||||
expectedFrame: func() *data.Frame {
|
||||
frame := data.NewFrame("",
|
||||
data.NewField("XInf", nil, []*float64{pointer.Float64(math.Inf(0))}),
|
||||
data.NewField("XInfNeg", nil, []*float64{pointer.Float64(math.Inf(-2))}),
|
||||
data.NewField("XNan", nil, []*float64{pointer.Float64(math.NaN())}),
|
||||
)
|
||||
frame.Meta = &data.FrameMeta{
|
||||
Custom: &LogAnalyticsMeta{ColumnTypes: []string{"real", "real", "real"}},
|
||||
}
|
||||
return frame
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
29
pkg/tsdb/azuremonitor/testdata/loganalytics/8-log-analytics-response-nan-inf.json
vendored
Normal file
29
pkg/tsdb/azuremonitor/testdata/loganalytics/8-log-analytics-response-nan-inf.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"tables": [
|
||||
{
|
||||
"name": "PrimaryResult",
|
||||
"columns": [
|
||||
{
|
||||
"name": "XInf",
|
||||
"type": "real"
|
||||
},
|
||||
{
|
||||
"name": "XInfNeg",
|
||||
"type": "real"
|
||||
},
|
||||
{
|
||||
"name": "XNan",
|
||||
"type": "real"
|
||||
}
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
"Infinity",
|
||||
"-Infinity",
|
||||
"NaN"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user