From f80cf4dafa495bc4fd68bbe8cc8639433f8ee0d4 Mon Sep 17 00:00:00 2001 From: "HC Zhu (DB)" Date: Mon, 12 Aug 2024 18:25:43 -0700 Subject: [PATCH] Trunct labels for error messages --- pkg/receive/multitsdb.go | 2 +- pkg/store/labelpb/label.go | 6 +++--- pkg/store/proxy.go | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/receive/multitsdb.go b/pkg/receive/multitsdb.go index 2ac9d10ee67..8fd3aafe7bf 100644 --- a/pkg/receive/multitsdb.go +++ b/pkg/receive/multitsdb.go @@ -141,7 +141,7 @@ func (l *localClient) String() string { mint, maxt := l.store.TimeRange() return fmt.Sprintf( "LabelSets: %v MinTime: %d MaxTime: %d", - labelpb.PromLabelSetsToStringN(l.LabelSets(), 10), mint, maxt, + labelpb.PromLabelSetsToStringN(l.LabelSets(), 10, 100), mint, maxt, ) } diff --git a/pkg/store/labelpb/label.go b/pkg/store/labelpb/label.go index 64312b4d061..301860118b7 100644 --- a/pkg/store/labelpb/label.go +++ b/pkg/store/labelpb/label.go @@ -303,13 +303,13 @@ func ExtendSortedLabels(lset, extend labels.Labels) labels.Labels { } func PromLabelSetsToString(lsets []labels.Labels) string { - return PromLabelSetsToStringN(lsets, 1000000) + return PromLabelSetsToStringN(lsets, 10, 100) } -func PromLabelSetsToStringN(lsets []labels.Labels, maxNumLabels int) string { +func PromLabelSetsToStringN(lsets []labels.Labels, maxNumLabels, maxLabelLength int) string { s := []string{} for _, ls := range lsets { - s = append(s, ls.String()) + s = append(s, ls.String()[:min(maxLabelLength, len(ls.String()))]) maxNumLabels-- if maxNumLabels <= 0 { break diff --git a/pkg/store/proxy.go b/pkg/store/proxy.go index 99365c0963d..f929961b442 100644 --- a/pkg/store/proxy.go +++ b/pkg/store/proxy.go @@ -464,14 +464,16 @@ func (s *ProxyStore) Series(originalRequest *storepb.SeriesRequest, srv storepb. if resp.GetWarning() != "" { totalFailedStores++ - level.Error(s.logger).Log("msg", "Series: warning from store", "warning", resp.GetWarning()) + maxWarningBytes := 2000 + warning := resp.GetWarning()[:min(maxWarningBytes, len(resp.GetWarning()))] + level.Error(s.logger).Log("msg", "Series: warning from store", "warning", warning) if r.PartialResponseStrategy == storepb.PartialResponseStrategy_GROUP_REPLICA { // TODO: attribute the warning to the store(group key and replica key) that produced it. // Each client streams a sequence of time series, so it's not trivial to attribute the warning to a specific client. if totalFailedStores > 1 { level.Error(reqLogger).Log("msg", "more than one stores have failed") // If we don't know which store has failed, we can tolerate at most one failed store. - return status.Error(codes.Aborted, resp.GetWarning()) + return status.Error(codes.Aborted, warning) } } else if r.PartialResponseDisabled || r.PartialResponseStrategy == storepb.PartialResponseStrategy_ABORT { return status.Error(codes.Aborted, resp.GetWarning())