PCA Querying & Visualization 2 — Questions and Answers
Question 1: What does the `rate()` function calculate when applied to a counter metric?
- The total accumulated value over the range
- The per-second average rate of increase over the range window (Correct answer)
- The instantaneous rate using only the last two samples
- The maximum value observed in the range window
Correct answer: The per-second average rate of increase over the range window
`rate()` calculates the per-second average rate of increase of a counter over the specified time range window.
Question 2: What is the key difference between `irate()` and `rate()` in PromQL?
- `irate()` works on gauges while `rate()` works on counters
- `irate()` uses only the last two data points while `rate()` averages across the full range (Correct answer)
- `irate()` returns total increase while `rate()` returns a per-second value
- `irate()` handles resets differently and ignores them entirely
Correct answer: `irate()` uses only the last two data points while `rate()` averages across the full range
`irate()` calculates the instantaneous rate using only the last two samples in the range, making it more responsive to sudden spikes than `rate()`.
Question 3: What does the `increase()` function return for a counter over a given range vector?
- The per-second rate of increase
- The total increase in the counter value over the time range (Correct answer)
- The number of times the counter was incremented
- The difference between the maximum and minimum values
Correct answer: The total increase in the counter value over the time range
`increase()` returns the total increase in a counter's value over the specified range, accounting for counter resets.
Question 4: Which label matcher in PromQL uses a regular expression to match label values?
- `=`
- `!=`
- `=~` (Correct answer)
- `!~`
Correct answer: `=~`
The `=~` matcher selects labels matching a provided regular expression, while `!~` selects labels that do NOT match the regex.
Question 5: What does `absent(up{job="myapp"})` return when the time series EXISTS?
- An empty vector (no data) (Correct answer)
- A vector with value 1
- A vector with value 0
- An error is thrown
Correct answer: An empty vector (no data)
`absent()` returns an empty vector when the input time series exists, and returns a vector with value 1 only when the series is missing.
Question 6: What result type does the expression `http_requests_total[5m]` produce?
- Instant vector
- Range vector (Correct answer)
- Scalar
- String
Correct answer: Range vector
Using a duration in square brackets creates a range vector, which contains a set of time series with a range of data points over the specified time window.
Question 7: Which PromQL function would you use to predict a gauge's value 1 hour from now based on recent trends?
- `delta()`
- `deriv()`
- `predict_linear()` (Correct answer)
- `forecast()`
Correct answer: `predict_linear()`
`predict_linear(v range-vector, t scalar)` predicts the value t seconds from now using linear regression on the range vector.
What does the `rate()` function calculate when applied to a counter metric?