Skip to content

Commit

Permalink
Trunct labels for error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hczhu-db committed Aug 13, 2024
1 parent 936f992 commit 70eae10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(), 500), mint, maxt,
)
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/store/labelpb/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ func ExtendSortedLabels(lset, extend labels.Labels) labels.Labels {
}

func PromLabelSetsToString(lsets []labels.Labels) string {
return PromLabelSetsToStringN(lsets, 1000000)
return PromLabelSetsToStringN(lsets, 500)
}

func PromLabelSetsToStringN(lsets []labels.Labels, maxNumLabels int) string {
func PromLabelSetsToStringN(lsets []labels.Labels, maxLength int) string {
if len(lsets) == 0 {
return ""
}
s := []string{}
for _, ls := range lsets {
s = append(s, ls.String())
maxNumLabels--
if maxNumLabels <= 0 {
maxLength -= len(ls.String())
if maxLength <= 0 {
break
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/store/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 70eae10

Please sign in to comment.