PCA Querying & Visualization 3 — Questions and Answers
Question 1: What is the difference between `sum by (job)` and `sum without (instance)` when other labels are `job` and `instance`?
- They always produce identical results
- `sum by (job)` keeps only the `job` label; `sum without (instance)` also keeps `job` but drops `instance` — same result here (Correct answer)
- `sum by (job)` drops all labels; `sum without (instance)` keeps all labels
- They differ because `without` cannot be used with `sum`
Correct answer: `sum by (job)` keeps only the `job` label; `sum without (instance)` also keeps `job` but drops `instance` — same result here
When only `job` and `instance` labels exist, both expressions yield the same result — `by (job)` keeps job, and `without (instance)` keeps everything except instance (i.e., job).
Question 2: What does the `topk(3, http_requests_total)` expression return?
- The 3 time series with the highest values at the current moment (Correct answer)
- The top 3 values averaged over the last 5 minutes
- The 3 most frequently scraped targets
- The 3 labels with the highest cardinality
Correct answer: The 3 time series with the highest values at the current moment
`topk(k, expr)` returns the k time series with the largest values at the current evaluation timestamp.
Question 3: What does the binary operator `unless` do in PromQL?
- Returns elements from the left-hand side that have NO matching elements on the right-hand side (Correct answer)
- Returns elements only when the left value is less than the right value
- Filters out elements where the right-hand value is zero
- Performs a logical OR between two vectors
Correct answer: Returns elements from the left-hand side that have NO matching elements on the right-hand side
`unless` returns all elements of the left-hand vector for which there are no matching elements in the right-hand vector.
Question 4: When using `group_left` in a binary operation, what does it signify?
- The left-hand side has more labels and the result keeps all left-hand labels
- The left-hand side has fewer unique label sets (many-to-one matching) (Correct answer)
- The left-hand side is grouped first before matching
- Labels are copied from the right side to the left side result
Correct answer: The left-hand side has fewer unique label sets (many-to-one matching)
`group_left` indicates a many-to-one match where multiple left-side series can match a single right-side series, and optionally copies labels from the right side.
Question 5: What does `count_values("status", http_requests_total)` produce?
- A count of time series grouped by the `status` label
- A new metric with a `status` label containing each unique value and a count of how many series have that value (Correct answer)
- The total number of distinct status label values
- An error because `count_values` requires a range vector
Correct answer: A new metric with a `status` label containing each unique value and a count of how many series have that value
`count_values` groups all time series by their current value, creating a new series per unique value with a label named by the first argument containing that value.
Question 6: In PromQL binary operations, what is the default matching behavior when no `on()` or `ignoring()` clause is specified?
- All labels must match exactly (one-to-one matching on all labels) (Correct answer)
- Only the `__name__` label must match
- Labels are matched by job label only
- No label matching is performed and all series are cross-joined
Correct answer: All labels must match exactly (one-to-one matching on all labels)
By default, PromQL performs one-to-one matching requiring all labels to be identical between the left and right operands.
Question 7: Which aggregation operator would you use to calculate the number of time series that currently have a value greater than 0?
- `sum(metric > 0)`
- `count(metric > 0)` (Correct answer)
- `count_values("val", metric > 0)`
- `group(metric > 0)`
Correct answer: `count(metric > 0)`
`count()` aggregates by counting the number of elements in the resulting vector, so `count(metric > 0)` counts series where the condition is true.
What is the difference between `sum by (job)` and `sum without (instance)` when other labels are `job` and `instance`?