Azure/Insights: Fix handling of none dimension values (#27513)

Properly handle legacy dimension values in the backend.

Fixes #27512
This commit is contained in:
Marcus Efraimsson 2020-09-10 18:21:56 +02:00 committed by GitHub
parent 91a8937e6c
commit e85b266f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -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)
}

View File

@ -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
}