The ID function in internal/object/object.go creates the sortedTags slice with len(tags) empty fields, before adding len(tags) populated fields.
|
sortedTags := make([]KV, len(tags)) |
|
for k, v := range tags { |
|
sortedTags = append(sortedTags, KV{k, v}) |
|
} |
|
sort.Slice(sortedTags, func(i, j int) bool { return sortedTags[i].K < sortedTags[j].K }) |
|
|
|
for _, kv := range sortedTags { |
|
h.Write([]byte(kv.K)) |
|
h.Write([]byte{0}) |
|
h.Write([]byte(kv.V)) |
|
h.Write([]byte{0}) |
|
} |
This is most likely a bug and the code should be make([]KV, 0, len(tags)) to create the slice with a predefined capacity. However, due to the function warning this is maybe not something we can just fix.
|
// ID generates a stable identifier based on a source ID and tags. |
|
// |
|
// TODO: the return value of this function must be stable like forever |
A simplified demo is available on the Go Playground: https://go.dev/play/p/TtBg3FsIG0e
Thanks to @BastianLedererIcinga for finding this issue while working on a reimplementation on the web side.
The
IDfunction ininternal/object/object.gocreates thesortedTagsslice withlen(tags)empty fields, before addinglen(tags)populated fields.icinga-notifications/internal/object/object.go
Lines 205 to 216 in 710c818
This is most likely a bug and the code should be
make([]KV, 0, len(tags))to create the slice with a predefined capacity. However, due to the function warning this is maybe not something we can just fix.icinga-notifications/internal/object/object.go
Lines 187 to 189 in 710c818
A simplified demo is available on the Go Playground: https://go.dev/play/p/TtBg3FsIG0e
Thanks to @BastianLedererIcinga for finding this issue while working on a reimplementation on the web side.