Skip to content

Add observability for multicursor queue-state resolution loss - #11695

Open
ratdaddy wants to merge 6 commits into
temporalio:mainfrom
ratdaddy:multicursor
Open

Add observability for multicursor queue-state resolution loss#11695
ratdaddy wants to merge 6 commits into
temporalio:mainfrom
ratdaddy:multicursor

Conversation

@ratdaddy

Copy link
Copy Markdown
Contributor

What changed?

Adds metrics for how often and by how much queue slices
fail to narrow their predicate, and how large persisted queue state actually is.

  • queue_slice_pending_keys — histogram, recorded on every narrowing attempt (declined or
    succeeded). This is the distribution queueShrinkPredicateMaxPendingKeys should be sized against.
  • shard_info_size / queue_state_size — histograms recorded when a shard record is actually
    written, giving whole-record and per-category size.
  • queue_state_size_total / queue_slice_count_total — counters paired with the histograms above
    (and with the existing queue_slice_count), so an exact bytes-per-slice ratio is possible.
  • queue_slice_count gains a task_category tag (previously untagged beyond operation).

These are only metrics changes - no behavior changes.

Why?

A slice only narrows its predicate below queueShrinkPredicateMaxPendingKeys (10) pending
namespaces; above that it stays universal and re-reads the whole range every time. Raising that
threshold safely requires knowing the pending-key distribution and the persisted size.
This PR is the baseline for evaluating a follow-on encoding.

There are two counters because this server's tally-backed Prometheus reporter doesn't preserve the
true recorded value when a histogram flushes — it replays each sample as its bucket's upper bound,
so a histogram's _sum has no more precision than its buckets.

How did you test it?

  • built
  • covered by existing tests
  • added new unit test(s)
  • run locally and tested manually (queue_predicate_resolution_loss confirmed live against a local server under forced
    narrowing-decline conditions)

Potential risks

@ratdaddy
ratdaddy requested a review from a team August 20, 2026 22:04
@ratdaddy
ratdaddy requested review from a team as code owners August 20, 2026 22:04
@yycptt yycptt added the reliability-2026 Reliability related changes label Aug 21, 2026

// TODO: this should be generic enough to shrink any predicate type, probably doesn't belong here.
pendingPerKey := s.pendingPerKey
metrics.QueueSlicePendingKeys.With(s.metricsHandler).Record(int64(len(pendingPerKey)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: just calling out that # of remaining keys is not very interesting for slices that's just created.

// The counter is a true accumulator; the histogram's _sum is not, since tally's Prometheus
// reporter replays each sample as its bucket's upper bound, not the recorded value.
metrics.QueueSliceCountHistogram.With(p.metricsHandler).Record(sliceCount, categoryTag)
metrics.QueueSliceCountTotal.With(p.metricsHandler).Record(sliceCount, categoryTag)

@yycptt yycptt Aug 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so basically we want to have a more accurate version of histogram's _sum and we can calculate average?

@yycptt
yycptt enabled auto-merge (squash) August 21, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oss-foundations reliability-2026 Reliability related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants