From dd0df7a99c57bac12ac4e3212b81e5545b80f965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E5=AE=9D=E7=9F=B3=E7=9A=84=E5=82=BB=E8=AF=9D?= Date: Mon, 10 Apr 2023 16:03:36 +0800 Subject: [PATCH] truncateExtLabels support Unicode cut --- pkg/query/endpointset.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/query/endpointset.go b/pkg/query/endpointset.go index 36f6d389fea..dfd3ec83906 100644 --- a/pkg/query/endpointset.go +++ b/pkg/query/endpointset.go @@ -11,6 +11,7 @@ import ( "sort" "sync" "time" + "unicode/utf8" "github.com/thanos-io/thanos/pkg/api/query/querypb" @@ -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 }