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 d65e542
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 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(), 1000), mint, maxt,
)
}

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

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

func PromLabelSetsToStringN(lsets []labels.Labels, maxNumLabels int) string {
func PromLabelSetsToStringN(lsets []labels.Labels, maxLength int) string {
if len(lsets) == 0 {
return ""
}
s := []string{}
maxLabelLength := (maxLength + min(10, len(lsets)) - 1) / min(10, len(lsets))
for _, ls := range lsets {
s = append(s, ls.String())
maxNumLabels--
if maxNumLabels <= 0 {
break
}
s = append(s, ls.String()[:min(maxLabelLength, len(ls.String()))])
}
sort.Strings(s)
return strings.Join(s, ",")
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 d65e542

Please sign in to comment.