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

ingest storage: record latency in replaying records #8176

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all 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
23 changes: 22 additions & 1 deletion pkg/storage/ingest/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *PartitionReader) run(ctx context.Context) error {
}

func (r *PartitionReader) processNextFetches(ctx context.Context, delayObserver prometheus.Observer) {
fetches := r.client.PollFetches(ctx)
fetches := r.pollFetches(ctx)
r.recordFetchesMetrics(fetches, delayObserver)
r.logFetchErrors(fetches)
fetches = filterOutErrFetches(fetches)
Expand Down Expand Up @@ -336,7 +336,9 @@ func (r *PartitionReader) consumeFetches(ctx context.Context, fetches kgo.Fetche
})

for boff.Ongoing() {
consumeStart := time.Now()
err := r.consumer.consume(ctx, records)
r.metrics.consumeLatency.Observe(time.Since(consumeStart).Seconds())
if err == nil {
break
}
Expand Down Expand Up @@ -571,6 +573,13 @@ func (r *PartitionReader) WaitReadConsistency(ctx context.Context) (returnErr er
return r.consumedOffsetWatcher.Wait(ctx, lastProducedOffset)
}

func (r *PartitionReader) pollFetches(ctx context.Context) kgo.Fetches {
defer func(start time.Time) {
r.metrics.fetchWaitDuration.Observe(time.Since(start).Seconds())
}(time.Now())
return r.client.PollFetches(ctx)
}

type partitionCommitter struct {
services.Service

Expand Down Expand Up @@ -707,10 +716,12 @@ type readerMetrics struct {
recordsPerFetch prometheus.Histogram
fetchesErrors prometheus.Counter
fetchesTotal prometheus.Counter
fetchWaitDuration prometheus.Histogram
strongConsistencyRequests prometheus.Counter
strongConsistencyFailures prometheus.Counter
strongConsistencyLatency prometheus.Histogram
lastConsumedOffset prometheus.Gauge
consumeLatency prometheus.Histogram
kprom *kprom.Metrics
}

Expand Down Expand Up @@ -750,6 +761,16 @@ func newReaderMetrics(partitionID int32, reg prometheus.Registerer) readerMetric
Name: "cortex_ingest_storage_reader_fetches_total",
Help: "Total number of Kafka fetches received by the consumer.",
}),
fetchWaitDuration: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
Name: "cortex_ingest_storage_reader_fetch_wait_duration_seconds",
Help: "How long fetching a batch of records from the kafka client took to complete.",
NativeHistogramBucketFactor: 1.1,
}),
consumeLatency: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
Name: "cortex_ingest_storage_reader_consume_duration_seconds",
Help: "How long a request spent consuming a record batch from Kafka.",
Copy link
Collaborator

@pracucci pracucci May 29, 2024

Choose a reason for hiding this comment

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

[nit] Have you considered rename "request" to "batch" (or something similar) and maybe renaming the metric too? What we track here is the consumption of a batch of fetches.

Same comment applies to fetchWaitDuration metric

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened #8217

NativeHistogramBucketFactor: 1.1,
}),
strongConsistencyRequests: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "cortex_ingest_storage_strong_consistency_requests_total",
Help: "Total number of requests for which strong consistency has been requested.",
Expand Down
Loading