8000 docs: clarify and expand binary operations documentation by charleskorn · Pull Request #16716 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: clarify and expand binary operations documentation #16716

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

charleskorn
Copy link
Contributor

This PR clarifies the documentation for binary operations, based on the discussions in #15471 and #16631.

It also reformats some longer paragraphs into smaller pieces for easier reading.

I've made each change as a separate commit, and I'd suggest reviewing each separately.

Signed-off-by: Charles Korn <charles.korn@grafana.com>
Based on discussion in prometheus#15471

Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charles.korn@grafana.com>
See prometheus#16631

Signed-off-by: Charles Korn <charles.korn@grafana.com>
Copy link
Member
@juliusv juliusv left a comment

Choose a reason for hiding this comment

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

Looks great, just a few nits.

the original vector is multiplied by 2.

For vector elements that are histogram samples, the behavior is the
following:
Copy link
Member

Choose a reason for hiding this comment

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

We've had problems in the past with Markdown formatting (depending on MD preprocessing environment) not working when there is no empty line before a list. Let's add an empty line before the list just to be safe.

by the scalar on the right hand side (RHS). All bucket populations and the count
and the sum of observations are then divided by the scalar. A division by zero
results in a histogram with no regular buckets and the zero bucket population
and the count and sum of observations all set to +Inf, -Inf, or NaN, depending
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
and the count and sum of observations all set to +Inf, -Inf, or NaN, depending
and the count and sum of observations all set to `+Inf`, `-Inf`, or `NaN`, depending

(we do this above for these special values as well)

and the sum of observations are then divided by the scalar. A division by zero
results in a histogram with no regular buckets and the zero bucket population
and the count and sum of observations all set to +Inf, -Inf, or NaN, depending
on their values in the input histogram (positive, negative, or zero/NaN, respectively).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
on their values in the input histogram (positive, negative, or zero/NaN, respectively).
on their values in the input histogram (positive, negative, or zero/`NaN`, respectively).

adding or substracting all matching bucket populations and the count and the
entry in the right-hand vector can be found are not part of the result.

If two float samples are matched, the behavior is obvious.
Copy link
Member
@juliusv juliusv Jun 30, 2025

Choose a reason for hiding this comment

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

I would like to avoid too much use of the word "obvious" in documentation, especially for people who are already overwhelmed and don't feel that things are obvious (it's too subjective) :) How about something more like:

Suggested change
If two float samples are matched, the behavior is obvious.
If two float samples are matched, the result sample value is generated by applying the binary operator to the two input values in a straightforward way.

have the value `1`. Additionally, the metric name is dropped. (Note that
invalid operations involving histogram samples still return no result rather
than the value `0`.)
modifier changes the behavior in the following ways:
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here about adding an empty line before the Markdown list.

sum of observations. All other operations result in the removal of the
corresponding element from the output vector, flagged by an info-level
annotation.

**In any arithmetic binary operation involving vectors**, the metric name is
dropped.
dropped unless it is explicitly mentioned in `on`.
Copy link
Member

Choose a reason for hiding this comment

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

This is still false, right? Since we decided to not change the current behavior of dropping the metric name even when it's mentioned in an on() clause, see #16631 (comment)

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
0