fetchSeed fetches the cluster seed from the object store and try until it succeeds. continueFn allow you to decide if we should continue retrying. Nil means always retry
(ctx context.Context, continueFn func(err error) bool)
| 186 | // fetchSeed fetches the cluster seed from the object store and try until it succeeds. |
| 187 | // continueFn allow you to decide if we should continue retrying. Nil means always retry |
| 188 | func (rep *Reporter) fetchSeed(ctx context.Context, continueFn func(err error) bool) (*ClusterSeed, error) { |
| 189 | var ( |
| 190 | backoff = backoff.New(ctx, rep.conf.Backoff) |
| 191 | readingErr = 0 |
| 192 | ) |
| 193 | for backoff.Ongoing() { |
| 194 | seed, err := rep.readSeedFile(ctx) |
| 195 | if err != nil { |
| 196 | if !errors.Is(err, backend.ErrDoesNotExist) { |
| 197 | readingErr++ |
| 198 | } |
| 199 | level.Debug(rep.logger).Log("msg", "failed to read cluster seed file", "err", err) |
| 200 | if readingErr > attemptNumber { |
| 201 | if errors.Is(err, backend.ErrBadSeedFile) { |
| 202 | level.Debug(rep.logger).Log("msg", "seed file corrupted") |
| 203 | } |
| 204 | } |
| 205 | if continueFn == nil || continueFn(err) { |
| 206 | backoff.Wait() |
| 207 | continue |
| 208 | } |
| 209 | return nil, err |
| 210 | } |
| 211 | return seed, nil |
| 212 | } |
| 213 | return nil, backoff.Err() |
| 214 | } |
| 215 | |
| 216 | // readSeedFile reads the cluster seed file from the object store. |
| 217 | func (rep *Reporter) readSeedFile(ctx context.Context) (*ClusterSeed, error) { |
no test coverage detected