Skip to content

Commit 53350f3

Browse files
authored
Fix custom panel marshalling to be idempotent (#216)
1 parent 5c2631a commit 53350f3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

panel.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/json"
2525
"errors"
2626
"fmt"
27+
"sort"
2728
)
2829

2930
// Each panel may be one of these types.
@@ -1209,11 +1210,18 @@ func (c customPanelOutput) MarshalJSON() ([]byte, error) {
12091210
// Append custom keys to marshalled CommonPanel.
12101211
buf := bytes.NewBuffer(b[:len(b)-1])
12111212

1212-
for k, v := range c.CustomPanel {
1213+
// Sort keys to make output idempotent
1214+
keys := make([]string, 0, len(c.CustomPanel))
1215+
for k := range c.CustomPanel {
1216+
keys = append(keys, k)
1217+
}
1218+
sort.Strings(keys)
1219+
1220+
for _, k := range keys {
12131221
buf.WriteString(`,"`)
12141222
buf.WriteString(k)
12151223
buf.WriteString(`":`)
1216-
b, err := json.Marshal(v)
1224+
b, err := json.Marshal(c.CustomPanel[k])
12171225
if err != nil {
12181226
return b, err
12191227
}

0 commit comments

Comments
 (0)