mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
Azure/Insights: Fix handling of none dimension values (#27513)
Properly handle legacy dimension values in the backend. Fixes #27512
This commit is contained in:
parent
91a8937e6c
commit
e85b266f2e
@ -211,6 +211,11 @@ func TestAppInsightsPluginRoutes(t *testing.T) {
|
||||
func TestInsightsDimensionsUnmarshalJSON(t *testing.T) {
|
||||
a := []byte(`"foo"`)
|
||||
b := []byte(`["foo"]`)
|
||||
c := []byte(`["none"]`)
|
||||
d := []byte(`["None"]`)
|
||||
e := []byte("null")
|
||||
f := []byte(`""`)
|
||||
g := []byte(`"none"`)
|
||||
|
||||
var as InsightsDimensions
|
||||
var bs InsightsDimensions
|
||||
@ -223,4 +228,29 @@ func TestInsightsDimensionsUnmarshalJSON(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, []string{"foo"}, []string(bs))
|
||||
|
||||
var cs InsightsDimensions
|
||||
err = json.Unmarshal(c, &cs)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, cs)
|
||||
|
||||
var ds InsightsDimensions
|
||||
err = json.Unmarshal(d, &ds)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, ds)
|
||||
|
||||
var es InsightsDimensions
|
||||
err = json.Unmarshal(e, &es)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, es)
|
||||
|
||||
var fs InsightsDimensions
|
||||
err = json.Unmarshal(f, &fs)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, fs)
|
||||
|
||||
var gs InsightsDimensions
|
||||
err = json.Unmarshal(g, &gs)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, gs)
|
||||
}
|
||||
|
@ -170,7 +170,14 @@ func (s *InsightsDimensions) UnmarshalJSON(data []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s = InsightsDimensions(sa)
|
||||
dimensions := []string{}
|
||||
for _, v := range sa {
|
||||
if v == "none" || v == "None" {
|
||||
continue
|
||||
}
|
||||
dimensions = append(dimensions, v)
|
||||
}
|
||||
*s = InsightsDimensions(dimensions)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user