Skip to content

Commit

Permalink
truncateExtLabels support Unicode cut
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyzzc committed Apr 10, 2023
1 parent 1f16d08 commit dd0df7a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/query/endpointset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"sync"
"time"
"unicode/utf8"

"github.com/thanos-io/thanos/pkg/api/query/querypb"

Expand Down Expand Up @@ -218,7 +219,13 @@ func newEndpointSetNodeCollector(labels ...string) *endpointSetNodeCollector {
// truncateExtLabels truncates the stringify external labels with the format of {labels..}.
func truncateExtLabels(s string, threshold int) string {
if len(s) > threshold {
return fmt.Sprintf("%s}", s[:threshold-1])
for cut := 1; cut < 4; cut++ {
for cap := 1; cap < 4; cap++ {
if utf8.ValidString(s[threshold-cut-cap : threshold-cut]) {
return fmt.Sprintf("%s}", s[:threshold-cut])
}
}
}
}
return s
}
Expand Down

0 comments on commit dd0df7a

Please sign in to comment.