Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions asap-tools/experiments/datasets/fake_metric/generate_workloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,23 @@ def extrapolated_rate(cols: str, table: str, window: int, is_rate: bool) -> str:
f"FROM {table} WHERE ts > {END} - {window} AND ts <= {END} "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two contradictory "Prometheus 2.53" window conventions now coexist. This file uses left-open ts > END - window; sketch_bench_workloads.py uses closed [T-d, T] for the same Prometheus version. With 1s whole-second scrapes a [1m] query reads 60 samples here vs 61 there, so sum/count/quantile and rate extrapolation (first_t/to_start) diverge. Suggest one shared window helper. (Anchored here; the select() at line ~60 has the same predicate.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prometheus 2.x range selectors are closed, [T−d, T]; left-open arrived in 3.0. So this PR is correct and generated2 is off by one sample. Changing generated2 (merged in #837) changes its results, so it gets its own PR rather than going into this one: #867. generated2's ts is DateTime, so the fix there is just > → >=.

f"GROUP BY {cols} HAVING n >= 2"
)
return rate_from_samples(cols, samples, END, window, is_rate)


def rate_from_samples(
cols: str, samples: str, end: str, window: int, is_rate: bool
) -> str:
"""extrapolatedRate over `samples`, a query yielding per series `cols`,
first_v, last_v, first_t, last_t (unix seconds) and n >= 2 samples in the
window of `window` seconds ending at `end`."""
durations = (
f"SELECT {cols}, last_v - first_v AS delta, first_v, "
f"last_t - first_t AS sampled, sampled / (n - 1) AS avg_step, "
f"if(first_t - ({END} - {window}) >= 1.1 * avg_step, avg_step / 2, "
f"first_t - ({END} - {window})) AS to_start_clamped, "
f"if(first_t - ({end} - {window}) >= 1.1 * avg_step, avg_step / 2, "
f"first_t - ({end} - {window})) AS to_start_clamped, "
f"if(delta > 0 AND first_v >= 0, "
f"least(to_start_clamped, sampled * first_v / delta), to_start_clamped) AS to_start, "
f"if({END} - last_t >= 1.1 * avg_step, avg_step / 2, {END} - last_t) AS to_end "
f"if({end} - last_t >= 1.1 * avg_step, avg_step / 2, {end} - last_t) AS to_end "
f"FROM ({samples})"
)
per_second = f" / {window}" if is_rate else ""
Expand Down
Loading
Loading