Skip to content

Commit

Permalink
Fix utf8 metric panic, fix startup panic when memberlist is still not…
Browse files Browse the repository at this point in the history
… populated
  • Loading branch information
germanoeich committed May 2, 2022
1 parent eb19fe8 commit 0483b1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/bucketpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"strings"
"time"
"unicode/utf8"
)

const (
Expand Down Expand Up @@ -54,6 +55,11 @@ func GetMetricsPath(route string) string {
}
}

if !utf8.ValidString(path) {
logger.Warn("Non utf-8 path detected, Prometheus only supports utf-8, invalid runes will be replaced with @ in metrics. Path: " + path)
path = strings.ToValidUTF8(path, "@")
}

return path
}

Expand Down
2 changes: 2 additions & 0 deletions lib/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func doDiscordReq(ctx context.Context, path string, method string, body io.ReadC
status = "429 Shared"
}
}


RequestHistogram.With(map[string]string{"route": route, "status": status, "method": method, "clientId": identifier.(string)}).Observe(elapsed)
}
return discordResp, err
Expand Down
4 changes: 4 additions & 0 deletions lib/queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (m *QueueManager) calculateRoute(pathHash uint64) string {
members := m.orderedClusterMembers
count := uint64(len(members))

if count == 0 {
return ""
}

chosenIndex := pathHash % count
addr := m.nameToAddressMap[members[chosenIndex]]
if addr == m.localNodeProxyListenAddr {
Expand Down

0 comments on commit 0483b1d

Please sign in to comment.