From 91a20229f7c114227922a2d2109cc43a50741c3f Mon Sep 17 00:00:00 2001 From: zzylol Date: Thu, 26 Nov 2026 09:45:16 +0000 Subject: [PATCH 1/3] feat(common): engine boundary types and traits Step 4 of docs/design/repo-layout.md: crates/common holds the data plane's boundary types and traits (requests and results, ingest, plan, query, stores, fallback) with the names of ASAPQuery's engine-boundary design. No implementations and no callers yet. Adds the common package to the CI format check. --- Cargo.lock | 11 ++ Cargo.toml | 10 +- crates/common/Cargo.toml | 20 ++++ crates/common/src/fallback.rs | 40 +++++++ crates/common/src/ingest.rs | 45 ++++++++ crates/common/src/lib.rs | 39 +++++++ crates/common/src/plan.rs | 30 +++++ crates/common/src/query_engine.rs | 168 ++++++++++++++++++++++++++++ crates/common/src/query_request.rs | 24 ++++ crates/common/src/query_result.rs | 63 +++++++++++ crates/common/src/store.rs | 84 ++++++++++++++ crates/common/tests/trait_shapes.rs | 147 ++++++++++++++++++++++++ 12 files changed, 678 insertions(+), 3 deletions(-) create mode 100644 crates/common/Cargo.toml create mode 100644 crates/common/src/fallback.rs create mode 100644 crates/common/src/ingest.rs create mode 100644 crates/common/src/lib.rs create mode 100644 crates/common/src/plan.rs create mode 100644 crates/common/src/query_engine.rs create mode 100644 crates/common/src/query_request.rs create mode 100644 crates/common/src/query_result.rs create mode 100644 crates/common/src/store.rs create mode 100644 crates/common/tests/trait_shapes.rs diff --git a/Cargo.lock b/Cargo.lock index 5dc5ff4b7..4db60f4ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,6 +850,17 @@ dependencies = [ "unicode-width 0.2.2", ] +[[package]] +name = "common" +version = "0.1.0" +dependencies = [ + "asap-planner", + "asap-types", + "async-trait", + "thiserror 1.0.69", + "tokio", +] + [[package]] name = "const-random" version = "0.1.18" diff --git a/Cargo.toml b/Cargo.toml index 5cd886380..7dde9c069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] resolver = "2" members = [ + "crates/common", "crates/control-plane", "crates/data-plane", "crates/internal-metrics", @@ -12,11 +13,13 @@ edition = "2021" version = "0.1.0" [workspace.dependencies] -# The backend depends on two Planner crates, at one immutable revision: -# `asap-planner` to plan and `asap-executor` to execute. Planner IR types -# are reached through `asap_executor::planner`. +# The backend depends on three Planner crates, at one immutable revision: +# `asap-planner` to plan, `asap-executor` to execute, and `asap-types` for +# the plan types `common`'s boundary names (`QueryLanguage`, `Source`). +# Elsewhere, Planner IR types are reached through `asap_executor::planner`. asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" } asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" } +asap-types = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" } # The sketch library the Planner's executor pins, for the byte encodings of # the sketch states the data plane persists; keep it at the Planner's rev # (here overridden below for the executor too). @@ -27,6 +30,7 @@ serde = { version = "1.0", features = ["derive"] } # (its predicted usage and prices are floats). serde_json = { version = "1.0", features = ["float_roundtrip"] } thiserror = "1.0" +async-trait = "0.1" anyhow = "1.0" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml new file mode 100644 index 000000000..5fddbfe5d --- /dev/null +++ b/crates/common/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "common" +version.workspace = true +edition.workspace = true + +# The data plane's boundary types and traits (docs/design/repo-layout.md). +# Only ASAPPlanner's plan types: `asap-planner` for `InstallablePlan` and +# `asap-types` for the IR types it does not re-export. No executor item is +# named here; `asap-planner` still compiles the executor and the frontends +# as its own dependencies. +[dependencies] +asap-planner.workspace = true +asap-types.workspace = true +# The engine traits are used as `Arc`, so their async methods must +# be object safe; native `async fn` in traits is not. +async-trait.workspace = true +thiserror.workspace = true + +[dev-dependencies] +tokio.workspace = true diff --git a/crates/common/src/fallback.rs b/crates/common/src/fallback.rs new file mode 100644 index 000000000..973332599 --- /dev/null +++ b/crates/common/src/fallback.rs @@ -0,0 +1,40 @@ +use async_trait::async_trait; + +use crate::QueryRequest; + +/// The client of the backend that answers a query the data plane does not: +/// a query that is not planned, not ready, or failed in the engine. +#[async_trait] +pub trait FallbackClient: Send + Sync { + /// Sends the query to the backend, with the client's `headers` (name, + /// value), and returns the backend's response as is. + async fn execute( + &self, + request: &QueryRequest, + headers: &[(String, String)], + ) -> Result; +} + +/// The backend's HTTP response, passed to the client unchanged. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct FallbackResponse { + pub status_code: u16, + /// The `Content-Type` header value, e.g. `application/json`. + pub content_type: String, + pub body: Vec, +} + +/// The backend could not be reached or sent no response. +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +#[error("{message}")] +pub struct FallbackError { + pub message: String, +} + +impl FallbackError { + pub fn new(message: impl Into) -> Self { + Self { + message: message.into(), + } + } +} diff --git a/crates/common/src/ingest.rs b/crates/common/src/ingest.rs new file mode 100644 index 000000000..e4a1fe458 --- /dev/null +++ b/crates/common/src/ingest.rs @@ -0,0 +1,45 @@ +use async_trait::async_trait; + +use crate::{InstallError, InstalledPlan, LabelSet}; + +/// Raw input data: what an ingest adapter hands the ingest engine and what +/// the raw-data store appends and returns. Never data between operators. +#[derive(Debug, Clone, PartialEq)] +pub enum RawDataBatch { + /// Samples of several series: each series' labels and its + /// `(timestamp_ms, value)` samples. + TimeSeries { + series: Vec<(LabelSet, Vec<(i64, f64)>)>, + }, +} + +/// The engine that runs the installed plan's ingest-time part: it builds +/// the plan's views from raw data and keeps the raw data the plan reads. +/// It closes windows on its own timer. +#[async_trait] +pub trait IngestEngine: Send + Sync { + /// Replaces the plan it runs. On an error, the current plan stays. + fn install(&self, plan: InstalledPlan) -> Result<(), InstallError>; + + /// Takes one batch, waiting while the engine cannot accept it + /// (backpressure). Discards it before the first plan is installed. + async fn ingest(&self, batch: RawDataBatch) -> Result<(), IngestError>; + + /// Stops the engine, best effort. + fn shutdown(&self); +} + +/// The ingest engine is gone and accepts no more batches. +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +#[error("{message}")] +pub struct IngestError { + pub message: String, +} + +impl IngestError { + pub fn new(message: impl Into) -> Self { + Self { + message: message.into(), + } + } +} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs new file mode 100644 index 000000000..7545172e6 --- /dev/null +++ b/crates/common/src/lib.rs @@ -0,0 +1,39 @@ +//! The data plane's boundary types and traits, with the names and shapes of +//! ASAPQuery's engine-boundary design (docs/design/repo-layout.md). Adapters, +//! engines and stores meet here; this crate holds no implementation. +//! +//! It names ASAPPlanner's plan types only (`InstallablePlan`, the DAG's node +//! ids, `RawDataRetention`, `QueryLanguage`, `Source`) and no executor item. +//! `asap-planner`, which defines `InstallablePlan`, still brings the +//! executor and the frontends in at compile time. + +mod fallback; +mod ingest; +mod plan; +mod query_engine; +mod query_request; +mod query_result; +mod store; + +pub use fallback::{FallbackClient, FallbackError, FallbackResponse}; +pub use ingest::{IngestEngine, IngestError, RawDataBatch}; +pub use plan::{InstallError, InstalledPlan, PlanId}; +pub use query_engine::{AnswerSource, EngineQueryResult, QueryEngine, QueryEngineError}; +pub use query_request::{QueryEval, QueryRequest}; +pub use query_result::{ + InstantVector, InstantVectorElement, QueryResult, RangeVector, RangeVectorElement, Sample, + Table, TableValue, +}; +pub use store::{ + RawDataStore, ViewId, ViewInstance, ViewInstanceKey, ViewInstanceMetadata, ViewState, ViewStore, +}; + +/// One series' labels, name to value, `__name__` included: on raw data and +/// on query results. +pub type LabelSet = std::collections::BTreeMap; + +// The plan types the boundary names, so callers need no direct Planner +// dependency to use it. +pub use asap_planner::{InstallablePlan, PhysicalASAPNodeId, RawDataRetention}; +pub use asap_types::ir::operator::arguments::Source; +pub use asap_types::workload::QueryLanguage; diff --git a/crates/common/src/plan.rs b/crates/common/src/plan.rs new file mode 100644 index 000000000..8c5f24034 --- /dev/null +++ b/crates/common/src/plan.rs @@ -0,0 +1,30 @@ +use asap_planner::InstallablePlan; + +/// The installed plan's version for the workload: a counter the installer +/// increments per install. Part of every view's id ([`crate::ViewId`]). +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct PlanId(pub u64); + +/// A validated `InstallablePlan` with the id it was installed under. Nothing +/// else: everything an engine derives from the plan, it computes from `plan`. +#[derive(Debug, Clone, PartialEq)] +pub struct InstalledPlan { + pub id: PlanId, + pub plan: InstallablePlan, +} + +/// Why an engine refused a plan; the installer keeps the current plan and +/// logs `message`. +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +#[error("{message}")] +pub struct InstallError { + pub message: String, +} + +impl InstallError { + pub fn new(message: impl Into) -> Self { + Self { + message: message.into(), + } + } +} diff --git a/crates/common/src/query_engine.rs b/crates/common/src/query_engine.rs new file mode 100644 index 000000000..89893c614 --- /dev/null +++ b/crates/common/src/query_engine.rs @@ -0,0 +1,168 @@ +use asap_planner::PhysicalASAPNodeId; +use async_trait::async_trait; + +use crate::{InstallError, InstalledPlan, PlanId, QueryRequest, QueryResult}; + +/// What answers a query, as the dispatcher resolved it: the engine runs it +/// without matching the query again. +#[derive(Debug, Clone, PartialEq)] +pub enum AnswerSource { + /// The query is the plan's query `i`, answered by `dag.roots[i]`. + /// `plan` is the plan it was resolved against. + Planned { + plan: PlanId, + root: PhysicalASAPNodeId, + }, + // `CapabilityMatched { plan, matched }` goes here once capability + // matching (answering an unplanned query from the stored views) is + // designed. +} + +/// What the query engine reports for one query. +#[derive(Debug, Clone, PartialEq)] +pub enum EngineQueryResult { + /// The answer. + Ready { result: QueryResult }, + /// The stored data does not cover the whole query, or the plan changed + /// since the query was resolved; the query falls back. + NotReady, +} + +/// The engine that answers queries from the installed plan's views and raw +/// data. It holds its installed plan and steps through range queries +/// itself. +#[async_trait] +pub trait QueryEngine: Send + Sync { + /// Replaces the plan it answers from. On an error, the current plan + /// stays. + fn install(&self, plan: InstalledPlan) -> Result<(), InstallError>; + + /// One query: a batch of one. + async fn execute( + &self, + source: &AnswerSource, + request: &QueryRequest, + ) -> Result { + let mut results = self + .execute_batch(&[(source.clone(), request.clone())]) + .await; + let returned = results.len(); + match results.pop() { + Some(result) if returned == 1 => result, + _ => Err(QueryEngineError::new(format!( + "execute_batch returned {returned} results for one query" + ))), + } + } + + /// Several queries evaluated together, so the work the plan shares + /// between them runs once. One result per query, in order. + async fn execute_batch( + &self, + queries: &[(AnswerSource, QueryRequest)], + ) -> Vec>; +} + +/// A query the engine failed to run. The dispatcher logs and counts it, and +/// the query falls back. +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +#[error("{message}")] +pub struct QueryEngineError { + pub message: String, +} + +impl QueryEngineError { + pub fn new(message: impl Into) -> Self { + Self { + message: message.into(), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{QueryEval, QueryLanguage, Sample}; + + /// Returns `results_per_call` copies of its first query's answer and + /// records the batch it was given. + struct Batches { + results_per_call: usize, + seen: std::sync::Mutex>>, + } + + #[async_trait] + impl QueryEngine for Batches { + fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { + Ok(()) + } + + async fn execute_batch( + &self, + queries: &[(AnswerSource, QueryRequest)], + ) -> Vec> { + self.seen.lock().unwrap().push(queries.to_vec()); + let QueryEval::Instant { time_ms } = queries[0].1.eval else { + unreachable!("the tests send instant queries") + }; + let answer = EngineQueryResult::Ready { + result: QueryResult::Scalar(Sample { + timestamp_ms: time_ms, + value: 1.0, + }), + }; + vec![Ok(answer); self.results_per_call] + } + } + + fn query() -> (AnswerSource, QueryRequest) { + let source = AnswerSource::Planned { + plan: PlanId(1), + root: 7, + }; + let request = QueryRequest { + language: QueryLanguage::PromQL, + query: "sum(up)".into(), + eval: QueryEval::Instant { time_ms: 60_000 }, + }; + (source, request) + } + + fn engine(results_per_call: usize) -> Batches { + Batches { + results_per_call, + seen: Default::default(), + } + } + + #[tokio::test] + async fn execute_is_a_batch_of_one() { + let engine = engine(1); + let (source, request) = query(); + let result = engine.execute(&source, &request).await; + assert_eq!( + result, + Ok(EngineQueryResult::Ready { + result: QueryResult::Scalar(Sample { + timestamp_ms: 60_000, + value: 1.0 + }) + }) + ); + assert_eq!(*engine.seen.lock().unwrap(), vec![vec![query()]]); + } + + #[tokio::test] + async fn execute_reports_a_batch_without_exactly_one_result() { + let (source, request) = query(); + for returned in [0, 2] { + let result = engine(returned).execute(&source, &request).await; + assert_eq!( + result, + Err(QueryEngineError::new(format!( + "execute_batch returned {returned} results for one query" + ))) + ); + } + } +} diff --git a/crates/common/src/query_request.rs b/crates/common/src/query_request.rs new file mode 100644 index 000000000..53ae2f2c5 --- /dev/null +++ b/crates/common/src/query_request.rs @@ -0,0 +1,24 @@ +use asap_types::workload::QueryLanguage; + +/// One parsed query, independent of the protocol it arrived on. +#[derive(Debug, Clone, PartialEq)] +pub struct QueryRequest { + pub language: QueryLanguage, + /// The query text, as the client sent it. + pub query: String, + pub eval: QueryEval, +} + +/// When to evaluate a query, in unix epoch milliseconds. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum QueryEval { + Instant { + time_ms: i64, + }, + /// At `start_ms`, then every `step_ms` up to `end_ms`. + Range { + start_ms: i64, + end_ms: i64, + step_ms: i64, + }, +} diff --git a/crates/common/src/query_result.rs b/crates/common/src/query_result.rs new file mode 100644 index 000000000..3f5087db7 --- /dev/null +++ b/crates/common/src/query_result.rs @@ -0,0 +1,63 @@ +//! A query's answer. Every variant carries its own label or column names. + +use crate::LabelSet; + +/// The result of a query. A response adapter returns an error for a +/// variant its protocol cannot express. +#[derive(Debug, Clone, PartialEq)] +pub enum QueryResult { + Vector(InstantVector), + Matrix(RangeVector), + /// One value at one time (a PromQL scalar). + Scalar(Sample), + /// Named columns and rows (a SQL result set). + Table(Table), +} + +/// One value per series, all at `timestamp_ms`. +#[derive(Debug, Clone, PartialEq)] +pub struct InstantVector { + pub timestamp_ms: i64, + pub series: Vec, +} + +/// One series of an instant vector: its labels and its value. +#[derive(Debug, Clone, PartialEq)] +pub struct InstantVectorElement { + pub labels: LabelSet, + pub value: f64, +} + +/// Samples over a time range, per series. +#[derive(Debug, Clone, PartialEq)] +pub struct RangeVector { + pub series: Vec, +} + +/// One series of a range vector: its labels and its samples, oldest first. +#[derive(Debug, Clone, PartialEq)] +pub struct RangeVectorElement { + pub labels: LabelSet, + pub samples: Vec, +} + +/// A value at a time. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Sample { + pub timestamp_ms: i64, + pub value: f64, +} + +/// A table: each row holds one value per column, in column order. +#[derive(Debug, Clone, PartialEq)] +pub struct Table { + pub columns: Vec, + pub rows: Vec>, +} + +/// One table cell. +#[derive(Debug, Clone, PartialEq)] +pub enum TableValue { + String(String), + Float(f64), +} diff --git a/crates/common/src/store.rs b/crates/common/src/store.rs new file mode 100644 index 000000000..f43b26ef2 --- /dev/null +++ b/crates/common/src/store.rs @@ -0,0 +1,84 @@ +//! The stores the deployment owns and injects into both engines: the ingest +//! engine writes them, the query engine reads and evicts. + +use std::any::Any; +use std::collections::HashMap; +use std::sync::Arc; + +use asap_planner::{PhysicalASAPNodeId, RawDataRetention}; +use asap_types::ir::operator::arguments::Source; + +use crate::{PlanId, RawDataBatch}; + +/// A materialized view: its node in plan `plan`, which fixes what it +/// computes (sub-DAG, selection, sketch parameters, window widths). +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct ViewId { + pub plan: PlanId, + pub node: PhysicalASAPNodeId, +} + +/// One window of one view: the view and its absolute window +/// `(start_ms, end_ms]`. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct ViewInstanceKey { + pub view: ViewId, + pub window_ms: (i64, i64), +} + +/// A view's stored state for one window, for all of the window's group +/// keys. +#[derive(Debug, Clone)] +pub struct ViewInstance { + pub state: ViewState, + pub metadata: ViewInstanceMetadata, +} + +/// What the store knows about an instance besides its opaque state. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct ViewInstanceMetadata { + /// What the state occupies in memory, for the store's memory budget. + pub size_bytes: u64, +} + +/// The engine's native state of one view instance, opaque to the store; +/// the query engine downcasts it. +#[derive(Debug, Clone)] +pub struct ViewState(pub Arc); + +/// Stored view instances, in memory, on disk or both; the implementation +/// chooses its indexing and never looks inside a state. +pub trait ViewStore: Send + Sync { + /// Stores an instance. Each key is put once and never rewritten. + fn put(&self, key: ViewInstanceKey, instance: ViewInstance); + + /// The instance stored under `key`, if any. + fn get(&self, key: &ViewInstanceKey) -> Option; + + /// Each stored instance of `view` whose window lies within + /// `interval_ms` `(start_ms, end_ms]`, with its window. + fn instances(&self, view: &ViewId, interval_ms: (i64, i64)) -> Vec<((i64, i64), ViewInstance)>; + + /// Drops the instances of `view` whose window ends at or before + /// `before_ms`. + fn evict_before(&self, view: &ViewId, before_ms: i64); + + /// Per view with stored instances, the start of its oldest window and + /// the end of its newest, in ms; for runtime info. + fn timestamp_range_per_view(&self) -> HashMap; +} + +/// Stored raw data, per source of the plan's `Scan`s. +pub trait RawDataStore: Send + Sync { + /// Appends a batch of `source`'s raw data. + fn append(&self, source: &Source, batch: RawDataBatch); + + /// `source`'s stored raw data with timestamps in `interval_ms` + /// `(start_ms, end_ms]`, or `None` when the store no longer holds the + /// whole interval (evicted), so the query engine reports `NotReady`. + fn read(&self, source: &Source, interval_ms: (i64, i64)) -> Option; + + /// Drops each listed source's raw data at or before `now_ms` minus its + /// retention's lookback; a source with no lookback keeps all of it. + fn evict(&self, retention: &[RawDataRetention], now_ms: i64); +} diff --git a/crates/common/tests/trait_shapes.rs b/crates/common/tests/trait_shapes.rs new file mode 100644 index 000000000..7f42c9a76 --- /dev/null +++ b/crates/common/tests/trait_shapes.rs @@ -0,0 +1,147 @@ +//! Each boundary trait can be implemented outside this crate and used as +//! `Arc`, as the deployment holds its engines, stores and fallback. +//! The fakes are trivial: only the trait shapes are under test. + +use std::collections::HashMap; +use std::sync::Arc; + +use async_trait::async_trait; +use common::{ + AnswerSource, EngineQueryResult, FallbackClient, FallbackError, FallbackResponse, IngestEngine, + IngestError, InstallError, InstalledPlan, PlanId, QueryEngine, QueryEngineError, QueryEval, + QueryLanguage, QueryRequest, RawDataBatch, RawDataRetention, RawDataStore, Source, ViewId, + ViewInstance, ViewInstanceKey, ViewInstanceMetadata, ViewState, ViewStore, +}; + +struct NoIngest; + +#[async_trait] +impl IngestEngine for NoIngest { + fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { + Ok(()) + } + async fn ingest(&self, _batch: RawDataBatch) -> Result<(), IngestError> { + Ok(()) + } + fn shutdown(&self) {} +} + +struct NeverReady; + +#[async_trait] +impl QueryEngine for NeverReady { + fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { + Ok(()) + } + async fn execute_batch( + &self, + queries: &[(AnswerSource, QueryRequest)], + ) -> Vec> { + queries + .iter() + .map(|_| Ok(EngineQueryResult::NotReady)) + .collect() + } +} + +struct NoViews; + +impl ViewStore for NoViews { + fn put(&self, _key: ViewInstanceKey, _instance: ViewInstance) {} + fn get(&self, _key: &ViewInstanceKey) -> Option { + None + } + fn instances( + &self, + _view: &ViewId, + _interval_ms: (i64, i64), + ) -> Vec<((i64, i64), ViewInstance)> { + Vec::new() + } + fn evict_before(&self, _view: &ViewId, _before_ms: i64) {} + fn timestamp_range_per_view(&self) -> HashMap { + HashMap::new() + } +} + +struct NoRawData; + +impl RawDataStore for NoRawData { + fn append(&self, _source: &Source, _batch: RawDataBatch) {} + fn read(&self, _source: &Source, _interval_ms: (i64, i64)) -> Option { + None + } + fn evict(&self, _retention: &[RawDataRetention], _now_ms: i64) {} +} + +struct Unreachable; + +#[async_trait] +impl FallbackClient for Unreachable { + async fn execute( + &self, + _request: &QueryRequest, + _headers: &[(String, String)], + ) -> Result { + Err(FallbackError::new("connection refused")) + } +} + +#[tokio::test] +async fn every_trait_is_usable_as_a_trait_object() { + let ingest: Arc = Arc::new(NoIngest); + let query: Arc = Arc::new(NeverReady); + let views: Arc = Arc::new(NoViews); + let raw: Arc = Arc::new(NoRawData); + let fallback: Arc = Arc::new(Unreachable); + + let labels = [("__name__".to_string(), "up".to_string())].into(); + let batch = RawDataBatch::TimeSeries { + series: vec![(labels, vec![(1_000, 1.0)])], + }; + assert_eq!(ingest.ingest(batch).await, Ok(())); + ingest.shutdown(); + + let request = QueryRequest { + language: QueryLanguage::PromQL, + query: "up".into(), + eval: QueryEval::Range { + start_ms: 0, + end_ms: 60_000, + step_ms: 15_000, + }, + }; + let source = AnswerSource::Planned { + plan: PlanId(1), + root: 0, + }; + assert_eq!( + query.execute(&source, &request).await, + Ok(EngineQueryResult::NotReady) + ); + + let view = ViewId { + plan: PlanId(1), + node: 3, + }; + let key = ViewInstanceKey { + view, + window_ms: (0, 10_000), + }; + views.put( + key, + ViewInstance { + state: ViewState(Arc::new(0_u64)), + metadata: ViewInstanceMetadata { size_bytes: 8 }, + }, + ); + assert!(views.get(&key).is_none()); + + let metric = Source::TimeSeries { + metric: "up".into(), + }; + raw.evict(&[], 0); + assert_eq!(raw.read(&metric, (0, 1)), None); + + assert!(fallback.execute(&request, &[]).await.is_err()); +} From 7caa497251c204aff78ed8a0fe0f252e3f7bc278 Mon Sep 17 00:00:00 2001 From: zzylol Date: Thu, 26 Nov 2026 09:45:16 +0000 Subject: [PATCH 2/3] ci: sync the asap-types pin with the other Planner pins common depends on asap-types directly (QueryLanguage, Source), so the Planner sync script rewrites three pins and updates three packages. --- scripts/ci/README.md | 2 +- scripts/ci/test_sync_planner.py | 7 ++++--- scripts/sync-asapplanner-main.sh | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/ci/README.md b/scripts/ci/README.md index ffc00818a..d369a65a9 100644 --- a/scripts/ci/README.md +++ b/scripts/ci/README.md @@ -2,7 +2,7 @@ The backend keeps reproducible Planner revisions in `Cargo.toml` and `Cargo.lock`. `Sync ASAPPlanner main` checks upstream main daily (or on manual dispatch), updates -both Planner dependencies (`asap-planner`, `asap-executor`) together, and opens or refreshes +the three Planner dependencies (`asap-planner`, `asap-executor`, `asap-types`) together, and opens or refreshes `automation/sync-asapplanner-main` against backend main. GitHub scheduled runs can be delayed. The existing `ASAP_CI_REPO_TOKEN` secret must have read access to private dependency diff --git a/scripts/ci/test_sync_planner.py b/scripts/ci/test_sync_planner.py index c9af27d5d..409ff1d89 100644 --- a/scripts/ci/test_sync_planner.py +++ b/scripts/ci/test_sync_planner.py @@ -33,7 +33,7 @@ class PlannerSyncTests(unittest.TestCase): revision = "a" * 40 manifest = ''.join( f'{name} = {{ git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "{"b" * 40}" }}\n' - for name in ['asap-planner', 'asap-executor'] + for name in ['asap-planner', 'asap-executor', 'asap-types'] ) def run_sync(self, manifest, revision=None, cargo_status=0): @@ -58,10 +58,11 @@ def test_updates_all_dependencies_and_lock_resolution(self): root, result = self.run_sync(self.manifest + other) self.assertEqual(result.returncode, 0, result.stderr) updated = (root / 'Cargo.toml').read_text() - self.assertEqual(updated.count(f'rev = "{self.revision}"'), 2) + self.assertEqual(updated.count(f'rev = "{self.revision}"'), 3) self.assertTrue(updated.endswith(other)) self.assertEqual((root / 'cargo-args').read_text().splitlines(), [ - 'update', '-p', 'asap-planner', '-p', 'asap-executor', '--precise', self.revision]) + 'update', '-p', 'asap-planner', '-p', 'asap-executor', '-p', 'asap-types', '--precise', + self.revision]) def test_repository_manifest_updates_only_locked_packages(self): """Every pin in the real Cargo.toml is rewritten and every `-p` names a locked package.""" diff --git a/scripts/sync-asapplanner-main.sh b/scripts/sync-asapplanner-main.sh index 37273d5df..5fc9e3d3b 100755 --- a/scripts/sync-asapplanner-main.sh +++ b/scripts/sync-asapplanner-main.sh @@ -20,14 +20,15 @@ pattern = re.compile( r'(git = "https://github.com/ProjectASAP/ASAPPlanner", rev = ")[0-9a-f]{40}("\s*[,}])' ) updated, replacements = pattern.subn(rf"\g<1>{revision}\2", text) -if replacements != 2: - raise SystemExit(f"expected two ASAPPlanner dependencies, found {replacements}") +if replacements != 3: + raise SystemExit(f"expected three ASAPPlanner dependencies, found {replacements}") path.write_text(updated) PY cargo update \ -p asap-planner \ -p asap-executor \ + -p asap-types \ --precise "$planner_rev" echo "synchronized ASAPPlanner dependencies to $planner_rev" From d7847335abc0b1a6e1c13d25b4a82d18c1f63744 Mon Sep 17 00:00:00 2001 From: zzylol Date: Fri, 27 Nov 2026 22:34:21 +0000 Subject: [PATCH 3/3] refactor(common): drop the engine and store traits; one boundary trait The whole-stack review found no second implementation of IngestEngine, QueryEngine, ViewStore or RawDataStore, and no production caller of IngestEngine::ingest, shutdown or QueryEngine::execute_batch. A trait is added with its second implementation, so common keeps the types and FallbackClient (three implementations later in the stack): - ViewStore, RawDataStore and their types (ViewId, ViewInstance*, ViewState), RawDataBatch, IngestEngine and IngestError are deleted, with the Source and RawDataRetention re-exports only they named. - QueryEngine and its batch-of-one tests are deleted; AnswerSource, EngineQueryResult and QueryEngineError stay for the query engine's inherent execute. - The trait-shape test checks FallbackClient alone. - README: the Planner pin is 1d527bc for all three Planner crates. --- Cargo.toml | 2 +- README.md | 5 +- crates/common/Cargo.toml | 7 +- crates/common/src/ingest.rs | 45 ---------- crates/common/src/lib.rs | 24 ++---- crates/common/src/plan.rs | 2 +- crates/common/src/query_engine.rs | 126 +--------------------------- crates/common/src/store.rs | 84 ------------------- crates/common/tests/trait_shapes.rs | 119 ++------------------------ 9 files changed, 24 insertions(+), 390 deletions(-) delete mode 100644 crates/common/src/ingest.rs delete mode 100644 crates/common/src/store.rs diff --git a/Cargo.toml b/Cargo.toml index 7dde9c069..daff37847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ version = "0.1.0" [workspace.dependencies] # The backend depends on three Planner crates, at one immutable revision: # `asap-planner` to plan, `asap-executor` to execute, and `asap-types` for -# the plan types `common`'s boundary names (`QueryLanguage`, `Source`). +# the plan types `common`'s boundary names (such as `QueryLanguage`). # Elsewhere, Planner IR types are reached through `asap_executor::planner`. asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" } asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" } diff --git a/README.md b/README.md index 83aa2df23..5de55a0b6 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,7 @@ cargo clippy --workspace --all-targets --locked -- -D warnings cargo test --workspace --locked ``` -The Planner revision is pinned in `Cargo.toml` (ASAPPlanner `737bfb1`; `asap_sketchlib` patched -to `355093f`); see +The Planner revision is pinned in `Cargo.toml` (ASAPPlanner `1d527bc` for +`asap-planner`, `asap-executor` and `asap-types`; `asap_sketchlib` patched to +`355093f`); see [scripts/ci/README.md](scripts/ci/README.md). diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 5fddbfe5d..0dc6e5bd7 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -3,7 +3,8 @@ name = "common" version.workspace = true edition.workspace = true -# The data plane's boundary types and traits (docs/design/repo-layout.md). +# The data plane's boundary types and the fallback trait +# (docs/design/repo-layout.md). # Only ASAPPlanner's plan types: `asap-planner` for `InstallablePlan` and # `asap-types` for the IR types it does not re-export. No executor item is # named here; `asap-planner` still compiles the executor and the frontends @@ -11,8 +12,8 @@ edition.workspace = true [dependencies] asap-planner.workspace = true asap-types.workspace = true -# The engine traits are used as `Arc`, so their async methods must -# be object safe; native `async fn` in traits is not. +# `FallbackClient` is used as `Arc`, so its async method must be +# object safe; native `async fn` in traits is not. async-trait.workspace = true thiserror.workspace = true diff --git a/crates/common/src/ingest.rs b/crates/common/src/ingest.rs deleted file mode 100644 index e4a1fe458..000000000 --- a/crates/common/src/ingest.rs +++ /dev/null @@ -1,45 +0,0 @@ -use async_trait::async_trait; - -use crate::{InstallError, InstalledPlan, LabelSet}; - -/// Raw input data: what an ingest adapter hands the ingest engine and what -/// the raw-data store appends and returns. Never data between operators. -#[derive(Debug, Clone, PartialEq)] -pub enum RawDataBatch { - /// Samples of several series: each series' labels and its - /// `(timestamp_ms, value)` samples. - TimeSeries { - series: Vec<(LabelSet, Vec<(i64, f64)>)>, - }, -} - -/// The engine that runs the installed plan's ingest-time part: it builds -/// the plan's views from raw data and keeps the raw data the plan reads. -/// It closes windows on its own timer. -#[async_trait] -pub trait IngestEngine: Send + Sync { - /// Replaces the plan it runs. On an error, the current plan stays. - fn install(&self, plan: InstalledPlan) -> Result<(), InstallError>; - - /// Takes one batch, waiting while the engine cannot accept it - /// (backpressure). Discards it before the first plan is installed. - async fn ingest(&self, batch: RawDataBatch) -> Result<(), IngestError>; - - /// Stops the engine, best effort. - fn shutdown(&self); -} - -/// The ingest engine is gone and accepts no more batches. -#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] -#[error("{message}")] -pub struct IngestError { - pub message: String, -} - -impl IngestError { - pub fn new(message: impl Into) -> Self { - Self { - message: message.into(), - } - } -} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 7545172e6..bd8e1ec3f 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,39 +1,33 @@ -//! The data plane's boundary types and traits, with the names and shapes of -//! ASAPQuery's engine-boundary design (docs/design/repo-layout.md). Adapters, -//! engines and stores meet here; this crate holds no implementation. +//! The data plane's boundary types and the `FallbackClient` trait, with the +//! names and shapes of ASAPQuery's engine-boundary design +//! (docs/design/repo-layout.md). Adapters and engines meet here; this crate +//! holds no implementation. //! //! It names ASAPPlanner's plan types only (`InstallablePlan`, the DAG's node -//! ids, `RawDataRetention`, `QueryLanguage`, `Source`) and no executor item. +//! ids, `QueryLanguage`) and no executor item. //! `asap-planner`, which defines `InstallablePlan`, still brings the //! executor and the frontends in at compile time. mod fallback; -mod ingest; mod plan; mod query_engine; mod query_request; mod query_result; -mod store; pub use fallback::{FallbackClient, FallbackError, FallbackResponse}; -pub use ingest::{IngestEngine, IngestError, RawDataBatch}; pub use plan::{InstallError, InstalledPlan, PlanId}; -pub use query_engine::{AnswerSource, EngineQueryResult, QueryEngine, QueryEngineError}; +pub use query_engine::{AnswerSource, EngineQueryResult, QueryEngineError}; pub use query_request::{QueryEval, QueryRequest}; pub use query_result::{ InstantVector, InstantVectorElement, QueryResult, RangeVector, RangeVectorElement, Sample, Table, TableValue, }; -pub use store::{ - RawDataStore, ViewId, ViewInstance, ViewInstanceKey, ViewInstanceMetadata, ViewState, ViewStore, -}; -/// One series' labels, name to value, `__name__` included: on raw data and -/// on query results. +/// One series' labels, name to value, `__name__` included, as query results +/// carry them. pub type LabelSet = std::collections::BTreeMap; // The plan types the boundary names, so callers need no direct Planner // dependency to use it. -pub use asap_planner::{InstallablePlan, PhysicalASAPNodeId, RawDataRetention}; -pub use asap_types::ir::operator::arguments::Source; +pub use asap_planner::{InstallablePlan, PhysicalASAPNodeId}; pub use asap_types::workload::QueryLanguage; diff --git a/crates/common/src/plan.rs b/crates/common/src/plan.rs index 8c5f24034..1d5bebdb8 100644 --- a/crates/common/src/plan.rs +++ b/crates/common/src/plan.rs @@ -1,7 +1,7 @@ use asap_planner::InstallablePlan; /// The installed plan's version for the workload: a counter the installer -/// increments per install. Part of every view's id ([`crate::ViewId`]). +/// increments per install. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct PlanId(pub u64); diff --git a/crates/common/src/query_engine.rs b/crates/common/src/query_engine.rs index 89893c614..78b472663 100644 --- a/crates/common/src/query_engine.rs +++ b/crates/common/src/query_engine.rs @@ -1,7 +1,6 @@ use asap_planner::PhysicalASAPNodeId; -use async_trait::async_trait; -use crate::{InstallError, InstalledPlan, PlanId, QueryRequest, QueryResult}; +use crate::{PlanId, QueryResult}; /// What answers a query, as the dispatcher resolved it: the engine runs it /// without matching the query again. @@ -28,41 +27,6 @@ pub enum EngineQueryResult { NotReady, } -/// The engine that answers queries from the installed plan's views and raw -/// data. It holds its installed plan and steps through range queries -/// itself. -#[async_trait] -pub trait QueryEngine: Send + Sync { - /// Replaces the plan it answers from. On an error, the current plan - /// stays. - fn install(&self, plan: InstalledPlan) -> Result<(), InstallError>; - - /// One query: a batch of one. - async fn execute( - &self, - source: &AnswerSource, - request: &QueryRequest, - ) -> Result { - let mut results = self - .execute_batch(&[(source.clone(), request.clone())]) - .await; - let returned = results.len(); - match results.pop() { - Some(result) if returned == 1 => result, - _ => Err(QueryEngineError::new(format!( - "execute_batch returned {returned} results for one query" - ))), - } - } - - /// Several queries evaluated together, so the work the plan shares - /// between them runs once. One result per query, in order. - async fn execute_batch( - &self, - queries: &[(AnswerSource, QueryRequest)], - ) -> Vec>; -} - /// A query the engine failed to run. The dispatcher logs and counts it, and /// the query falls back. #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] @@ -78,91 +42,3 @@ impl QueryEngineError { } } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::{QueryEval, QueryLanguage, Sample}; - - /// Returns `results_per_call` copies of its first query's answer and - /// records the batch it was given. - struct Batches { - results_per_call: usize, - seen: std::sync::Mutex>>, - } - - #[async_trait] - impl QueryEngine for Batches { - fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { - Ok(()) - } - - async fn execute_batch( - &self, - queries: &[(AnswerSource, QueryRequest)], - ) -> Vec> { - self.seen.lock().unwrap().push(queries.to_vec()); - let QueryEval::Instant { time_ms } = queries[0].1.eval else { - unreachable!("the tests send instant queries") - }; - let answer = EngineQueryResult::Ready { - result: QueryResult::Scalar(Sample { - timestamp_ms: time_ms, - value: 1.0, - }), - }; - vec![Ok(answer); self.results_per_call] - } - } - - fn query() -> (AnswerSource, QueryRequest) { - let source = AnswerSource::Planned { - plan: PlanId(1), - root: 7, - }; - let request = QueryRequest { - language: QueryLanguage::PromQL, - query: "sum(up)".into(), - eval: QueryEval::Instant { time_ms: 60_000 }, - }; - (source, request) - } - - fn engine(results_per_call: usize) -> Batches { - Batches { - results_per_call, - seen: Default::default(), - } - } - - #[tokio::test] - async fn execute_is_a_batch_of_one() { - let engine = engine(1); - let (source, request) = query(); - let result = engine.execute(&source, &request).await; - assert_eq!( - result, - Ok(EngineQueryResult::Ready { - result: QueryResult::Scalar(Sample { - timestamp_ms: 60_000, - value: 1.0 - }) - }) - ); - assert_eq!(*engine.seen.lock().unwrap(), vec![vec![query()]]); - } - - #[tokio::test] - async fn execute_reports_a_batch_without_exactly_one_result() { - let (source, request) = query(); - for returned in [0, 2] { - let result = engine(returned).execute(&source, &request).await; - assert_eq!( - result, - Err(QueryEngineError::new(format!( - "execute_batch returned {returned} results for one query" - ))) - ); - } - } -} diff --git a/crates/common/src/store.rs b/crates/common/src/store.rs deleted file mode 100644 index f43b26ef2..000000000 --- a/crates/common/src/store.rs +++ /dev/null @@ -1,84 +0,0 @@ -//! The stores the deployment owns and injects into both engines: the ingest -//! engine writes them, the query engine reads and evicts. - -use std::any::Any; -use std::collections::HashMap; -use std::sync::Arc; - -use asap_planner::{PhysicalASAPNodeId, RawDataRetention}; -use asap_types::ir::operator::arguments::Source; - -use crate::{PlanId, RawDataBatch}; - -/// A materialized view: its node in plan `plan`, which fixes what it -/// computes (sub-DAG, selection, sketch parameters, window widths). -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct ViewId { - pub plan: PlanId, - pub node: PhysicalASAPNodeId, -} - -/// One window of one view: the view and its absolute window -/// `(start_ms, end_ms]`. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct ViewInstanceKey { - pub view: ViewId, - pub window_ms: (i64, i64), -} - -/// A view's stored state for one window, for all of the window's group -/// keys. -#[derive(Debug, Clone)] -pub struct ViewInstance { - pub state: ViewState, - pub metadata: ViewInstanceMetadata, -} - -/// What the store knows about an instance besides its opaque state. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct ViewInstanceMetadata { - /// What the state occupies in memory, for the store's memory budget. - pub size_bytes: u64, -} - -/// The engine's native state of one view instance, opaque to the store; -/// the query engine downcasts it. -#[derive(Debug, Clone)] -pub struct ViewState(pub Arc); - -/// Stored view instances, in memory, on disk or both; the implementation -/// chooses its indexing and never looks inside a state. -pub trait ViewStore: Send + Sync { - /// Stores an instance. Each key is put once and never rewritten. - fn put(&self, key: ViewInstanceKey, instance: ViewInstance); - - /// The instance stored under `key`, if any. - fn get(&self, key: &ViewInstanceKey) -> Option; - - /// Each stored instance of `view` whose window lies within - /// `interval_ms` `(start_ms, end_ms]`, with its window. - fn instances(&self, view: &ViewId, interval_ms: (i64, i64)) -> Vec<((i64, i64), ViewInstance)>; - - /// Drops the instances of `view` whose window ends at or before - /// `before_ms`. - fn evict_before(&self, view: &ViewId, before_ms: i64); - - /// Per view with stored instances, the start of its oldest window and - /// the end of its newest, in ms; for runtime info. - fn timestamp_range_per_view(&self) -> HashMap; -} - -/// Stored raw data, per source of the plan's `Scan`s. -pub trait RawDataStore: Send + Sync { - /// Appends a batch of `source`'s raw data. - fn append(&self, source: &Source, batch: RawDataBatch); - - /// `source`'s stored raw data with timestamps in `interval_ms` - /// `(start_ms, end_ms]`, or `None` when the store no longer holds the - /// whole interval (evicted), so the query engine reports `NotReady`. - fn read(&self, source: &Source, interval_ms: (i64, i64)) -> Option; - - /// Drops each listed source's raw data at or before `now_ms` minus its - /// retention's lookback; a source with no lookback keeps all of it. - fn evict(&self, retention: &[RawDataRetention], now_ms: i64); -} diff --git a/crates/common/tests/trait_shapes.rs b/crates/common/tests/trait_shapes.rs index 7f42c9a76..aa28b07f4 100644 --- a/crates/common/tests/trait_shapes.rs +++ b/crates/common/tests/trait_shapes.rs @@ -1,79 +1,14 @@ -//! Each boundary trait can be implemented outside this crate and used as -//! `Arc`, as the deployment holds its engines, stores and fallback. -//! The fakes are trivial: only the trait shapes are under test. +//! `FallbackClient` can be implemented outside this crate and used as +//! `Arc`, as the query routes hold their fallback. The +//! fake is trivial: only the trait's shape is under test. -use std::collections::HashMap; use std::sync::Arc; use async_trait::async_trait; use common::{ - AnswerSource, EngineQueryResult, FallbackClient, FallbackError, FallbackResponse, IngestEngine, - IngestError, InstallError, InstalledPlan, PlanId, QueryEngine, QueryEngineError, QueryEval, - QueryLanguage, QueryRequest, RawDataBatch, RawDataRetention, RawDataStore, Source, ViewId, - ViewInstance, ViewInstanceKey, ViewInstanceMetadata, ViewState, ViewStore, + FallbackClient, FallbackError, FallbackResponse, QueryEval, QueryLanguage, QueryRequest, }; -struct NoIngest; - -#[async_trait] -impl IngestEngine for NoIngest { - fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { - Ok(()) - } - async fn ingest(&self, _batch: RawDataBatch) -> Result<(), IngestError> { - Ok(()) - } - fn shutdown(&self) {} -} - -struct NeverReady; - -#[async_trait] -impl QueryEngine for NeverReady { - fn install(&self, _plan: InstalledPlan) -> Result<(), InstallError> { - Ok(()) - } - async fn execute_batch( - &self, - queries: &[(AnswerSource, QueryRequest)], - ) -> Vec> { - queries - .iter() - .map(|_| Ok(EngineQueryResult::NotReady)) - .collect() - } -} - -struct NoViews; - -impl ViewStore for NoViews { - fn put(&self, _key: ViewInstanceKey, _instance: ViewInstance) {} - fn get(&self, _key: &ViewInstanceKey) -> Option { - None - } - fn instances( - &self, - _view: &ViewId, - _interval_ms: (i64, i64), - ) -> Vec<((i64, i64), ViewInstance)> { - Vec::new() - } - fn evict_before(&self, _view: &ViewId, _before_ms: i64) {} - fn timestamp_range_per_view(&self) -> HashMap { - HashMap::new() - } -} - -struct NoRawData; - -impl RawDataStore for NoRawData { - fn append(&self, _source: &Source, _batch: RawDataBatch) {} - fn read(&self, _source: &Source, _interval_ms: (i64, i64)) -> Option { - None - } - fn evict(&self, _retention: &[RawDataRetention], _now_ms: i64) {} -} - struct Unreachable; #[async_trait] @@ -88,20 +23,8 @@ impl FallbackClient for Unreachable { } #[tokio::test] -async fn every_trait_is_usable_as_a_trait_object() { - let ingest: Arc = Arc::new(NoIngest); - let query: Arc = Arc::new(NeverReady); - let views: Arc = Arc::new(NoViews); - let raw: Arc = Arc::new(NoRawData); +async fn the_fallback_client_is_usable_as_a_trait_object() { let fallback: Arc = Arc::new(Unreachable); - - let labels = [("__name__".to_string(), "up".to_string())].into(); - let batch = RawDataBatch::TimeSeries { - series: vec![(labels, vec![(1_000, 1.0)])], - }; - assert_eq!(ingest.ingest(batch).await, Ok(())); - ingest.shutdown(); - let request = QueryRequest { language: QueryLanguage::PromQL, query: "up".into(), @@ -111,37 +34,5 @@ async fn every_trait_is_usable_as_a_trait_object() { step_ms: 15_000, }, }; - let source = AnswerSource::Planned { - plan: PlanId(1), - root: 0, - }; - assert_eq!( - query.execute(&source, &request).await, - Ok(EngineQueryResult::NotReady) - ); - - let view = ViewId { - plan: PlanId(1), - node: 3, - }; - let key = ViewInstanceKey { - view, - window_ms: (0, 10_000), - }; - views.put( - key, - ViewInstance { - state: ViewState(Arc::new(0_u64)), - metadata: ViewInstanceMetadata { size_bytes: 8 }, - }, - ); - assert!(views.get(&key).is_none()); - - let metric = Source::TimeSeries { - metric: "up".into(), - }; - raw.evict(&[], 0); - assert_eq!(raw.read(&metric, (0, 1)), None); - assert!(fallback.execute(&request, &[]).await.is_err()); }