Skip to content

feat(otlp): histogram count limits now configurable - #1913

Merged
lucastemb merged 3 commits into
mainfrom
lt/configure-histogram-count
Jul 23, 2026
Merged

feat(otlp): histogram count limits now configurable#1913
lucastemb merged 3 commits into
mainfrom
lt/configure-histogram-count

Conversation

@lucastemb

Copy link
Copy Markdown
Contributor

What does this PR do?

A brief description of the change being made with this pull request.

Added support for configurable histogram count limits

Motivation

What inspired you to submit this pull request?

A failing CI job when updating the lading version in Agent Data Plane exposed a small bug caused by the Core Agent. Although counts are required to be positive, they are stored as i64. Previously, lading could produce count sizes up to u64, which would cause overflows, and subsequently, negative numbers. To mitigate this, we now allow configuration of histogram count fields to ensure the invariant that count >= 0 holds true.

Related issues

A list of issues either fixed, containing architectural discussions, otherwise relevant
for this Pull Request.

Additional Notes

Anything else we should know when reviewing?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83fe5ee4e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// Define the contexts available when generating metrics
pub contexts: Contexts,
/// Defines generation limits for histogram count fields.
pub histogram_count_limits: HistogramCountLimits,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add defaults to remaining Config literals

Adding this non-defaulted field makes existing Config literal construction non-exhaustive. I checked the repo validation path: ci/clippy runs cargo clippy --all-targets --all-features, which compiles benches, and cargo check --locked --all-features --benches -p lading-payload now fails at lading_payload/benches/opentelemetry_metric.rs:18 and :48 with missing histogram_count_limits, so the validation suite cannot pass until those literals use ..Default::default() or set the new field.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 28ae4d7

.min(self.histogram_count_limits.zero);
let positive_count =
point.positive.as_mut().map_or(0, |positive| {
randomize_exp_bucket_counts(positive, rng)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply bucket limits to delta exponential buckets

When histogram_count_limits.bucket is configured below 10, delta exponential histograms still call randomize_exp_bucket_counts, whose buckets are sampled from 0..=10 without applying the configured bucket cap. The explicit-histogram delta path and cumulative exponential path do cap buckets, so generated positive and negative exponential bucket counts can exceed the new maximum for this metric kind.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would like to say it's very unlikely that anyone would manually want configure the bucket limit to below 10 when the default is u32::MAX, but nonetheless, a safeguard has been implemented in 28ae4d7

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28ae4d723b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +689 to +692
point.count = checked_count_sum(
point.bucket_counts.iter().copied(),
self.histogram_count_limits.total,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve histogram count consistency

When histogram_count_limits.total is configured below the generated bucket sum, this caps point.count while leaving bucket_counts unchanged (for example total: 1 still leaves every explicit bucket sampled from 1..=10). The emitted OTLP histogram then reports a total count that is smaller than sum(bucket_counts), breaking the histogram invariant already asserted later in histograms_populate_min_max; the exponential paths have the same issue for zero_count + positive + negative.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be preferable to prevent users from setting absurdly low limits or options that break the invariants we've established dc83369

@lucastemb
lucastemb merged commit 6577087 into main Jul 23, 2026
31 checks passed
@lucastemb
lucastemb deleted the lt/configure-histogram-count branch July 23, 2026 14:38
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