Repository navigation
VictoriaMetrics: hand-written baseline variant (one stream aggregation or vmalert rule per query) - #291
Draft
zzylol wants to merge 1 commit into
Draft
VictoriaMetrics: hand-written baseline variant (one stream aggregation or vmalert rule per query)#291zzylol wants to merge 1 commit into
zzylol wants to merge 1 commit into
Conversation
…vmalert rules per query) Adds victoriametrics.hand-written, what an experienced user writes by hand for each query: one stream aggregation (sum/count/min/max over_time, grouped at ingest when the outer aggregate allows) or one vmalert recording rule (everything else), nothing shared between queries; the dashboard query reads the recorded series. scripts/victoriametrics-hand-written.py writes it (and victoriametrics.native) into a run directory, so native, planner plans and hand-written run on one engine into one report. The adapter installs a file with the key victoriametrics_hand_written instead of translating it: stream aggregations as before, rules into a vmalert (new --victoriametrics-vmalert-url / -rules-file) that the up script runs inside the server's container (VMALERT_PORT), so its CPU and memory are measured with the server's. Ingest waits for each rule's evaluation at the chunk end and for vmalert's writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
victoriametricsengine ran only the query texts (native) and planner plans.victoriametrics.hand-written: per query, the one stream aggregation or one vmalert recording rule an experienced user writes by hand (nothing shared between queries), with the dashboard query reading the recorded series.scripts/victoriametrics-hand-written.pywrites it into a run directory; the adapter installs it (stream config as before, rules into a vmalert that runs inside the server's container).sum by (job) (rate(requests_total[1m]))every 10 s becomes the rulejob:requests_total:sum_rate_1m_q1(vmalert group every 10 s) read bylast_over_time(job:requests_total:sum_rate_1m_q1[10s]); on the conformance data its answers equal the hand-computed VictoriaMetricsrateat every evaluation (1e-9).Review guide
Base
main. Read first:system-bench/src/engines_external/victoriametrics_hand_written.rs: the file format, its checks, the YAML it renders, vmalert API parsing.system-bench/src/engines_external/victoriametrics_server.rs:installnow builds anArmSetupfrom a plan (unchanged logic, moved intoplan_setup) or a hand-written file (hand_written_setup);InstalledRules(load / wait / unload) and the ingest additions.scripts/victoriametrics-hand-written.py: the rules per query shape.Mechanical: the fixtures under
system-bench/tests/fixtures/hand-written/victoriametrics/are the generator's output forsuites/showcase-1mand-1h(a test regenerates and compares them). Shared files touched minimally:engines_external/mod.rs(one line),docs/system-bench.md(one paragraph). No aqpbm-core change: the hand-written file sits in the harness's opaqueplans/<variant>/<w>.plan.jsonslot, told apart by its top-level key (the same convention as the ClickHouse hand-written variant).Behavior: before → after
Before: a run directory for engine
victoriametricscould holdvictoriametrics.nativeand the planner'svictoriametrics.equivalent-only/.with-substitutes.After:
Rules per showcase query (pane p = gcd(window, interval): 10 s for showcase-1m, 60 s for -1h; h = (p − 1 s)/2):
sum by (job) (sum_over_time(latency[1m]))latencyevery 10 s,by: [job],sum_samplessum_over_time(latency:10s_by_job_sum_samples[60s] offset -4500ms)sum by (job) (count_over_time(latency[1m]))count_samplessum_over_time(latency:10s_by_job_count_samples[60s] offset -4500ms)max_over_time(latency[1m])maxmax_over_time(latency:10s_max[60s] offset -4500ms)quantile_over_time(0.99, latency[1m])series:latency:quantile_over_time_0_99_1m_q1last_over_time(series:latency:quantile_over_time_0_99_1m_q1[10s])avg by (job) (quantile_over_time(0.9, latency[1m]))job:latency:avg_quantile_over_time_0_9_1m_q1last_over_time(…[10s])sum by (job) (rate(requests_total[1m]))job:requests_total:sum_rate_1m_q1last_over_time(…[10s])Each rule is its own vmalert group:
interval= the evaluation interval,eval_alignment: true,eval_delay: 0s(the server's-search.latencyOffsetis 0).Where hand-written answers can differ (also in
capabilities/README.md§ Hand-written variant)job:…_q1answers from the last 5 minutes (an instant query's default look-back), so series another arm or a removed rule recorded keep answering. The first conformance run showed it: the quantile record returned two series of an earlier test run besides the current three. The dashboard query therefore readslast_over_time(<record>[<interval>]), the latest evaluation only.-rule.evalDelay=30s(default) the record at t holds the window ending 30 s earlier (rounded down to the interval), and a dashboard reading before the group ran for t gets the previous interval's record (stale by one interval). The variant setseval_delay: 0sand the adapter waits for the evaluation at t (ingest work).[end − 1 s, end + lag]), so an unshifted read can count one window too many or too few; the variant reads withoffset -hlike the translator. Measured: the unshifted read was wrong at 0 of 6 evaluations in the conformance run (timing-dependent hazard, not seen here).sum_sampleswithoutcount_samples: the translator pairs them in case an empty window is written as 0; v1.154.1 wrote no such 0 in the conformance test (by job and per series, 20–70 s after the series stopped), so the hand-written read has no companion.rate/increase(no extrapolation, prev/8 reset rule), identical to the native query; the differences from PromQL are the ones the existing conformance documents.Interfaces
system-bench/src/engines_external/victoriametrics_hand_written.rs(new):system-bench/src/engines_external/victoriametrics_server.rs:pub struct VictoriaMetricsEngine { /* private fields; + vmalert: Option<VmalertServer> */ } +/// A vmalert that runs hand-written arms' rules against the server (in the server's container). +pub struct VmalertServer { + /// e.g. `http://10.0.0.1:8880` + pub url: String, + /// its `-rule` file on the server host, replaced per arm + pub rules_file: PathBuf, +} impl VictoriaMetricsEngine { + /// The vmalert that runs hand-written arms' recording rules. + pub fn with_vmalert(self, vmalert: VmalertServer) -> VictoriaMetricsEngine; } pub struct VictoriaMetricsOptions { pub victoriametrics_url: Option<String>, pub victoriametrics_stream_aggregation_config: Option<PathBuf>, pub speed: Option<f64>, pub cgroup: ServerCgroupOptions, pub victoriametrics_restart_command: Option<String>, + /// --victoriametrics-vmalert-url + pub victoriametrics_vmalert_url: Option<String>, + /// --victoriametrics-vmalert-rules-file (goes with the URL) + pub victoriametrics_vmalert_rules_file: Option<PathBuf>, }Files and scripts:
Usage (the conformance test H1, end to end): the workload's nine queries →
hand_written_file(&workload)runs the generator →engine().with_vmalert(VmalertServer { url, rules_file })→install(&workload, &arm)loads 3 stream aggregations + 5 vmalert groups (reloaded 100 ms after a 10 s tick) →run_until(..., 110_000)feeds 10 s chunks in real time; each ingest waits for the stream flushes and each rule's evaluation at the chunk end → 6 evaluations (60–110 s) × 9 queries compared with the hand-computed answers.Algorithm changes
Ingest of a hand-written arm with rules (new; planner arms unchanged):
force_flushand require it done before the tick T (else apacingerror), since vmalert evaluates at T + 0.1–1.1 s;/api/v1/ruleuntilupdates[0].at ≥ T(an evaluation error fails the step; past T + interval fails);/metricsuntilsent + dropped ≥ queued(dropped or write errors since install fail the step);force_flush.The rule evaluation and its write-back thus count as ingest CPU; evaluation steps run only the dashboard queries.
vmalert phase:
-group.maxStartDelay=1smakes a group start within 1 s of a reload, at a sub-second offset from its id; the adapter reloads 100 ms after a tick, so each group runs 0.1–1.1 s after each tick. Complexity: one HTTP poll per rule per 50 ms while waiting.Decisions and open questions
Needs reviewer decision
docker exec) so one cgroup holds both; alternative was a second container measured separately (the harness reads one cgroup). Idle vmalert (no rules) is in native and planner arms' numbers too (~tens of MB RSS).last_over_time(<record>[<interval>])instead of the bare record name (see look-back above).quantile_rankgets the same rule asquantile(same text; the hand-written baseline is exact).Decided
histogram_bucket,quantilesoutputs) are not a hand-written choice here.Verification
cargo test -p system-bench --test victoriametrics_hand_writtencargo test -p system-bench --librfc3339_timespython3 -m unittest scripts/test_victoriametrics_hand_written.pyvictoriametrics_conformance--ignoredon VictoriaMetrics v1.154.1 + vmalert v1.154.1hand_written_rules_equal_the_hand_computed_answers: 6 evaluations × 9 queries equal to 1e-9 (rate through 80 s); existing R1–R9 still pass after theinstallrefactorcargo clippy -p system-bench --all-targets -- -D warnings,cargo fmtbenchmark-external run+report --truth victoriametrics/victoriametrics.native)End-to-end numbers (throttled shared test host, 7 server cores; correctness smoke, not headline timings)
Native is replayed as fast as accepted; planner and hand-written arms are fed in wall-clock time (1 s slices and per-chunk flushes), which is most of their ingest CPU difference to native here.
Follow-ups
scripts/plan-suite.shstill lists novictoriametrics.*planner variants (runs add them locally); left alone here to keep shared files untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi