Skip to content

Commit c16c0dd

Browse files
authored
Truncate labels for error messages (#71)
2 parents 936f992 + 70eae10 commit c16c0dd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

pkg/receive/multitsdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (l *localClient) String() string {
141141
mint, maxt := l.store.TimeRange()
142142
return fmt.Sprintf(
143143
"LabelSets: %v MinTime: %d MaxTime: %d",
144-
labelpb.PromLabelSetsToStringN(l.LabelSets(), 10), mint, maxt,
144+
labelpb.PromLabelSetsToStringN(l.LabelSets(), 500), mint, maxt,
145145
)
146146
}
147147

pkg/store/labelpb/label.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,18 @@ func ExtendSortedLabels(lset, extend labels.Labels) labels.Labels {
303303
}
304304

305305
func PromLabelSetsToString(lsets []labels.Labels) string {
306-
return PromLabelSetsToStringN(lsets, 1000000)
306+
return PromLabelSetsToStringN(lsets, 500)
307307
}
308308

309-
func PromLabelSetsToStringN(lsets []labels.Labels, maxNumLabels int) string {
309+
func PromLabelSetsToStringN(lsets []labels.Labels, maxLength int) string {
310+
if len(lsets) == 0 {
311+
return ""
312+
}
310313
s := []string{}
311314
for _, ls := range lsets {
312315
s = append(s, ls.String())
313-
maxNumLabels--
314-
if maxNumLabels <= 0 {
316+
maxLength -= len(ls.String())
317+
if maxLength <= 0 {
315318
break
316319
}
317320
}

pkg/store/proxy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,16 @@ func (s *ProxyStore) Series(originalRequest *storepb.SeriesRequest, srv storepb.
464464

465465
if resp.GetWarning() != "" {
466466
totalFailedStores++
467-
level.Error(s.logger).Log("msg", "Series: warning from store", "warning", resp.GetWarning())
467+
maxWarningBytes := 2000
468+
warning := resp.GetWarning()[:min(maxWarningBytes, len(resp.GetWarning()))]
469+
level.Error(s.logger).Log("msg", "Series: warning from store", "warning", warning)
468470
if r.PartialResponseStrategy == storepb.PartialResponseStrategy_GROUP_REPLICA {
469471
// TODO: attribute the warning to the store(group key and replica key) that produced it.
470472
// Each client streams a sequence of time series, so it's not trivial to attribute the warning to a specific client.
471473
if totalFailedStores > 1 {
472474
level.Error(reqLogger).Log("msg", "more than one stores have failed")
473475
// If we don't know which store has failed, we can tolerate at most one failed store.
474-
return status.Error(codes.Aborted, resp.GetWarning())
476+
return status.Error(codes.Aborted, warning)
475477
}
476478
} else if r.PartialResponseDisabled || r.PartialResponseStrategy == storepb.PartialResponseStrategy_ABORT {
477479
return status.Error(codes.Aborted, resp.GetWarning())

0 commit comments

Comments
 (0)