MCPcopy
hub / github.com/grafana/tempo / pollTenantAndCreateIndex

Method pollTenantAndCreateIndex

tempodb/blocklist/poller.go:254–319  ·  view source on GitHub ↗
(
	ctx context.Context,
	tenantID string,
	previous *List,
)

Source from the content-addressed store, hash-verified

252}
253
254func (p *Poller) pollTenantAndCreateIndex(
255 ctx context.Context,
256 tenantID string,
257 previous *List,
258) ([]*backend.BlockMeta, []*backend.CompactedBlockMeta, error) {
259 derivedCtx, span := tracer.Start(ctx, "Poller.pollTenantAndCreateIndex", trace.WithAttributes(attribute.String("tenant", tenantID)))
260 defer span.End()
261
262 // are we a tenant index builder?
263 builder := p.tenantIndexBuilder(tenantID)
264 span.SetAttributes(attribute.Bool("tenant_index_builder", builder))
265 if !builder {
266 metricTenantIndexBuilder.WithLabelValues(tenantID).Set(0)
267
268 i, err := p.reader.TenantIndex(derivedCtx, tenantID)
269 err = p.tenantIndexPollError(i, err)
270 if err == nil {
271 // success! return the retrieved index
272 metricTenantIndexAgeSeconds.WithLabelValues(tenantID).Set(float64(time.Since(i.CreatedAt) / time.Second))
273 level.Info(p.logger).Log("msg", "successfully pulled tenant index", "tenant", tenantID, "createdAt", i.CreatedAt, "metas", len(i.Meta), "compactedMetas", len(i.CompactedMeta))
274
275 span.SetAttributes(attribute.Int("metas", len(i.Meta)))
276 span.SetAttributes(attribute.Int("compactedMetas", len(i.CompactedMeta)))
277 return i.Meta, i.CompactedMeta, nil
278 }
279
280 metricTenantIndexErrors.WithLabelValues(tenantID).Inc()
281 span.RecordError(err)
282
283 // there was an error, return the error if we're not supposed to fallback to polling
284 if !p.cfg.PollFallback {
285 return nil, nil, fmt.Errorf("failed to pull tenant index and no fallback configured: %w", err)
286 }
287
288 // polling fallback is true, log the error and continue in this method to completely poll the backend
289 level.Error(p.logger).Log("msg", "failed to pull bucket index for tenant. falling back to polling", "tenant", tenantID, "err", err)
290 }
291
292 // if we're here then we have been configured to be a tenant index builder OR
293 // there was a failure to pull the tenant index and we are configured to fall
294 // back to polling.
295 metricTenantIndexBuilder.WithLabelValues(tenantID).Set(1)
296 blocklist, compactedBlocklist, err := p.pollTenantBlocks(derivedCtx, tenantID, previous)
297 if err != nil {
298 return nil, nil, fmt.Errorf("failed to poll tenant blocks: %w", err)
299 }
300
301 // everything is happy, write this tenant index
302 level.Info(p.logger).Log("msg", "writing tenant index", "tenant", tenantID, "metas", len(blocklist), "compactedMetas", len(compactedBlocklist))
303 err = p.writer.WriteTenantIndex(ctx, tenantID, blocklist, compactedBlocklist)
304 if err != nil {
305 metricTenantIndexErrors.WithLabelValues(tenantID).Inc()
306 level.Error(p.logger).Log("msg", "failed to write tenant index", "tenant", tenantID, "err", err)
307 }
308
309 if len(blocklist) == 0 && len(compactedBlocklist) == 0 {
310 err := p.deleteTenant(ctx, tenantID)
311 if err != nil {

Callers 1

DoMethod · 0.95

Calls 14

tenantIndexBuilderMethod · 0.95
tenantIndexPollErrorMethod · 0.95
pollTenantBlocksMethod · 0.95
deleteTenantMethod · 0.95
BoolMethod · 0.80
IntMethod · 0.80
StartMethod · 0.65
SetMethod · 0.65
TenantIndexMethod · 0.65
LogMethod · 0.65
IncMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected