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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/devtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ edition = "2021"
# matching `asap-frontend-*` crate directly to avoid pulling the other parser.
[dependencies]
asap-frontend-promql = { path = "../frontend-promql" }
asap-frontend-metricsql = { path = "../frontend-metricsql" }
asap-frontend-sql = { path = "../frontend-sql" }
asap-accuracy = { path = "../accuracy" }
asap-stage0-memo = { path = "../stage0-memo" }
asap-stage1-pass1-per-computation-candidates = { path = "../stage1-pass1-per-computation-candidates" }
asap-stage1-pass2-reuse-candidates = { path = "../stage1-pass2-reuse-candidates" }
Expand All @@ -30,7 +30,7 @@ asap-executor = { path = "../executor" }
# examples. Regular deps, not dev-deps: `[[bin]]` targets can't see dev-deps.
asap-types = { path = "../types" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_json = { version = "1", features = ["float_roundtrip"] }
serde_yaml = "0.9"
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }

Expand Down
874 changes: 685 additions & 189 deletions crates/devtools/src/bin/asap_planner.rs

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions crates/devtools/src/bin/planner_fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// cargo run -p asap-devtools --bin planner_fuzz -- \
// --seed 1 --cases 200 --time-budget-s 600 --out /tmp/planner-fuzz
// cargo run -p asap-devtools --bin planner_fuzz -- \
// --seed 2 --cases 50 --relations a,b,tighter-accuracy --search candidate-connections \
// --seed 2 --cases 50 --relations b,c,added-query --search candidate-connections \
// --seed-workload eval/rangeheavy.workload.json --out out
//
// Metamorphic fuzz testing for missed reuse and sharing
Expand All @@ -14,11 +14,10 @@
// draft per distinct shrunk violation with its two workload files. Nothing
// is filed.
//
// `--relations` takes relation names or the letters a–o (default: all);
// `--search` is `candidate-connections` (the default search);
// `--ignore-accuracy-guarantees` accepts every output
// regardless of its accuracy guarantee (guarantees are enforced by
// default, as `plan_installable` does). A relation is violated when it misses by more
// `--relations` takes relation names or the letters b–o (default: all);
// `--search` is `candidate-connections` (the default search). Every
// workload is planned with accuracy not enforced (no query has an accuracy
// target), so a witness needs no accuracy check. A relation is violated when it misses by more
// than max(`--relative-tolerance` (default 0.01) × cost,
// `--absolute-tolerance` (default 1e-6)). `--max-shrink-attempts` (default
// 60) bounds the checks one shrink runs. Each case and each shrink runs in
Expand All @@ -34,7 +33,7 @@ use asap_devtools::planner_fuzz::{read_seed_file, FuzzSettings, SearchKind};

const USAGE: &str = "usage: planner_fuzz --seed <u64> --cases <n> --time-budget-s <s> \
[--relations <name|letter>,...] [--search candidate-connections] \
[--seed-workload <file>]... [--ignore-accuracy-guarantees] [--relative-tolerance <f64>] \
[--seed-workload <file>]... [--relative-tolerance <f64>] \
[--absolute-tolerance <f64>] [--max-shrink-attempts <n>] [--case-timeout-s <s>] --out <dir>";

fn main() {
Expand Down Expand Up @@ -98,7 +97,6 @@ fn run(args: Vec<String>) -> Result<(), String> {
}
}
"--seed-workload" => seeds.push(read_seed_file(&PathBuf::from(value()?))?),
"--ignore-accuracy-guarantees" => settings.enforce_accuracy_guarantees = false,
"--relative-tolerance" => {
settings.relative_tolerance = value()?.parse().map_err(|e| format!("{e}"))?
}
Expand Down
81 changes: 58 additions & 23 deletions crates/devtools/src/candidate_labels.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//! Display labels for the planning stages' candidates, for the
//! `asap_planner` viewer document and text
//! only. Planning never reads them: they
//! are pure functions of the candidates' planning data (the logical roots
//! and the physical properties assignment).
//! Display labels for the planning stages' operators and parameters, for
//! the `asap_planner` viewer document and text only. Planning never reads
//! them: they are pure functions of the candidates' planning data.

use serde_json::Value;

/// One node's operator kind with its sketch family and parameters, its
/// summary query, its time range and its tumbling-window layout, when it has them: e.g.
/// `SummaryAgg Kll(k=200)`, `SummaryEstimate Quantile(q=0.5)`.
pub fn node_label(node: &asap_types::ir::flat::FlatNode) -> String {
let operator = serde_json::to_value(&node.operator).unwrap_or_default();
use asap_types::ir::Operator;
use asap_types::summary_type::SketchParams;

/// An operator's kind with its summary type, its summary query, its time
/// range and its tumbling-window width, when it has them, without its
/// inputs: e.g. `SummaryAgg Kll`, `SummaryEstimate Quantile(q=0.5)`,
/// `TimeRange 600s`.
pub fn operator_label<C>(operator: &Operator<C>) -> String {
let operator = serde_json::to_value(operator.map_children(|_| ())).unwrap_or_default();
// `{"ASAP": {"SummaryAgg": {...}}}` (or a unit variant's string).
let (kind, fields) = match operator.as_object().and_then(|o| o.values().next()) {
Some(Value::Object(inner)) => match inner.iter().next() {
Expand All @@ -30,7 +32,22 @@ pub fn node_label(node: &asap_types::ir::flat::FlatNode) -> String {
label
}

/// Sketch algorithms with parameters, summary queries and time ranges found
/// A sketch's parameters θ: e.g. `Kll(k=269)`, `Cms(width=2719, depth=5)`.
pub fn parameters_label(parameters: &SketchParams) -> String {
let value = serde_json::to_value(parameters).unwrap_or_default();
let Some((algorithm, fields)) = value.as_object().and_then(|o| o.iter().next()) else {
return value.to_string();
};
let fields: Vec<String> = fields
.as_object()
.into_iter()
.flatten()
.map(|(key, value)| format!("{key}={value}"))
.collect();
format!("{algorithm}({})", fields.join(", "))
}

/// Summary types, summary queries, measures, time ranges and windows found
/// in an operator's fields (not inside its schemas).
fn find_details(value: &Value, details: &mut Vec<String>, depth: usize) {
if depth > 6 || details.len() >= 4 {
Expand Down Expand Up @@ -63,17 +80,6 @@ fn find_details(value: &Value, details: &mut Vec<String>, depth: usize) {
};
match value {
Value::Object(fields) => {
if let (Some(Value::String(algorithm)), Some(params)) =
(fields.get("algorithm"), fields.get("params"))
{
let params = params
.as_object()
.and_then(|p| p.values().next())
.map(compact)
.unwrap_or_default();
details.push(format!("{algorithm}({params})"));
return;
}
for (key, field) in fields {
match key.as_str() {
"schema" | "input_schema" | "output_schema" | "predicates" | "cols" => {}
Expand All @@ -96,9 +102,11 @@ fn find_details(value: &Value, details: &mut Vec<String>, depth: usize) {
details.push(format!("{kind}({})", params.join(", ")));
}
}
// A summary type, e.g. `Kll` or `ExactAggregate(Rate)`.
"summary_type" => details.push(summary_type_text(field)),
// A time range's length, e.g. `60s`.
"range" => details.push(duration_text(field)),
// A window, and a tumbling-window chain's layout.
// A window, and a tumbling-window chain's width.
"window" | "tumbling_window_width_ms" => details.push(format!("{key}={field}")),
_ => find_details(field, details, depth + 1),
}
Expand All @@ -113,6 +121,33 @@ fn find_details(value: &Value, details: &mut Vec<String>, depth: usize) {
}
}

/// A serialized summary type: `Kll` (`{"Sketch": "Kll"}`),
/// `ExactAggregate(Rate)` (`{"ExactAggregate": ["Rate", "Rate"]}`, the
/// distinct names), or the JSON of any other value.
fn summary_type_text(value: &Value) -> String {
match value {
Value::String(name) => name.clone(),
Value::Object(fields) if fields.len() == 1 => {
let (kind, inner) = fields.iter().next().expect("one field");
let mut names: Vec<String> = match inner {
Value::String(name) => vec![name.clone()],
Value::Array(items) => items
.iter()
.map(|item| item.as_str().map_or(item.to_string(), str::to_owned))
.collect(),
other => vec![other.to_string()],
};
names.dedup();
if kind == "Sketch" {
names.join(", ")
} else {
format!("{kind}({})", names.join(", "))
}
}
other => other.to_string(),
}
}

/// A serialized `Duration` (`{"secs": 60, "nanos": 0}`) as `60s`, or
/// `1500ms` when it is not whole seconds; any other value as its JSON.
fn duration_text(value: &Value) -> String {
Expand Down
1 change: 1 addition & 0 deletions crates/devtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod planner_layering_examples;
pub mod planning_stages;
pub mod planning_stages_text;
pub mod rqe_atomic_costs;
pub mod stable_output;

use asap_frontend_promql::lower_promql_query_workload;
pub use asap_frontend_promql::PromqlError;
Expand Down
Loading
Loading