Skip to content

Commit

Permalink
loki: Sort context keys alphabetically
Browse files Browse the repository at this point in the history
Fixes #12293

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
  • Loading branch information
monstermunchkin committed Sep 22, 2023
1 parent 2d84817 commit dd4766f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lxd/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,19 @@ func (c *Client) HandleEvent(event api.Event) {
}
}

keys := make([]string, len(context))

for k := range context {
keys = append(keys, k)
}

sort.Strings(keys)

messagePrefix := ""

// Add the remaining context as the message prefix.
for k, v := range context {
messagePrefix += fmt.Sprintf("%s=\"%s\" ", k, v)
// Add the remaining context as the message prefix. The keys are sorted alphabetically.
for _, k := range keys {
messagePrefix += fmt.Sprintf("%s=\"%s\" ", k, context[k])
}

entry.Line = fmt.Sprintf("%s%s", messagePrefix, logEvent.Message)
Expand Down

0 comments on commit dd4766f

Please sign in to comment.