Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics Generator: Max limit on number of failed flushes #4254

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [ENHANCEMENT] Speedup collection of results from ingesters in the querier [#4100](https://github.com/grafana/tempo/pull/4100) (@electron0zero)
* [ENHANCEMENT] Speedup DistinctValue collector and exit early for ingesters [#4104](https://github.com/grafana/tempo/pull/4104) (@electron0zero)
* [ENHANCEMENT] Add disk caching in ingester SearchTagValuesV2 for completed blocks [#4069](https://github.com/grafana/tempo/pull/4069) (@electron0zero)
* [ENHANCEMENT] Add a max flush attempts and metric to the metrics generator [#4254](https://github.com/grafana/tempo/pull/4254) (@joe-elliott)
* [BUGFIX] Replace hedged requests roundtrips total with a counter. [#4063](https://github.com/grafana/tempo/pull/4063) [#4078](https://github.com/grafana/tempo/pull/4078) (@galalen)
* [BUGFIX] Metrics generators: Correctly drop from the ring before stopping ingestion to reduce drops during a rollout. [#4101](https://github.com/grafana/tempo/pull/4101) (@joe-elliott)
* [BUGFIX] Correctly handle 400 Bad Request and 404 Not Found in gRPC streaming [#4144](https://github.com/grafana/tempo/pull/4144) (@mapno)
Expand Down
6 changes: 6 additions & 0 deletions modules/generator/processor/localblocks/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ var (
Name: "flush_queue_size",
Help: "Size of the flush queue",
}, []string{"tenant"})
metricFailedFlushes = promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "failed_flushes_total",
Help: "The total number of failed flushes",
})
)
37 changes: 30 additions & 7 deletions modules/generator/processor/localblocks/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import (

var tracer = otel.Tracer("modules/generator/processor/localblocks")

const timeBuffer = 5 * time.Minute
const (
timeBuffer = 5 * time.Minute
maxFlushAttempts = 100
)

// ProcessorOverrides is just the set of overrides needed here.
type ProcessorOverrides interface {
Expand Down Expand Up @@ -276,16 +279,36 @@ func (p *Processor) flushLoop() {

op := o.(*flushOp)
op.attempts++

if op.attempts > maxFlushAttempts {
_ = level.Error(p.logger).Log("msg", "failed to flush block after max attempts", "tenant", p.tenant, "block", op.blockID, "attempts", op.attempts)

// attempt to delete the block
p.blocksMtx.Lock()
err := p.wal.LocalBackend().ClearBlock(op.blockID, p.tenant)
if err != nil {
_ = level.Error(p.logger).Log("msg", "failed to clear corrupt block", "tenant", p.tenant, "block", op.blockID, "err", err)
}
delete(p.completeBlocks, op.blockID)
p.blocksMtx.Unlock()

continue
}

err := p.flushBlock(op.blockID)
if err != nil {
_ = level.Error(p.logger).Log("msg", "failed to flush a block", "err", err)

_ = level.Info(p.logger).Log("msg", "re-queueing block for flushing", "block", op.blockID, "attempts", op.attempts)
joe-elliott marked this conversation as resolved.
Show resolved Hide resolved
op.at = time.Now().Add(op.backoff())
metricFailedFlushes.Inc()

if _, err := p.flushqueue.Enqueue(op); err != nil {
_ = level.Error(p.logger).Log("msg", "failed to requeue block for flushing", "err", err)
}
delay := op.backoff()
op.at = time.Now().Add(delay)

go func() {
time.Sleep(delay)
if _, err := p.flushqueue.Enqueue(op); err != nil {
_ = level.Error(p.logger).Log("msg", "failed to requeue block for flushing", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we fail to requeue? Should we delete the block as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think no. the only time enqueue can fail is if the queue is stopped:

https://github.com/grafana/tempo/blob/main/pkg/flushqueues/priority_queue.go#L91-L93

in this case the process is shutting down and so we want to keep the block for when it starts back up. we could definitely be more explicit about this tho.

}
}()
}
}
}
Expand Down