Skip to content

SP-5/SP-8: EMA cost model, dynamic scraper, backend delivery - #86

Merged
zzylol merged 3 commits into
mainfrom
controller-runtime
Mar 27, 2026
Merged

zzylol merged 3 commits into
mainfrom
controller-runtime

Conversation

@zzylol

@zzylol zzylol commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • SP-5 EMA cost model: online_cost_model wired into CostModelPlanner via with_online_store(). Scoring now uses a live-blended cost table (70 % online / 30 % benchmark after 5+ observations) instead of static benchmarks, so the planner converges toward real-world behaviour over time.
  • SP-8 feedback loop: Scraper gains dynamic endpoint management (add_endpoint, remove_endpoint, set_sketch_type) backed by Arc<RwLock<Vec<Endpoint>>>. New on_metrics callback delivers ScrapedData (sketch_size_bytes + derived cpu_micros_per_sample) to the EMA store after each successful scrape.
  • OpAMP role tracking: X-Agent-Role: agent|backend header distinguishes edge collectors from aggregation backends. push_to_role() delivers role-appropriate configs: agent YAML to Agent role, backend YAML to Backend role. on_connect/on_disconnect hooks auto-register/deregister scrape endpoints.
  • main.rs wiring: initialise EMA store → build Scraper with EMA callback → build OpampServer with connect/disconnect hooks → CostModelPlanner::with_online_store → start scraper background loop. After each plan: push agent config to agent-role collectors, backend config to backend-role collectors, update endpoint sketch types for EMA attribution.

Test plan

  • cargo test — all 128 tests pass
  • monitor — 8 tests including new on_metrics_callback_fires and add_remove_endpoint
  • opamp — role parsing, push_to_role, connect/disconnect
  • planner::online_cost_model — EMA blending, store init, effective_table fallback
  • All existing cost model, delta cost model, query parser, analyzer, config, and store tests continue to pass

Replaces #81 (retargeted to main after controller branch was merged)

🤖 Generated with Claude Code

zzylol and others added 3 commits March 26, 2026 15:48
Adds a `query_parser` module that implements SP-1 workload extraction from
raw query strings, covering DEBS 2022 financial queries and ClickBench SQL
patterns, following the SQL-to-sketch mapping rules in the design doc.

## query_parser/promql.rs
Regex-based PromQL parser recognising: quantile_over_time, avg/min/max/
sum/count_over_time, histogram_quantile, topk(k, count_over_time), and
count(count_over_time ... by (dims)) for cardinality. Bare selectors
(no agg fn) are marked exact_required for RSI/MACD/stochastic passthrough.

## query_parser/sql.rs
sqlparser-AST traversal implementing the doc's Generate_SQL_Aggregation_
Sketch_Mapping rules: COUNT(*)+GROUP BY → Frequency; COUNT(DISTINCT) →
Cardinality (HLL); AVG → Quantile p50; MIN/MAX → Quantile p0/p100;
ORDER BY DESC LIMIT k → heavy-hitter CountSketch; SUM → exact.

## query_parser/mod.rs
QueryHint enum for named DEBS patterns (DebsEma, DebsTopK, DebsPriceStats,
DebsVolatility, DebsCardinality, DebsTwap, DebsAnomaly, ExactRequired).
debs_hint() classifies financial.last_trade_price queries by quantile set.

## analyzer.rs
Adds optional query_string field to QuerySpec. When provided, the parsed
result populates metric_name, aggregations, time_window, group_by_labels,
and label_filters; explicit fields override parsed values.

## types.rs / rules.rs
Extends QueryWorkload with exact_required and quantiles fields. The
RulesPlanner returns a raw-passthrough plan when exact_required=true and
seeds DDSketch/KLL quantile params from parsed φ values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…delivery (#80)

- SP-5 (online_cost_model): expose OnlineMetricsStore from planner; wire into
  CostModelPlanner via with_online_store() so scoring uses EMA-blended costs
- SP-8 (feedback loop): Scraper gains dynamic add/remove/set_sketch_type
  endpoints backed by Arc<RwLock<>>; new on_metrics callback feeds observed
  bandwidth + CPU/sample deltas into the EMA store after each scrape
- OpAMP role tracking: X-Agent-Role header distinguishes agent vs backend
  collectors; push_to_role() delivers role-appropriate configs; on_connect /
  on_disconnect callbacks register/deregister scrape endpoints automatically
- main.rs: initialise EMA store, wire Scraper + OpAMP callbacks, start scraper
  background loop, push agent config to Agent-role and backend config to
  Backend-role collectors on every plan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…licts

SP-1 query_parser (promql-parser 0.8, sqlparser 0.61) landed on main via
PR #79 after controller-runtime branched. Take main's versions for
Cargo.toml, Cargo.lock, and all query_parser files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zzylol
zzylol merged commit 7fb2dc3 into main Mar 27, 2026
@zzylol
zzylol deleted the controller-runtime branch March 27, 2026 03:28
SieDeta pushed a commit that referenced this pull request Apr 17, 2026
* SP-1: PromQL and SQL query parsing with DEBS Q1–Q12 and sketch mapping

Adds a `query_parser` module that implements SP-1 workload extraction from
raw query strings, covering DEBS 2022 financial queries and ClickBench SQL
patterns, following the SQL-to-sketch mapping rules in the design doc.

## query_parser/promql.rs
Regex-based PromQL parser recognising: quantile_over_time, avg/min/max/
sum/count_over_time, histogram_quantile, topk(k, count_over_time), and
count(count_over_time ... by (dims)) for cardinality. Bare selectors
(no agg fn) are marked exact_required for RSI/MACD/stochastic passthrough.

## query_parser/sql.rs
sqlparser-AST traversal implementing the doc's Generate_SQL_Aggregation_
Sketch_Mapping rules: COUNT(*)+GROUP BY → Frequency; COUNT(DISTINCT) →
Cardinality (HLL); AVG → Quantile p50; MIN/MAX → Quantile p0/p100;
ORDER BY DESC LIMIT k → heavy-hitter CountSketch; SUM → exact.

## query_parser/mod.rs
QueryHint enum for named DEBS patterns (DebsEma, DebsTopK, DebsPriceStats,
DebsVolatility, DebsCardinality, DebsTwap, DebsAnomaly, ExactRequired).
debs_hint() classifies financial.last_trade_price queries by quantile set.

## analyzer.rs
Adds optional query_string field to QuerySpec. When provided, the parsed
result populates metric_name, aggregations, time_window, group_by_labels,
and label_filters; explicit fields override parsed values.

## types.rs / rules.rs
Extends QueryWorkload with exact_required and quantiles fields. The
RulesPlanner returns a raw-passthrough plan when exact_required=true and
seeds DDSketch/KLL quantile params from parsed φ values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* SP-5/SP-8: runtime wiring — EMA cost model, dynamic scraper, backend delivery (#80)

- SP-5 (online_cost_model): expose OnlineMetricsStore from planner; wire into
  CostModelPlanner via with_online_store() so scoring uses EMA-blended costs
- SP-8 (feedback loop): Scraper gains dynamic add/remove/set_sketch_type
  endpoints backed by Arc<RwLock<>>; new on_metrics callback feeds observed
  bandwidth + CPU/sample deltas into the EMA store after each scrape
- OpAMP role tracking: X-Agent-Role header distinguishes agent vs backend
  collectors; push_to_role() delivers role-appropriate configs; on_connect /
  on_disconnect callbacks register/deregister scrape endpoints automatically
- main.rs: initialise EMA store, wire Scraper + OpAMP callbacks, start scraper
  background loop, push agent config to Agent-role and backend config to
  Backend-role collectors on every plan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant