Skip to content

MAL: Inf histogram bounds; percentile overflow uses highest finite bound - #14275

Merged
wu-sheng merged 1 commit into
apache:masterfrom
songzhendong:fix/mal-histogram-inf-bucket
Nov 27, 2026
Merged

wu-sheng merged 1 commit into
apache:masterfrom
songzhendong:fix/mal-histogram-inf-bucket

Conversation

@songzhendong

@songzhendong songzhendong commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Behavior change

When a histogram percentile rank lands in the overflow (+Inf / Long.MAX_VALUE) bucket and a finite upper bound exists, AVG/SUM histogram_percentile now returns that highest finite bound instead of Long.MAX_VALUE.

Dashboards or alarms that previously showed ~Long.MAX_VALUE for those ranks will show the last finite le instead. Documented in docs/en/concepts-and-designs/mal.md.

Also in this PR

  • histogram() accepts Prometheus/Java Inf spellings (+Inf / -Inf / Infinity) and maps them to Long.MAX_VALUE / Long.MIN_VALUE.
  • Rejects NaN bucket bounds.
  • Sorts the -Inf dataset key (infinite-) without throwing.

Scope / non-goals

In scope: the behavior change above; Inf parse hardening; unit coverage.

Out of scope: cumulative→interval histogram conversion; merging duplicate Inf aliases in one group; a product sentinel when the histogram has only an overflow bucket (still Long.MAX_VALUE).

Verification

Test plan

  • ParseBucketBoundTest
  • FunctionTest Inf forms
  • AnalyzerHistogramInfTest
  • AVG/SUM percentile overflow and -Inf tests
  • TALExecutionTest overflow expects highest finite bound
  • CI on this head

@wu-sheng

Copy link
Copy Markdown
Member

We don't have Prometheus or OpenMetrics reader anymore. We are mainly on OTLP metrics. Is there any case around that?

@songzhendong

Copy link
Copy Markdown
Contributor Author

The Prometheus scrape reader is not the motivation,
Native OTLP histograms are adapted in OpenTelemetryMetricRequestProcessor.buildBuckets with an overflow bound of Double.POSITIVE_INFINITY. The shared converter then sets le via Double.toString(...), i.e. "Infinity".
Double.parseDouble("Infinity") already succeeds in Java; the NumberFormatException was for Prometheus spellings (+Inf / -Inf), not for that OTLP "Infinity" label.
What still matters for the current OTLP → MAL path is the rest of this change: after histogram() maps the overflow bucket to Long.MAX_VALUE, percentile calculation used to return that sentinel when the rank landed in the overflow bucket. This PR makes it report the highest finite upper bound instead. That affects shipped otel-rules that call .histogram().histogram_percentile(...) (e.g. in otel-rules/oap.yaml) when the rank falls in the overflow bucket.
Accepting +Inf / -Inf covers the same bucket label shape when it arrives that way (and keeps MAL aligned with Prometheus/OpenMetrics spellings); it is not claiming we still run a Prometheus scrape reader.

Comment thread docs/en/changes/changes.md Outdated
* Bump Armeria `1.34.2` → `1.43.1`, and the managed versions of the libraries it is built against to its versions: gRPC `1.80.0` → `1.85.1`, Jackson `2.18.12` → `2.22.4` (jackson-annotations `2.22`, which has no patch versions since `2.20`) and Micrometer `1.16.8` → `1.17.2`. graphql-java stays at `25.2`, though armeria-graphql `1.43.1` is built against `26.1`: graphql-java `26` removed `graphql.schema.idl.DirectiveInfo`, which graphql-java-tools `14.0.1`, its latest release, still uses to build the schema, so the OAP failed to boot on it. Armeria `1.43.1` builds a gRPC stub on the client factory named in the stub's options instead of the one `newClient` is called on, so the Cilium fetcher's stubs fell back to Armeria's default factory and connected without the fetcher's TLS settings, and the fetcher read nothing from a TLS Hubble endpoint; it now names its factory in the options. Armeria `1.43.1` also applies a `tlsCustomizer` after `tlsNoVerify()`, so the Cilium fetcher's CA replaced the trust-all setting and Hubble's certificates failed the host name check. The fetcher now verifies Hubble's certificates against `SW_CILIUM_FETCHER_CA_FILE_PATH`, without checking host names; before, `tlsNoVerify()` won and the CA file was ignored, so a CA file that does not sign Hubble's server certificates no longer connects. jackson-datatype-jsr310, which Armeria pulls, is pinned to the managed Jackson version; it was `2.20.1` beside Jackson `2.18.12`. Transitively, brotli4j moves `1.20.0` → `1.24.0`, micrometer context-propagation `1.2.0` → `1.2.1`, proto-google-common-protos `2.63.2` → `2.64.1` and animal-sniffer-annotations `1.26` → `1.27`, and LatencyUtils is no longer shipped.

#### OAP Server
* Fix MAL `histogram()` / percentile rules failing on Prometheus histogram buckets labeled `le="+Inf"` (or `-Inf`): `Double.parseDouble` rejected those spellings, so the whole expression failed. Accept Prometheus and Java Inf forms and map them to `Long.MAX_VALUE` / `Long.MIN_VALUE`; reject `NaN` bounds. Histogram percentile calculation now sorts the `-Inf` dataset key without throwing, and when a rank lands in the overflow (`+Inf`) bucket it reports the highest finite upper bound instead of `Long.MAX_VALUE`.

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.

The latter change should be in the last part of this change log section. Not first row.

@songzhendong
songzhendong force-pushed the fix/mal-histogram-inf-bucket branch 3 times, most recently from 41d50bd to 4ed692d Compare November 27, 2026 00:24
@wu-sheng

Copy link
Copy Markdown
Member

This kind of statement keeps showing, which this PR title doesn't declare. I feel this means that the last bucket is infinite, you will report different as before. The PR title and description doesn't say this explictly.

Only Not returning Long.MAX_VALUE as a latency when a finite upper bound exists., this is a global change, not just a bug fix, we could say it makes some sense, but we need to evaluate carefully, including doc.

@songzhendong
songzhendong force-pushed the fix/mal-histogram-inf-bucket branch from 4ed692d to 27e4086 Compare November 27, 2026 00:25
@songzhendong songzhendong changed the title Fix MAL histogram() failing on Prometheus le=+Inf buckets MAL: Inf histogram bounds; percentile overflow uses highest finite bound Nov 27, 2026
@songzhendong

Copy link
Copy Markdown
Contributor Author

Thanks for the review.
Updated this PR to make it explicit:

  • Title now leads with the percentile overflow behavior.
  • Description opens with a Behavior change section (no longer returning Long.MAX_VALUE when a finite bound exists).
  • Changelog is marked Behavior change: and moved to the end of the OAP Server section.
  • docs/en/concepts-and-designs/mal.md documents the overflow percentile rule.

@wu-sheng

Copy link
Copy Markdown
Member

Please resolve conflicts for the latest changes.

@wu-sheng wu-sheng added bug Something isn't working and you are sure it's a bug! enhancement Enhancement on performance or codes labels Nov 27, 2026
@wu-sheng wu-sheng added this to the 11.2.0 milestone Nov 27, 2026
@songzhendong
songzhendong force-pushed the fix/mal-histogram-inf-bucket branch from d623527 to 4792ac3 Compare November 27, 2026 02:29
@wu-sheng
wu-sheng force-pushed the fix/mal-histogram-inf-bucket branch from 4792ac3 to b6c0520 Compare November 27, 2026 12:32
@wu-sheng

Copy link
Copy Markdown
Member

@songzhendong I pushed a fix-up and squashed the branch into one commit, with you kept as the author, rebased on the latest master. Please save any local work before you git reset --hard to the new head.

What changed:

  • Conflict: rebased on master and resolved the changes.md conflict; your entry stays at the end of the OAP Server section.
  • TAL docs: they still described the old reading. The percentile row in docs/en/concepts-and-designs/tal.md and the *_percentile note in docs/en/setup/backend/trace-analyzer.md said a rank in the overflow bucket reads 9223372036854775807; they now say it reads the last bound.
  • Alarm impact: after this change no percentile reads above the highest finite bound, so an alarm condition that needs a value above it never fires, such as p99 > 10000 with the TAL buckets, which end at 10000. A reading equal to that bound may also be above it. mal.md, tal.md, trace-analyzer.md and the changelog now say both.
  • Changelog: rewritten for operators and rule authors, without internal names (AVG/SUM, the infinite- dataset key), and with the alarm note.
  • Commit message: the first commit said percentile rules failed for scraped histograms. No receiver scrapes Prometheus text any more, and OTLP labels the overflow bucket Infinity, which already parsed, so the message now describes the behaviour change and the parsing as they are.

wu-sheng
wu-sheng previously approved these changes Nov 27, 2026
Behavior change: a MAL histogram_percentile or TAL percentile rank that
falls in a histogram's overflow (+Inf, Long.MAX_VALUE) bucket now reads
the highest finite bucket bound instead of Long.MAX_VALUE, as Prometheus
histogram_quantile does. A percentile that reads that bound may be above
it, and none reads above it, so an alarm condition that needs a value
above it no longer fires. The MAL, TAL and trace-analyzer docs and the
changelog say so.

histogram() also accepts the +Inf / -Inf / Inf bucket bound spellings
and rejects NaN; the shipped receivers send numbers (OTLP labels the
overflow bucket "Infinity", which already parsed). The percentile
functions sort the negative-infinity bucket key ("infinite-") instead of
failing Long.parseLong on it.
@songzhendong

Copy link
Copy Markdown
Contributor Author

Thanks for the fix-up and the squash — and for keeping me as the author.

I'll save any local work and git reset --hard to the new head so I don't overwrite your changes.

@wu-sheng
wu-sheng merged commit 8bec128 into apache:master Nov 27, 2026
545 of 549 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working and you are sure it's a bug! enhancement Enhancement on performance or codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants