@@ -22,6 +22,8 @@ import (
2222 "time"
2323
2424 timestamp_pb "github.com/golang/protobuf/ptypes/timestamp"
25+ "github.com/go-kit/kit/log"
26+ "github.com/go-kit/kit/log/level"
2527 "github.com/pkg/errors"
2628 "github.com/prometheus/prometheus/pkg/textparse"
2729 "github.com/prometheus/tsdb"
@@ -31,6 +33,7 @@ import (
3133)
3234
3335type sampleBuilder struct {
36+ logger log.Logger
3437 series seriesGetter
3538}
3639
@@ -39,10 +42,7 @@ type sampleBuilder struct {
3942func (b * sampleBuilder ) next (ctx context.Context , samples []tsdb.RefSample ) (* monitoring_pb.TimeSeries , uint64 , []tsdb.RefSample , error ) {
4043 sample := samples [0 ]
4144
42- entry , ok , err := b .series .get (ctx , sample .Ref )
43- if err != nil {
44- return nil , 0 , samples , errors .Wrap (err , "get series information" )
45- }
45+ entry , ok := b .seriesGetWithRetry (ctx , sample )
4646 if ! ok {
4747 return nil , 0 , samples [1 :], nil
4848 }
@@ -57,6 +57,7 @@ func (b *sampleBuilder) next(ctx context.Context, samples []tsdb.RefSample) (*mo
5757 }
5858 ts .Points = append (ts .Points , point )
5959
60+ var err error
6061 var resetTimestamp int64
6162
6263 switch entry .metadata .Type {
@@ -120,6 +121,23 @@ func (b *sampleBuilder) next(ctx context.Context, samples []tsdb.RefSample) (*mo
120121 return & ts , entry .hash , samples [1 :], nil
121122}
122123
124+ func (b * sampleBuilder ) seriesGetWithRetry (ctx context.Context , sample tsdb.RefSample ) (* seriesCacheEntry , bool ) {
125+ backoff := time .Duration (0 )
126+ entry , ok , err := b .series .get (ctx , sample .Ref )
127+ for {
128+ if err == nil {
129+ break
130+ }
131+ level .Warn (b .logger ).Log ("msg" , "failed to get seriesCacheEntry" , "err" , err )
132+ backoff = exponential (backoff )
133+ if backoff > 0 {
134+ time .Sleep (backoff )
135+ }
136+ entry , ok , err = b .series .get (ctx , sample .Ref )
137+ }
138+ return entry , ok
139+ }
140+
123141const (
124142 metricSuffixBucket = "_bucket"
125143 metricSuffixSum = "_sum"
@@ -198,10 +216,7 @@ func (b *sampleBuilder) buildDistribution(
198216 // until we hit a new metric.
199217Loop:
200218 for i , s := range samples {
201- e , ok , err := b .series .get (ctx , s .Ref )
202- if err != nil {
203- return nil , 0 , samples , err
204- }
219+ e , ok := b .seriesGetWithRetry (ctx , s )
205220 if ! ok {
206221 consumed ++
207222 // TODO(fabxc): increment metric.
@@ -337,3 +352,18 @@ func histogramLabelsEqual(a, b tsdbLabels.Labels) bool {
337352 // If one label set still has labels left, they are not equal.
338353 return i == len (a ) && j == len (b )
339354}
355+
356+ func exponential (d time.Duration ) time.Duration {
357+ const (
358+ min = 10 * time .Millisecond
359+ max = 2 * time .Second
360+ )
361+ d *= 2
362+ if d < min {
363+ d = min
364+ }
365+ if d > max {
366+ d = max
367+ }
368+ return d
369+ }
0 commit comments