diff --git a/asap-precompute-rs/src/bin/asap_views_bench.rs b/asap-precompute-rs/src/bin/asap_views_bench.rs index e4ee935..e97f6cc 100644 --- a/asap-precompute-rs/src/bin/asap_views_bench.rs +++ b/asap-precompute-rs/src/bin/asap_views_bench.rs @@ -85,13 +85,21 @@ fn run(views: &str, mode: &str, series: usize, rate: u64, seconds: u64) -> (Dura let mut rng = Rng(0x9E37_79B9_7F4A_7C15); let views = planner_views::parse(views).expect("views load"); // The `sketches` mode builds q01's view: one DDSketch view, 5 s windows. - let [view] = views.views.as_slice() else { - panic!("one view"); - }; - assert_eq!( - (view.sketch, view.tumbling_window_width_ms), - (asap_sketchlib::SketchAlgorithm::DDSketch, 5_000) - ); + // The `executor` mode builds any views, e.g. the exact fixture's. + if mode == "sketches" { + let [view] = views.views.as_slice() else { + panic!("one view"); + }; + assert_eq!( + (view.summary, view.tumbling_window_width_ms), + ( + asap_types::summary_type::SummaryFamily::Sketch( + asap_sketchlib::SketchAlgorithm::DDSketch + ), + 5_000 + ) + ); + } let mut executor = (mode == "executor").then(|| ViewExecutor::new(&views).expect("compiles")); let sketches = (mode == "sketches").then(|| { let config = PrecomputeConfig { diff --git a/asap-precompute-rs/src/otap/capabilities.rs b/asap-precompute-rs/src/otap/capabilities.rs index a7499ef..9d42339 100644 --- a/asap-precompute-rs/src/otap/capabilities.rs +++ b/asap-precompute-rs/src/otap/capabilities.rs @@ -8,7 +8,14 @@ //! except that each `supported_summaries` entry is the planner's //! `SupportedSummary` wrapped as `{"summary", "input", "parameters"}`. The //! sketches, their input kind and their parameter ranges come from the -//! processor's dispatch table ([`SKETCH_TYPES`]). +//! processor's dispatch table ([`SKETCH_TYPES`]). It is read with the +//! planner's semantics in full: `supported_summaries` lists sketches only, +//! and every exact accumulator family is supported unless an exclusion +//! the fields expand into (`DeploymentCapabilities::exclusions`) rules it +//! out. The collector builds `Sum`, `Count`, `Min` and `Max` per series +//! and window over the sample value; `counter_semantics` (no reset +//! handling, no extrapolation) rules out the order-sensitive `Counter` +//! and `IRate` states ([`CollectorCapabilities::exclusion_of`]). //! - `predicate_ops`: the label comparisons the runtime's matchers //! ([`MatchOp`], `PrecomputeConfig::matchers`) evaluate, for every //! operator that takes a predicate. The processor's own config sets no @@ -22,10 +29,13 @@ use std::time::Duration; use asap_types::deployment_capabilities::{ - CounterSemanticsSupport, DeploymentCapabilities, SupportedSummary, + CandidateDescription, CounterSemanticsSupport, DeploymentCapabilities, ExclusionSource, + SupportedSummary, }; use asap_types::ir::operator::{OperatorKind, Reduction, Source}; use asap_types::ir::scalar::CompareOpKind; +use asap_types::plan::physical_asap_dag::PhysicalASAPDAGNode; +use asap_types::stages::PhysicalProperties; use serde::ser::{Error as _, SerializeMap}; use serde::{Serialize, Serializer}; @@ -33,7 +43,10 @@ use super::config::{PluginConfig, SketchInput, SketchParameter, SKETCH_TYPES}; use crate::matchers::MatchOp; /// The version of this format; a reader refuses one it does not know. -pub const CAPABILITIES_VERSION: u32 = 1; +/// Version 2: `executor` is read with the planner's semantics in full, so +/// the exact accumulator families it does not exclude are built (version 1 +/// built sketches only, with the same JSON). +pub const CAPABILITIES_VERSION: u32 = 2; /// What `asap-collector --print-capabilities` prints. #[derive(Debug, Serialize)] @@ -123,6 +136,29 @@ fn serialize_parameters( map.end() } +impl CollectorCapabilities { + /// The capability of `executor` that rules out `node` in the planner's + /// reading: the source of the first of its exclusions + /// (`DeploymentCapabilities::exclusions`) that matches the node's + /// operator, θ, timing and lifetime. `None` when none does, e.g. for + /// an ingestion-time exact `Sum` chain. + pub fn exclusion_of(&self, node: &PhysicalASAPDAGNode) -> Option { + let candidate = CandidateDescription { + operator: &node.payload, + parameters: node.parameters.as_ref(), + physical_properties: PhysicalProperties::new(node.output_state.timing, node.lifetime) + .ok()?, + read_summary_type: None, + }; + self.executor + .deployment_capabilities() + .exclusions() + .into_iter() + .find(|excluded| excluded.exclusion.matches(&candidate)) + .map(|excluded| excluded.source) + } +} + /// One operator the collector runs, with the limits of that operator only. #[derive(Debug, Serialize)] pub struct OperatorCapability { @@ -391,6 +427,73 @@ mod tests { assert_eq!(loaded.window_close_delay_ms, 6000); } + /// The printed `executor`, read as the planner reads it, supports the + /// exact `Sum`, `Count`, `Min` and `Max` families (no exclusion rules + /// any of them out) and excludes the order-sensitive `Counter` and + /// `IRate` ones. + #[test] + fn exact_accumulators_are_in_the_printed_capabilities() { + use asap_types::summary_type::{ExactKind, SummaryFamily}; + let json: serde_json::Value = serde_json::from_str(&capabilities_json()).unwrap(); + assert_eq!(json["capabilities_version"], 2); + let mut executor = json["executor"].clone(); + executor["supported_summaries"] = serde_json::Value::Null; + let parsed: DeploymentCapabilities = serde_json::from_value(executor).unwrap(); + let excluded: Vec = parsed + .exclusions() + .iter() + .filter_map(|excluded| excluded.exclusion.family_excluded_outright()) + .collect(); + for kind in [ + ExactKind::Sum, + ExactKind::Count, + ExactKind::Min, + ExactKind::Max, + ] { + assert!(!excluded.contains(&SummaryFamily::Exact(kind)), "{kind:?}"); + } + for kind in [ExactKind::Counter, ExactKind::IRate] { + assert!(excluded.contains(&SummaryFamily::Exact(kind)), "{kind:?}"); + } + } + + /// The exact fixture's chains (ingestion-time `Sum`, `Count`, `Min` and + /// `Max` per series) match no exclusion; the same chain of a `Counter` + /// matches `counter_semantics`'. + #[test] + fn exact_chains_match_no_exclusion_but_a_counters_does() { + use asap_types::plan::physical_asap_dag::PhysicalASAPDAG; + #[derive(serde::Deserialize)] + struct File { + dag: PhysicalASAPDAG, + } + let file: File = serde_json::from_str(include_str!( + "../../tests/fixtures/collector-views/exact/collector-views.json" + )) + .unwrap(); + let capabilities = collector_capabilities(); + let chains: Vec<&PhysicalASAPDAGNode> = file + .dag + .nodes + .iter() + .filter(|node| { + OperatorKind::of(&node.payload) == OperatorKind::SummaryTumblingWindowChain + }) + .collect(); + assert_eq!(chains.len(), 4); + for chain in &chains { + assert_eq!(capabilities.exclusion_of(chain), None, "node {}", chain.id); + } + let mut counter = serde_json::to_value(chains[0]).unwrap(); + counter["payload"]["ASAP"]["SummaryTumblingWindowChain"]["summary_type"] = + serde_json::json!({"ExactAggregate": ["Counter", "Counter"]}); + let counter: PhysicalASAPDAGNode = serde_json::from_value(counter).unwrap(); + assert_eq!( + capabilities.exclusion_of(&counter), + Some(ExclusionSource::CounterResetsNotHandled) + ); + } + /// `executor`, with each entry replaced by its `summary`, is the /// planner's `DeploymentCapabilities` (its serde denies unknown fields). #[test] diff --git a/asap-precompute-rs/src/otap/codec.rs b/asap-precompute-rs/src/otap/codec.rs index 9bf918d..5d025f3 100644 --- a/asap-precompute-rs/src/otap/codec.rs +++ b/asap-precompute-rs/src/otap/codec.rs @@ -1839,8 +1839,8 @@ struct DecodeMetric { impl DecodeMetric { /// The sketch type of the metric's states: a collector view's, from θ - /// in its view state key; a hand-configured sketch's, from the - /// Resource's `sketch.type`. + /// in its view state key (a key without θ is an exact accumulator's); + /// a hand-configured sketch's, from the Resource's `sketch.type`. fn sketch_type(&self, schema: &DecodeSchema) -> Result { let Some(view) = &self.view else { return parse_sketch_type(schema.sketch_type.as_deref()); @@ -1848,9 +1848,10 @@ impl DecodeMetric { let key: ViewStateKey = serde_json::from_str(&view.view_state_key).map_err(|e| { CodecError::Decode(format!("metric {}: {META_VIEW_STATE_KEY}: {e}", self.name)) })?; - key.logical_properties - .parameters() - .and_then(super::planner_views::sketch_type_spec_of) + let Some(parameters) = key.logical_properties.parameters() else { + return Ok(SketchType::Exact); + }; + super::planner_views::sketch_type_spec_of(parameters) .map(|spec| spec.sketch_type) .ok_or_else(|| { CodecError::Decode(format!( @@ -2562,6 +2563,43 @@ mod tests { assert_eq!(env.payload, state.payload); } + /// An exact view's state (the exact fixture's `Sum`, whose key has no + /// θ) round-trips as `Exact` with its view-layout bytes and count. + #[test] + fn exact_view_state_round_trips_through_otap_arrow() { + let views = super::super::planner_views::parse(include_str!( + "../../tests/fixtures/collector-views/exact/collector-views.json" + )) + .unwrap(); + let sum = views + .views + .iter() + .find(|v| { + v.summary + == asap_types::summary_type::SummaryFamily::Exact( + asap_types::summary_type::ExactKind::Sum, + ) + }) + .unwrap(); + let mut state = q01_state(1_767_225_600_000); + state.sketch_type = SketchType::Exact; + state.view = Some(Arc::clone(&sum.identity)); + state.metric_name = sum.output_metric_name.clone(); + // Sum 7.5, no compensation, seen. + state.payload = [7.5f64.to_le_bytes(), 0f64.to_le_bytes(), 1u64.to_le_bytes()].concat(); + state.count = 3; + let pdata = encode_envelopes_to_pdata(std::slice::from_ref(&state)).expect("encode"); + let decoded = decode_pdata_to_observations(pdata).expect("decode"); + let [obs] = decoded.observations.as_slice() else { + panic!("one state"); + }; + let env = obs.value.envelope.as_ref().expect("a state"); + assert_eq!(env.view, state.view); + assert_eq!(env.sketch_type, SketchType::Exact, "a key without θ"); + assert_eq!(env.payload, state.payload); + assert_eq!(env.count, 3); + } + /// Through OTAP Arrow and the OTAP → OTLP conversion, the state is an /// OTLP Summary point with the raw sample's structure, and the view /// identity is `Metric.metadata`; decoding the OTLP request again gives diff --git a/asap-precompute-rs/src/otap/planner_views.rs b/asap-precompute-rs/src/otap/planner_views.rs index c65fadd..414b4cc 100644 --- a/asap-precompute-rs/src/otap/planner_views.rs +++ b/asap-precompute-rs/src/otap/planner_views.rs @@ -18,10 +18,12 @@ //! v1 accepts each output as a leaf view: a `SummaryTumblingWindowChain` //! over a `Scan` of `TimeSeries { metric }`, with only label `Filter`s //! between them, and reads it into a [`CollectorView`] in the planner's -//! terms: the sketch, its `Scan`, the tumbling width and where its states -//! go. θ (an out-of-range size is an error, never a default) and the label -//! predicates on the way are checked, not kept: ASAPPlanner's executor -//! builds the states from the sub-DAG itself ([`super::view_executor`]). +//! terms: the summary family (a sketch, or an exact accumulator such as +//! `Sum`), its `Scan`, the tumbling width and where its states go. θ (an +//! out-of-range size is an error, never a default), an exact family the +//! capabilities exclude, and the label predicates on the way are checked, +//! not kept: ASAPPlanner's executor builds the states from the sub-DAG +//! itself ([`super::view_executor`]). use std::collections::{BTreeMap, HashMap}; use std::path::Path; @@ -37,7 +39,9 @@ use asap_types::plan::materialized_view::InstallableDagError; use asap_types::plan::physical_asap_dag::{ PhysicalASAPDAG, PhysicalASAPDAGNode, PhysicalASAPNodeId, }; -use asap_types::summary_type::{parameter_list, SketchParams, SummaryInputExpr, SummaryUpdate}; +use asap_types::summary_type::{ + parameter_list, ExactKind, SketchParams, SummaryFamily, SummaryInputExpr, SummaryUpdate, +}; use serde::Deserialize; use super::capabilities::{ @@ -80,9 +84,9 @@ pub struct CollectorViewsFile { /// One checked collector view, in the planner's terms: what a window state /// of the collector must build, one state per series. /// -/// Example (q01): `source_metric: "data"`, `scan_node: 0`, `sketch: -/// DDSketch`, `tumbling_window_width_ms: 5000`, `retention_ms: 60000`, -/// `output_metric_name: "data.asap_view.1"`. +/// Example (q01): `source_metric: "data"`, `scan_node: 0`, `summary: +/// Sketch(DDSketch)`, `tumbling_window_width_ms: 5000`, `retention_ms: +/// 60000`, `output_metric_name: "data.asap_view.1"`. #[derive(Debug, Clone, PartialEq)] pub struct CollectorView { /// The identity stamped on each of its states. @@ -93,8 +97,8 @@ pub struct CollectorView { pub scan_node: PhysicalASAPNodeId, /// The name its states are emitted under: `.asap_view.`. pub output_metric_name: String, - /// The chain's sketch. - pub sketch: SketchAlgorithm, + /// The chain's summary family: a sketch, or an exact accumulator. + pub summary: SummaryFamily, /// The chain's tumbling window width, positive. pub tumbling_window_width_ms: u64, /// The view node's `retention_ms`: how far back from the newest window @@ -286,7 +290,13 @@ fn leaf_view( "must be positive", )); } - let sketch = sketch(chain, summary_type, input, capabilities)?; + let summary = match summary_type { + FieldDataType::ExactAggregate(kind, _) => { + exact(chain, *kind, input, capabilities)?; + SummaryFamily::Exact(*kind) + } + _ => SummaryFamily::Sketch(sketch(chain, summary_type, input, capabilities)?), + }; if let Some(filter) = filter { check_label_predicates( @@ -350,7 +360,7 @@ fn leaf_view( output_metric_name: format!("{metric}{VIEW_NAME_INFIX}{id}"), source_metric: metric, scan_node, - sketch, + summary, tumbling_window_width_ms: *tumbling_window_width_ms, retention_ms, }) @@ -483,6 +493,45 @@ fn sketch( Ok(*algorithm) } +/// Checks an exact accumulator chain of `kind`: it folds each sample's value, +/// has no θ, and no exclusion the capabilities' `executor` expands into (in +/// the planner's reading, every exact family is supported unless one rules +/// it out) matches it. +fn exact( + chain: &PhysicalASAPDAGNode, + kind: ExactKind, + input: &SummaryUpdate, + capabilities: &CollectorCapabilities, +) -> Result<(), PlannerViewsError> { + let id = chain.id; + let sample_value = SummaryUpdate { + item: None, + weight: SummaryInputExpr::Column(ColumnRef::SampleValue), + }; + if *input != sample_value { + return Err(not_executable( + id, + "input", + format!("an exact {kind:?} reads the sample value, not {input:?}"), + )); + } + if let Some(parameters) = &chain.parameters { + return Err(not_executable( + id, + "parameters", + format!("an exact {kind:?} has no θ, not {parameters:?}"), + )); + } + if let Some(source) = capabilities.exclusion_of(chain) { + return Err(not_executable( + id, + "summary_type", + format!("an exact {kind:?} is excluded by the collector's {source}"), + )); + } + Ok(()) +} + /// The `SKETCH_TYPES` row θ `parameters` size: the one whose algorithm's /// planner parameter list (`parameter_list`) holds θ's variant, e.g. /// `DDSketch { alpha }` for DDSketch, `Cms { width, depth }` for Count-Min. @@ -628,7 +677,10 @@ mod tests { assert_eq!(view.source_metric, "data"); assert_eq!(view.scan_node, 0); assert_eq!(view.output_metric_name, "data.asap_view.1"); - assert_eq!(view.sketch, SketchAlgorithm::DDSketch); + assert_eq!( + view.summary, + SummaryFamily::Sketch(SketchAlgorithm::DDSketch) + ); assert_eq!(view.tumbling_window_width_ms, 5000); assert_eq!(view.retention_ms, 60_000); assert!(loaded.drops_raw("data")); @@ -742,4 +794,78 @@ mod tests { let text = q01_with(|f| f["extra"] = 1.into()); assert!(matches!(parse(&text), Err(PlannerViewsError::Parse(_)))); } + + const EXACT: &str = + include_str!("../../tests/fixtures/collector-views/exact/collector-views.json"); + + /// `EXACT` with `edit` applied to its `Sum` chain node. + fn exact_sum_with(edit: impl FnOnce(&mut serde_json::Value)) -> (String, PhysicalASAPNodeId) { + let mut file: serde_json::Value = serde_json::from_str(EXACT).unwrap(); + let node = file["dag"]["nodes"] + .as_array_mut() + .unwrap() + .iter_mut() + .find(|n| { + n["payload"]["ASAP"]["SummaryTumblingWindowChain"]["summary_type"] + == serde_json::json!({"ExactAggregate": ["Sum", "Sum"]}) + }) + .unwrap(); + let id = node["id"].as_u64().unwrap() as PhysicalASAPNodeId; + edit(node); + (file.to_string(), id) + } + + /// The control plane's cut of `sum`, `count`, `avg`, `min` and + /// `max_over_time(data[1m])`: four exact views, `Sum`, `Count`, `Min` + /// and `Max` per series in 5 s windows, with no θ; `data` is not read + /// raw. + #[test] + fn exact_views_load() { + let loaded = parse(EXACT).expect("loads"); + let mut families: Vec = loaded.views.iter().map(|v| v.summary).collect(); + families.sort_by_key(|f| format!("{f:?}")); + assert_eq!( + families, + [ + ExactKind::Count, + ExactKind::Max, + ExactKind::Min, + ExactKind::Sum + ] + .map(SummaryFamily::Exact) + ); + for view in &loaded.views { + assert_eq!(view.source_metric, "data"); + assert_eq!(view.tumbling_window_width_ms, 5_000); + } + assert!(loaded.drops_raw("data")); + } + + /// An exact chain the capabilities exclude (a `Counter`, ruled out by + /// `counter_semantics`) is refused at `summary_type`. + #[test] + fn an_excluded_exact_family_is_refused() { + let (text, id) = exact_sum_with(|node| { + node["payload"]["ASAP"]["SummaryTumblingWindowChain"]["summary_type"] = + serde_json::json!({"ExactAggregate": ["Counter", "Counter"]}); + node["output_schema"]["fields"][1]["dtype"] = + serde_json::json!({"ExactAggregate": ["Counter", "Counter"]}); + }); + assert_eq!(refused_field(&text), (id, "summary_type".into())); + } + + /// An exact chain over anything but the sample value, or with θ, is + /// refused. + #[test] + fn an_exact_chain_needs_the_sample_value_and_no_theta() { + let (text, id) = exact_sum_with(|node| { + node["payload"]["ASAP"]["SummaryTumblingWindowChain"]["input"]["weight"] = + serde_json::json!({"Constant": 1.0}); + }); + assert_eq!(refused_field(&text), (id, "input".into())); + let (text, id) = exact_sum_with(|node| { + node["parameters"] = serde_json::json!({"DDSketch": {"alpha": 0.05}}); + }); + assert_eq!(refused_field(&text), (id, "parameters".into())); + } } diff --git a/asap-precompute-rs/src/otap/view_executor.rs b/asap-precompute-rs/src/otap/view_executor.rs index 6877fd1..76aae57 100644 --- a/asap-precompute-rs/src/otap/view_executor.rs +++ b/asap-precompute-rs/src/otap/view_executor.rs @@ -28,8 +28,14 @@ //! closes every window of its group ending before its own window starts, and //! [`ViewExecutor::close_idle`] every window ending before a time (the //! processor's idle timer). Closing a window ends its run's streams; the run -//! seals its states, each encoded to ASAPv1 into a [`SketchEnvelope`] -//! carrying the view's identity, the series' attributes and the window. +//! seals its states, each encoded into a [`SketchEnvelope`] carrying the +//! view's identity, the series' attributes and the window: a sketch as its +//! ASAPv1 bytes, an exact accumulator (`Sum`, `Count`, `Min`, `Max`) as the +//! executor's view layout of it (`StateColumn::view_bytes`, its fixed-width +//! little-endian record, e.g. a `Sum`'s sum, compensation and whether it saw +//! a sample), the bytes ASAPQuery-backend keeps for the state it builds of +//! the same view. A sketch's state counts its samples; an exact state's +//! window counts them as they are sent ([`WindowRun::sample_counts`]). //! //! A sample of a window its group has closed is late. If the window is still //! within the views' retention (the view nodes' `retention_ms`, counted back @@ -38,8 +44,10 @@ //! only. Correction runs close at the next [`ViewExecutor::close_idle`] (the //! idle timer, so within a timer period) or [`ViewExecutor::drain`], and //! their states ([`Closed::corrections`]) are encoded exactly as the -//! window's own: the same view, series and window, ASAPv1 of the late -//! samples. ASAPQuery-backend merges a correction into the committed window. +//! window's own: the same view, series and window, the state of the late +//! samples. ASAPQuery-backend merges a correction into the committed window: +//! a sketch by its merge, an exact state by its own (sums and counts add, a +//! minimum or maximum is the smaller or larger). //! A late sample beyond retention is dropped, and a value a view's sketch //! refuses (NaN, ±Inf, a DDSketch magnitude outside its range) is rejected: //! both are counted per view, as is every sample a view takes @@ -80,6 +88,7 @@ use asap_executor::planner::ir::schema::{DataType, FieldDataType, PROMQL_SERIES_ use asap_executor::planner::ir::{ASAPOp, Operator}; use asap_executor::planner::plan::materialized_view::MaterializedView; use asap_executor::planner::plan::physical_asap_dag::{PhysicalASAPDAG, PhysicalASAPNodeId}; +use asap_executor::planner::summary_type::SummaryFamily; use asap_executor::runtime::{IngestionOutputs, Limits, OutputStream, RunContext, Scope}; use asap_executor::sources::{DataStore, MaterializedViewRequest, RawDataRequest}; use asap_executor::summary_kernels::{DDSketchAccumulator, DatasketchesKLLAccumulator}; @@ -219,15 +228,15 @@ struct RunGroup { late_rows: Vec, } -/// What a view's states are emitted as, and the values its sketch takes. +/// What a view's states are emitted as, and the values its summary takes. struct GroupView { /// Its position in [`PlannerViews::views`]. index: usize, identity: Arc, output_metric_name: String, - sketch: SketchAlgorithm, + summary: SummaryFamily, sketch_type: SketchType, - /// The executor's kernel for the view's sketch, used only to check a + /// The executor's kernel for the view's summary, used only to check a /// value as the run will. domain: Box, } @@ -255,6 +264,10 @@ struct WindowRun { senders: Vec>>, /// Set when the run finishes. result: RunResult, + /// The samples sent to the run, by series id, when the group has an + /// exact view: an exact state does not count its samples (a `Sum` keeps + /// its sum only), so its envelope's `count` comes from here. + sample_counts: Option>, } /// A window's run outcome, set by the run's task when it finishes. @@ -496,7 +509,8 @@ impl ViewExecutor { /// next sequence of its lineage; and evicts the series no open window or /// correction run holds. fn seal(&mut self, closed: &mut Closed, corrections: bool, open: bool) { - // (metric, group, window end, run result, is a correction). + // (metric, group, window end, (run result, sample counts), is a + // correction). let mut closing = Vec::new(); for (name, metric) in &mut self.metrics { for (index, group) in metric.groups.iter_mut().enumerate() { @@ -510,17 +524,17 @@ impl ViewExecutor { .windows .split_off(&group.closed_through_ms.saturating_add(1)); for (end, run) in std::mem::replace(&mut group.windows, still_open) { - closing.push((name.clone(), index, end, run.result, false)); + closing.push((name.clone(), index, end, run.finish(), false)); } } if open { for (end, run) in std::mem::take(&mut group.windows) { - closing.push((name.clone(), index, end, run.result, false)); + closing.push((name.clone(), index, end, run.finish(), false)); } } if corrections { for (end, run) in std::mem::take(&mut group.corrections) { - closing.push((name.clone(), index, end, run.result, true)); + closing.push((name.clone(), index, end, run.finish(), true)); } } } @@ -529,7 +543,7 @@ impl ViewExecutor { return; } self.pool.run_until_stalled(); - for (name, index, end, result, correction) in &closing { + for (name, index, end, (result, sample_counts), correction) in &closing { let metric = self.metrics.get_mut(name).expect("a closing metric"); let group = &mut metric.groups[*index]; let sequences = group.sequences.entry(*end).or_default(); @@ -564,6 +578,7 @@ impl ViewExecutor { *end, group.width_ms, &metric.series, + sample_counts.as_deref(), &mut lineage, &mut states, )?; @@ -696,40 +711,46 @@ impl RunGroup { dag: &PhysicalASAPDAG, compiled: &CompiledPhysicalDAG, ) -> Result<(), Error> { - if !matches!( - view.sketch, - SketchAlgorithm::DDSketch | SketchAlgorithm::KLL - ) { - return Err(Error::Invalid(format!( - "node {}: the collector does not encode {:?} states", - view.identity.node_id, view.sketch - ))); - } - let spec = SKETCH_TYPES - .iter() - .find(|spec| spec.algorithm == view.sketch) - .expect("the loader accepts only SKETCH_TYPES sketches"); + let sketch_type = match view.summary { + SummaryFamily::Sketch(sketch @ (SketchAlgorithm::DDSketch | SketchAlgorithm::KLL)) => { + SKETCH_TYPES + .iter() + .find(|spec| spec.algorithm == sketch) + .expect("the loader accepts only SKETCH_TYPES sketches") + .sketch_type + } + // The loader accepts only the families the capabilities do not + // exclude: `Sum`, `Count`, `Min` and `Max`. + SummaryFamily::Exact(_) => SketchType::Exact, + other => { + return Err(Error::Invalid(format!( + "node {}: the collector does not encode {other:?} states", + view.identity.node_id + ))) + } + }; let node = dag .nodes .iter() .find(|n| n.id as u64 == view.identity.node_id) .expect("a loaded view is a node of the DAG"); - let Operator::ASAP(ASAPOp::SummaryTumblingWindowChain { input, .. }) = &node.payload else { + let Operator::ASAP(ASAPOp::SummaryTumblingWindowChain { + summary_type, + input, + .. + }) = &node.payload + else { unreachable!("a loaded view is a SummaryTumblingWindowChain"); }; - let domain = create_planner_accumulator( - &FieldDataType::Sketch(view.sketch), - node.parameters.as_ref(), - input, - ) - .map_err(|e| Error::Invalid(format!("node {}: {e}", view.identity.node_id)))?; + let domain = create_planner_accumulator(summary_type, node.parameters.as_ref(), input) + .map_err(|e| Error::Invalid(format!("node {}: {e}", view.identity.node_id)))?; self.roots.push(view.identity.node_id); self.views.push(GroupView { index, identity: Arc::clone(&view.identity), output_metric_name: view.output_metric_name.clone(), - sketch: view.sketch, - sketch_type: spec.sketch_type, + summary: view.summary, + sketch_type, domain, }); if self.scan_nodes.contains(&view.scan_node) { @@ -860,6 +881,15 @@ impl RunGroup { Entry::Occupied(run) => run.into_mut(), Entry::Vacant(slot) => slot.insert(self.open(end, compiled, pool)?), }; + if let Some(counts) = &mut run.sample_counts { + for &(id, _, _) in rows { + let id = id as usize; + if counts.len() <= id { + counts.resize(id + 1, 0); + } + counts[id] += 1; + } + } let columns = TextColumns::new(rows, codes); for (slot, senders) in self.scans.iter().zip(&run.senders) { let batch = slot.batch(rows, &columns, series)?; @@ -915,7 +945,23 @@ impl RunGroup { *finished.borrow_mut() = Some(run.await); }) .map_err(|e| Error::Invalid(format!("cannot start a window's run: {e}")))?; - Ok(WindowRun { senders, result }) + let counts_samples = self + .views + .iter() + .any(|view| matches!(view.summary, SummaryFamily::Exact(_))); + Ok(WindowRun { + senders, + result, + sample_counts: counts_samples.then(Vec::new), + }) + } +} + +impl WindowRun { + /// Ends the run's input (dropping its streams), keeping what its states + /// are encoded with: its outcome and its sample counts. + fn finish(self) -> (RunResult, Option>) { + (self.result, self.sample_counts) } } @@ -1033,14 +1079,17 @@ impl ScanSlot { } /// Appends one envelope per row of `batch`, a run's output for `view` of -/// the window ending at `end_ms`: the row's state as ASAPv1, under the -/// view's identity and name, with its series' attributes. +/// the window ending at `end_ms`: the row's state ([`state_bytes`]), under +/// the view's identity and name, with its series' attributes. +/// `sample_counts` are the run's, by series id. +#[allow(clippy::too_many_arguments)] fn encode( view: &GroupView, batch: &Batch, end_ms: u64, width_ms: u64, series: &[Option], + sample_counts: Option<&[u64]>, lineage: &mut impl FnMut(&Series) -> Lineage, out: &mut Vec, ) -> Result<(), Error> { @@ -1059,12 +1108,18 @@ fn encode( let texts = identities.values().as_string::(); for row in 0..batch.num_rows() { let text = texts.value(identities.keys().value(row) as usize); - let series = text + let id = text .parse::() .ok() - .and_then(|id| series.get(id)?.as_ref()) + .filter(|&id| series.get(id).is_some_and(Option::is_some)) .ok_or_else(|| Error::Invalid(format!("an unknown series identity {text:?}")))?; - let (payload, count) = asapv1(view.sketch, state.1, indices.value(row) as usize)?; + let series = series[id].as_ref().expect("checked"); + let (payload, count) = state_bytes(view.summary, state.1, indices.value(row) as usize)?; + let count = count.unwrap_or_else(|| { + sample_counts + .and_then(|counts| counts.get(id).copied()) + .unwrap_or(0) + }); out.push(SketchEnvelope { schema_version: 1, sketch_type: view.sketch_type, @@ -1104,6 +1159,29 @@ fn random_epoch() -> u64 { std::collections::hash_map::RandomState::new().hash_one((now, std::process::id())) } +/// State `index` of `states` as the bytes the collector sends, and the +/// samples it holds when the state counts them: a sketch's ASAPv1 bytes and +/// count; an exact state's view layout (`StateColumn::view_bytes`, the +/// bytes ASAPQuery-backend stores the state as) and `None`. +fn state_bytes( + summary: SummaryFamily, + states: &StateColumn, + index: usize, +) -> Result<(Vec, Option), Error> { + match summary { + SummaryFamily::Sketch(sketch) => { + let (bytes, count) = asapv1(sketch, states, index)?; + Ok((bytes, Some(count))) + } + SummaryFamily::Exact(kind) => { + let bytes = states.view_bytes(index).ok_or_else(|| { + Error::Invalid(format!("an exact {kind:?} state has no view layout")) + })?; + Ok((bytes.into_owned(), None)) + } + } +} + /// State `index` of `states` as ASAPv1 bytes, and the samples it holds. fn asapv1( sketch: SketchAlgorithm, @@ -1145,6 +1223,7 @@ fn asapv1( mod tests { use super::*; use crate::observation::ObservationValue; + use asap_executor::planner::summary_type::ExactKind; use asap_executor::sources::InMemoryDataStore; use asap_executor::values::Value; use asap_sketchlib::DdSketch; @@ -1341,7 +1420,7 @@ mod tests { for row in 0..batch.num_rows() { let text = texts.value(dict.keys().value(row) as usize); let (bytes, _) = - asapv1(view.sketch, states, indices.value(row) as usize).unwrap(); + state_bytes(view.summary, states, indices.value(row) as usize).unwrap(); out.insert((keys[text].clone(), end), bytes); } } @@ -2211,4 +2290,307 @@ mod tests { executor_build(Q01_LABELS, 1, &samples) ); } + + const EXACT: &str = + include_str!("../../tests/fixtures/collector-views/exact/collector-views.json"); + + /// The exact fixture's view nodes, by family: `Sum`, `Count`, `Min`, + /// `Max` per series in 5 s windows over `data`. + fn exact_nodes() -> [(ExactKind, u64); 4] { + let views = super::super::planner_views::parse(EXACT).expect("loads"); + [ + ExactKind::Sum, + ExactKind::Count, + ExactKind::Min, + ExactKind::Max, + ] + .map(|kind| { + let view = views + .views + .iter() + .find(|v| v.summary == SummaryFamily::Exact(kind)) + .unwrap_or_else(|| panic!("no {kind:?} view")); + assert_eq!(view.tumbling_window_width_ms, 5_000); + (kind, view.identity.node_id) + }) + } + + /// An exact state's value from its view-layout record: a `Sum`'s sum + /// plus its compensation, a `Count`, or a `Min`'s or `Max`'s value + /// (`None`: no sample). + fn exact_value(kind: ExactKind, record: &[u8]) -> Option { + let word = |i: usize| u64::from_le_bytes(record[8 * i..8 * i + 8].try_into().unwrap()); + match kind { + ExactKind::Sum => { + assert_eq!(record.len(), 24); + (word(2) == 1).then(|| f64::from_bits(word(0)) + f64::from_bits(word(1))) + } + ExactKind::Count => { + assert_eq!(record.len(), 8); + Some(word(0) as f64) + } + ExactKind::Min | ExactKind::Max => { + assert_eq!(record.len(), 16); + (word(0) == 1).then(|| f64::from_bits(word(1))) + } + other => panic!("{other:?}"), + } + } + + fn hex(bytes: &[u8]) -> String { + bytes.iter().map(|b| format!("{b:02x}")).collect() + } + + /// Series 0's samples on both sides of the window end T (Prometheus + /// windows `(end - 5 s, end]`): T - 5 s itself is in the window before; + /// T - 4999 ms, T - 2500 ms and T are in the window ending at T; T + 1 ms + /// and T + 5 s in the window ending at T + 5 s. Each view's state of + /// each window holds exactly its window's samples, its envelope counts + /// them, and the states are the golden vectors: the executor's + /// fixed-width little-endian view layout, which ASAPQuery-backend + /// stores for the state it builds of the same view. + #[test] + fn exact_views_build_per_window_states_on_prometheus_boundaries() { + let samples: Vec = [ + (T - 5_000, 100.0), + (T - 4_999, 1.0), + (T - 2_500, 4.0), + (T, 2.5), + (T + 1, 10.0), + (T + 5_000, -3.0), + ] + .into_iter() + .map(|(ts, value)| sample(0, ts, value)) + .collect(); + let states = build(EXACT, &samples, 2); + let states = by_key(&states); + let series = series_key(&samples[0].resource_labels, &samples[0].labels); + // (window end, samples, golden record per view: little-endian + // 8-byte words). + const SEEN: &str = "0100000000000000"; + const NO_COMPENSATION: &str = "0000000000000000"; + let golden = [ + ( + T - 5_000, + 1, + [ + // Sum 100.0. + format!("0000000000005940{NO_COMPENSATION}{SEEN}"), + // Count 1. + "0100000000000000".to_string(), + // Min, Max 100.0. + format!("{SEEN}0000000000005940"), + format!("{SEEN}0000000000005940"), + ], + ), + ( + T, + 3, + [ + // Sum 7.5, count 3, min 1.0, max 4.0. + format!("0000000000001e40{NO_COMPENSATION}{SEEN}"), + "0300000000000000".to_string(), + format!("{SEEN}000000000000f03f"), + format!("{SEEN}0000000000001040"), + ], + ), + ( + T + 5_000, + 2, + [ + // Sum 7.0, count 2, min -3.0, max 10.0. + format!("0000000000001c40{NO_COMPENSATION}{SEEN}"), + "0200000000000000".to_string(), + format!("{SEEN}00000000000008c0"), + format!("{SEEN}0000000000002440"), + ], + ), + ]; + assert_eq!(states.len(), 4 * golden.len()); + for (end, count, records) in golden { + for ((kind, node), record) in exact_nodes().into_iter().zip(records) { + let state = states[&(node, series.clone(), end)]; + assert_eq!(state.sketch_type, SketchType::Exact, "{kind:?}"); + assert_eq!(state.metric_name, format!("data.asap_view.{node}")); + assert_eq!( + (state.window_start_ms, state.window_end_ms), + (end - 5_000, end) + ); + assert_eq!(state.count, count, "{kind:?} {end}"); + assert_eq!(hex(&state.payload), record, "{kind:?} {end}"); + } + } + } + + /// The exact views' states are byte-for-byte the executor's own build + /// of the same samples (as ASAPQuery-backend builds the view: one batch + /// per window), whatever the batching here, and hold the window's sum, + /// count, minimum and maximum. + #[test] + fn exact_states_are_the_executors_own_build() { + let samples = samples(); + let states = build(EXACT, &samples, 7); + for (kind, node) in exact_nodes() { + let reference = executor_build(EXACT, node, &samples); + assert_eq!(reference.len(), 18, "{kind:?}"); + for batch in [1, 7, 100] { + assert_eq!( + bytes_of(&build(EXACT, &samples, batch), node), + reference, + "{kind:?}, {batch} per flush" + ); + } + for ((_, series, end), state) in + by_key(&states).into_iter().filter(|(k, _)| k.0 == node) + { + let values: Vec = samples + .iter() + .filter(|obs| { + series_key(&obs.resource_labels, &obs.labels) == series + && window_end_ms(obs.timestamp_ms, 5_000) == end + }) + .map(|obs| obs.value.float) + .collect(); + let expected = match kind { + ExactKind::Sum => values.iter().sum(), + ExactKind::Count => values.len() as f64, + ExactKind::Min => values.iter().copied().fold(f64::INFINITY, f64::min), + _ => values.iter().copied().fold(f64::NEG_INFINITY, f64::max), + }; + let value = exact_value(kind, &state.payload).unwrap(); + assert!( + (value - expected).abs() <= 1e-9 * expected.abs(), + "{kind:?} {end}: {value} vs {expected}" + ); + assert_eq!(state.count, values.len() as u64); + } + } + } + + /// A late sample of a closed window within retention goes to a + /// correction state of that window, as for a sketch: per view, the + /// window's state merged with its correction (sums and counts added, + /// the smaller minimum, the larger maximum) is the state of all the + /// window's samples on time, and the correction counts the late samples. + #[test] + fn exact_corrections_merge_into_the_on_time_state() { + // Integral values, so a sum is exact in any order. + let samples: Vec = samples() + .into_iter() + .map(|mut obs| { + obs.value = ObservationValue::float((obs.value.float * 8.0).round()); + obs + }) + .collect(); + let on_time = build(EXACT, &samples, 7); + let on_time = by_key(&on_time); + let (late, early): (Vec, Vec) = samples + .iter() + .cloned() + .partition(|obs| obs.timestamp_ms == T - 5_000 + 10); + let views = super::super::planner_views::parse(EXACT).unwrap(); + let mut executor = ViewExecutor::new(&views).unwrap(); + let mut windows = Vec::new(); + for obs in &early { + executor.observe(obs); + } + windows.extend(states(executor.flush())); + for obs in &late { + executor.observe(obs); + } + let closed = executor.flush(); + assert!( + closed.corrections.is_empty(), + "a flush keeps corrections open" + ); + windows.extend(states(closed)); + let closed = executor.drain(); + let corrections = closed.corrections.clone(); + windows.extend(states(closed)); + assert_eq!(corrections.len(), 4 * 6, "one per view and series"); + assert!(executor + .counts() + .iter() + .all(|c| c.folded == 6 * 8 * 3 && c.beyond_retention == 0 && c.rejected == 0)); + let windows = by_key(&windows); + assert_eq!(windows.len(), on_time.len()); + let nodes: Map = exact_nodes().into_iter().map(|(k, n)| (n, k)).collect(); + for (key, correction) in by_key(&corrections) { + let kind = nodes[&key.0]; + assert_eq!(key.2, T); + assert_eq!(correction.count, 1); + assert_eq!(correction.sketch_type, SketchType::Exact); + let window = windows[&key]; + assert_eq!(window.count, 7); + let (a, b) = ( + exact_value(kind, &window.payload).unwrap(), + exact_value(kind, &correction.payload).unwrap(), + ); + let merged = match kind { + ExactKind::Sum | ExactKind::Count => a + b, + ExactKind::Min => a.min(b), + _ => a.max(b), + }; + assert_eq!( + merged, + exact_value(kind, &on_time[&key].payload).unwrap(), + "{kind:?}" + ); + } + } + + /// Exact states carry the lineage frame as sketches do: per view, + /// series and window a full (0), then a delta per emission of the open + /// window and per correction. Two corrections of one late sample of the + /// same value each are equal records (`Count` 1, `Sum` 5.0) but + /// sequences 1 and 2 of their lineage, so the backend merges both, and + /// the increments add up to the window's state. + #[test] + fn exact_deltas_and_equal_corrections_carry_distinct_sequences() { + let views = super::super::planner_views::parse(EXACT).unwrap(); + let mut executor = ViewExecutor::with_epoch(&views, 9).unwrap(); + executor.observe(&sample(0, T - 4_000, 1.0)); + let full = states(executor.emit_open()); + executor.observe(&sample(0, T - 3_000, 2.0)); + let delta = states(executor.emit_open()); + // The next window's sample closes the window ending at T. + executor.observe(&sample(0, T + 1, 3.0)); + let closed = states(executor.flush()); + let mut corrections = Vec::new(); + for _ in 0..2 { + executor.observe(&sample(0, T - 1_000, 5.0)); + corrections.push(executor.close_idle(T + 1)); + } + let corrections: Vec> = + corrections.into_iter().map(|c| c.corrections).collect(); + for (kind, node) in exact_nodes() { + let of_view = |states: &[SketchEnvelope]| -> Vec<(u64, u64, Vec)> { + states + .iter() + .filter(|s| s.view.as_ref().unwrap().node_id == node && s.window_end_ms == T) + .map(|s| { + let lineage = s.lineage.expect("an exact state has a lineage"); + assert_eq!(lineage.producer_epoch, 9); + (lineage.sequence, s.count, s.payload.clone()) + }) + .collect() + }; + let [(s0, c0, _)] = of_view(&full)[..] else { + panic!("{kind:?} full") + }; + let [(s1, c1, _)] = of_view(&delta)[..] else { + panic!("{kind:?} delta") + }; + assert!(of_view(&closed).is_empty(), "nothing new at the close"); + let [(s2, c2, ref first)] = of_view(&corrections[0])[..] else { + panic!("{kind:?} first correction") + }; + let [(s3, c3, ref second)] = of_view(&corrections[1])[..] else { + panic!("{kind:?} second correction") + }; + assert_eq!((s0, s1, s2, s3), (0, 1, 2, 3), "{kind:?}"); + assert_eq!((c0, c1, c2, c3), (1, 1, 1, 1), "{kind:?}"); + assert_eq!(first, second, "{kind:?}: equal records, distinct sequences"); + } + } } diff --git a/asap-precompute-rs/tests/fixtures/collector-views/exact/collector-views.json b/asap-precompute-rs/tests/fixtures/collector-views/exact/collector-views.json new file mode 100644 index 0000000..8d318fc --- /dev/null +++ b/asap-precompute-rs/tests/fixtures/collector-views/exact/collector-views.json @@ -0,0 +1,596 @@ +{ + "planner_wire_version": 16, + "plan_id": "77e3e59b6e684dbb30034135fbb25a44", + "backend_reads_raw": { + "data": false + }, + "outputs": [ + 1, + 6, + 12, + 16 + ], + "dag": { + "nodes": [ + { + "id": 0, + "payload": { + "NonASAP": { + "Scan": { + "source": { + "TimeSeries": { + "metric": "data" + } + }, + "predicates": [], + "schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 1, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "9f73cc54cb2cc55c9c57db786b05835b", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 6, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "d90ddea318e29c482ef97c41cf42dfcb", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 12, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "5def88e5b03239e67a3438c1157642ef", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 16, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "4ad134f0fb4735e508eebcd8dac18b7b", + "selection": [ + { + "columns": [] + } + ] + } + } + ], + "edges": [ + { + "producer": 0, + "consumer": 1, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 6, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 12, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 16, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + } + ], + "roots": [ + 1, + 6, + 12, + 16 + ], + "scalar_roots": [] + } +} \ No newline at end of file diff --git a/asap-precompute-rs/tests/fixtures/collector-views/exact/installed-plan.json b/asap-precompute-rs/tests/fixtures/collector-views/exact/installed-plan.json new file mode 100644 index 0000000..0e6a12f --- /dev/null +++ b/asap-precompute-rs/tests/fixtures/collector-views/exact/installed-plan.json @@ -0,0 +1,2130 @@ +{ + "wire_version": 16, + "dag": { + "nodes": [ + { + "id": 0, + "payload": { + "NonASAP": { + "Scan": { + "source": { + "TimeSeries": { + "metric": "data" + } + }, + "predicates": [], + "schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 1, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "9f73cc54cb2cc55c9c57db786b05835b", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 2, + "payload": { + "NonASAP": { + "TimeRange": { + "range": { + "secs": 60, + "nanos": 0 + }, + "kind": "range", + "child": 1 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + } + }, + { + "id": 3, + "payload": { + "ASAP": { + "SummaryMerge": { + "children": [ + 2 + ] + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": { + "OneEvaluation": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 4, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 3 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 5, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 3 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 6, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "d90ddea318e29c482ef97c41cf42dfcb", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 7, + "payload": { + "NonASAP": { + "TimeRange": { + "range": { + "secs": 60, + "nanos": 0 + }, + "kind": "range", + "child": 6 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + } + }, + { + "id": 8, + "payload": { + "ASAP": { + "SummaryMerge": { + "children": [ + 7 + ] + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": { + "OneEvaluation": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 9, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 8 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 10, + "payload": { + "NonASAP": { + "BinaryOp": { + "operator": { + "checked_relative_division": false, + "checked_finite_division": true, + "kind": { + "Arithmetic": "Div" + }, + "vector_match": null + }, + "return_bool": false, + "lhs": 4, + "rhs": 9 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 11, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 8 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 12, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "5def88e5b03239e67a3438c1157642ef", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 13, + "payload": { + "NonASAP": { + "TimeRange": { + "range": { + "secs": 60, + "nanos": 0 + }, + "kind": "range", + "child": 12 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + } + }, + { + "id": 14, + "payload": { + "ASAP": { + "SummaryMerge": { + "children": [ + 13 + ] + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": { + "OneEvaluation": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 15, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 14 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 16, + "payload": { + "ASAP": { + "SummaryTumblingWindowChain": { + "child": 0, + "summary_type": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "input": { + "item": null, + "weight": { + "Column": "SampleValue" + } + }, + "reduction": "PerEntity", + "filter": null, + "tumbling_window_width_ms": 5000 + } + } + }, + "output_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "lifetime": { + "AcrossEvaluations": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "retention_ms": 60000, + "view_coverage": { + "definition_id": "4ad134f0fb4735e508eebcd8dac18b7b", + "selection": [ + { + "columns": [] + } + ] + } + }, + { + "id": 17, + "payload": { + "NonASAP": { + "TimeRange": { + "range": { + "secs": 60, + "nanos": 0 + }, + "kind": "range", + "child": 16 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + } + }, + { + "id": 18, + "payload": { + "ASAP": { + "SummaryMerge": { + "children": [ + 17 + ] + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "lifetime": { + "OneEvaluation": "Memory" + }, + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + }, + { + "id": 19, + "payload": { + "ASAP": { + "FinalizeExactAccumulator": { + "child": 18 + } + } + }, + "output_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "lifetime": "None", + "output_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + } + } + ], + "edges": [ + { + "producer": 0, + "consumer": 1, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 1, + "consumer": 2, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 2, + "consumer": 3, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 3, + "consumer": 4, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 3, + "consumer": 5, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Sum", + "Sum" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 6, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 6, + "consumer": 7, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 7, + "consumer": 8, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 8, + "consumer": 9, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 4, + "consumer": 10, + "role": "Left", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 9, + "consumer": 10, + "role": "Right", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 8, + "consumer": 11, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Count", + "Count" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 12, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 12, + "consumer": 13, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 13, + "consumer": 14, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 14, + "consumer": 15, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Min", + "Min" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 0, + "consumer": 16, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "value", + "dtype": { + "Plain": "float64" + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "Raw" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 16, + "consumer": 17, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "ingestion_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 17, + "consumer": 18, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "window_end", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 0, + 2 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + }, + { + "producer": 18, + "consumer": 19, + "role": "Input", + "intermediate_schema": { + "fields": [ + { + "name": "ts", + "dtype": { + "Plain": "timestamp" + }, + "nullable": false + }, + { + "name": "state", + "dtype": { + "ExactAggregate": [ + "Max", + "Max" + ] + }, + "nullable": false + }, + { + "name": "$promql_series_identity", + "dtype": { + "Plain": "utf8" + }, + "nullable": false + } + ], + "time_index": 0, + "unique_keys": [ + [ + 2, + 0 + ] + ], + "closed": true + }, + "data_state": { + "timing": "query_time", + "primitive": "SummaryState" + }, + "grouping": "NotApplicable", + "window": "NotApplicable" + } + ], + "roots": [ + 5, + 11, + 10, + 15, + 19 + ], + "scalar_roots": [] + }, + "query_texts": [ + "sum_over_time(data[1m])", + "count_over_time(data[1m])", + "avg_over_time(data[1m])", + "min_over_time(data[1m])", + "max_over_time(data[1m])" + ] +} \ No newline at end of file diff --git a/asap-precompute-rs/tests/fixtures/collector-views/exact/planner-workload.json b/asap-precompute-rs/tests/fixtures/collector-views/exact/planner-workload.json new file mode 100644 index 0000000..0e4631d --- /dev/null +++ b/asap-precompute-rs/tests/fixtures/collector-views/exact/planner-workload.json @@ -0,0 +1,97 @@ +{ + "query_workload": { + "language": "promql", + "query_batch": null, + "repeating_queries": [ + { + "query": "sum_over_time(data[1m])", + "demand": { + "fixed_interval_at": { + "interval": 5000, + "evaluation_phase": 0 + } + }, + "requirements": {}, + "predictability": { + "predictable": { + "known_at": null + } + } + }, + { + "query": "count_over_time(data[1m])", + "demand": { + "fixed_interval_at": { + "interval": 5000, + "evaluation_phase": 0 + } + }, + "requirements": {}, + "predictability": { + "predictable": { + "known_at": null + } + } + }, + { + "query": "avg_over_time(data[1m])", + "demand": { + "fixed_interval_at": { + "interval": 5000, + "evaluation_phase": 0 + } + }, + "requirements": {}, + "predictability": { + "predictable": { + "known_at": null + } + } + }, + { + "query": "min_over_time(data[1m])", + "demand": { + "fixed_interval_at": { + "interval": 5000, + "evaluation_phase": 0 + } + }, + "requirements": {}, + "predictability": { + "predictable": { + "known_at": null + } + } + }, + { + "query": "max_over_time(data[1m])", + "demand": { + "fixed_interval_at": { + "interval": 5000, + "evaluation_phase": 0 + } + }, + "requirements": {}, + "predictability": { + "predictable": { + "known_at": null + } + } + } + ] + }, + "data_workload": { + "arrival": { + "ingesting": { + "rows_per_second": 100000.0 + } + }, + "sources": { + "data": { + "series_count": 10000, + "sample_interval": 100, + "metric_type": "gauge" + } + } + } +} diff --git a/asap-precompute-rs/tests/golden/capabilities.json b/asap-precompute-rs/tests/golden/capabilities.json index 6461d5f..b4921d7 100644 --- a/asap-precompute-rs/tests/golden/capabilities.json +++ b/asap-precompute-rs/tests/golden/capabilities.json @@ -1,5 +1,5 @@ { - "capabilities_version": 1, + "capabilities_version": 2, "executor": { "supported_summaries": [ {