Skip to content

docs: follow-up fixes for collect() generator examples (#1169)#1172

Merged
csmarchbanks merged 2 commits intoprometheus:masterfrom
k1chik:fix/1169-collect-generator-context
May 4, 2026
Merged

docs: follow-up fixes for collect() generator examples (#1169)#1172
csmarchbanks merged 2 commits intoprometheus:masterfrom
k1chik:fix/1169-collect-generator-context

Conversation

@k1chik
Copy link
Copy Markdown
Contributor

@k1chik k1chik commented May 4, 2026

@csmarchbanks

Three issues raised in review of #1169 by @calestyo:

  1. The API Reference code examples used bare yield statements without
    any surrounding def collect(self): context, making it unclear what
    they belonged to. Added a preamble to the API Reference section
    pointing back to the top-level example.

  2. The InfoMetricFamily example had two yield statements in a single
    block, which looked like one collect() yielding both patterns rather
    than two alternatives. Split into separate labelled blocks.

  3. The collect() protocol section gave no explanation for why generators
    are used. Added a note explaining that yield is idiomatic (lazy
    iteration, no intermediate list) and that each scrape gets a fresh call
    with no state carried over.

k1chik added 2 commits May 4, 2026 10:48
…text

Add a note to the collect() protocol section explaining that yield is idiomatic
(generator iterates lazily, no state between scrapes) and a preamble to the API
Reference section clarifying that code snippets belong inside a collect() method.

Follows up on review feedback in prometheus#1169.

Signed-off-by: k1chik <kkukdia@gmail.com>
The single block with two yield statements looked like one collect() yielding
both patterns. Split into labelled prose + code pairs to make clear they are
alternatives, not sequential yields.

Signed-off-by: k1chik <kkukdia@gmail.com>
Copy link
Copy Markdown
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Thanks!

@csmarchbanks csmarchbanks merged commit 2c84c2a into prometheus:master May 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants