Skip to content

Commit 0226a98

Browse files
Added Rust version of asap-planner (#174)
* Added many crates from asa-common to Cargo workspace * Moved some files from asa-query-engine to asap-common * formatting * removed unnecessary method * Added Rust version of Controller * formatting * clippy fixes * Updated CI * Added some more test * formatting * fixed clippy * Added more tests * Removed unused file
1 parent 8ddb32f commit 0226a98

33 files changed

Lines changed: 3291 additions & 2 deletions

‎Cargo.lock‎

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"asap-common/dependencies/rs/sketch_db_common",
88
"asap-common/dependencies/rs/datafusion_summary_library",
99
"asap-query-engine",
10+
"asap-planner-rs",
1011
]
1112

1213
[workspace.package]
@@ -33,3 +34,5 @@ promql_utilities = { path = "asap-common/dependencies/rs/promql_utilities" }
3334
sql_utilities = { path = "asap-common/dependencies/rs/sql_utilities" }
3435
sketch_db_common = { path = "asap-common/dependencies/rs/sketch_db_common" }
3536
datafusion_summary_library = { path = "asap-common/dependencies/rs/datafusion_summary_library" }
37+
asap_planner = { path = "asap-planner-rs" }
38+
indexmap = { version = "2.0", features = ["serde"] }

‎asap-planner-rs/Cargo.toml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "asap_planner"
3+
version.workspace = true
4+
edition.workspace = true
5+
6+
[lib]
7+
name = "asap_planner"
8+
path = "src/lib.rs"
9+
10+
[[bin]]
11+
name = "asap-planner"
12+
path = "src/main.rs"
13+
14+
[dependencies]
15+
sketch_db_common.workspace = true
16+
promql_utilities.workspace = true
17+
serde.workspace = true
18+
serde_json.workspace = true
19+
serde_yaml.workspace = true
20+
thiserror.workspace = true
21+
anyhow.workspace = true
22+
tracing.workspace = true
23+
tracing-subscriber.workspace = true
24+
clap.workspace = true
25+
indexmap.workspace = true
26+
promql-parser = "0.5.0"
27+
28+
[dev-dependencies]
29+
tempfile = "3.20"
30+
pretty_assertions = "1.4"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use serde::Deserialize;
2+
3+
#[derive(Debug, Clone, Deserialize)]
4+
pub struct ControllerConfig {
5+
pub query_groups: Vec<QueryGroup>,
6+
pub metrics: Vec<MetricDefinition>,
7+
pub sketch_parameters: Option<SketchParameterOverrides>,
8+
pub aggregate_cleanup: Option<AggregateCleanupConfig>,
9+
}
10+
11+
#[derive(Debug, Clone, Deserialize)]
12+
pub struct QueryGroup {
13+
pub id: Option<u32>,
14+
pub queries: Vec<String>,
15+
pub repetition_delay: u64,
16+
pub controller_options: ControllerOptions,
17+
}
18+
19+
#[derive(Debug, Clone, Deserialize)]
20+
pub struct ControllerOptions {
21+
pub accuracy_sla: f64,
22+
pub latency_sla: f64,
23+
}
24+
25+
#[derive(Debug, Clone, Deserialize)]
26+
pub struct MetricDefinition {
27+
pub metric: String,
28+
pub labels: Vec<String>,
29+
}
30+
31+
#[derive(Debug, Clone, Deserialize)]
32+
pub struct AggregateCleanupConfig {
33+
pub policy: Option<String>,
34+
}
35+
36+
#[derive(Debug, Clone, Deserialize, Default)]
37+
pub struct SketchParameterOverrides {
38+
#[serde(rename = "CountMinSketch")]
39+
pub count_min_sketch: Option<CmsParams>,
40+
#[serde(rename = "CountMinSketchWithHeap")]
41+
pub count_min_sketch_with_heap: Option<CmsHeapParams>,
42+
#[serde(rename = "DatasketchesKLL")]
43+
pub datasketches_kll: Option<KllParams>,
44+
#[serde(rename = "HydraKLL")]
45+
pub hydra_kll: Option<HydraParams>,
46+
}
47+
48+
#[derive(Debug, Clone, Deserialize)]
49+
pub struct CmsParams {
50+
pub depth: u64,
51+
pub width: u64,
52+
}
53+
54+
#[derive(Debug, Clone, Deserialize)]
55+
pub struct CmsHeapParams {
56+
pub depth: u64,
57+
pub width: u64,
58+
pub heap_multiplier: Option<u64>,
59+
}
60+
61+
#[derive(Debug, Clone, Deserialize)]
62+
pub struct KllParams {
63+
#[serde(rename = "K")]
64+
pub k: u64,
65+
}
66+
67+
#[derive(Debug, Clone, Deserialize)]
68+
pub struct HydraParams {
69+
pub row_num: u64,
70+
pub col_num: u64,
71+
pub k: u64,
72+
}

‎asap-planner-rs/src/config/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod input;
2+
pub use input::*;

‎asap-planner-rs/src/error.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use thiserror::Error;
2+
3+
#[derive(Debug, Error)]
4+
pub enum ControllerError {
5+
#[error("IO error: {0}")]
6+
Io(#[from] std::io::Error),
7+
#[error("YAML parse error: {0}")]
8+
YamlParse(#[from] serde_yaml::Error),
9+
#[error("PromQL parse error: {0}")]
10+
PromQLParse(String),
11+
#[error("Duplicate query: {0}")]
12+
DuplicateQuery(String),
13+
#[error("Planner error: {0}")]
14+
PlannerError(String),
15+
#[error("Unknown metric: {0}")]
16+
UnknownMetric(String),
17+
}

0 commit comments

Comments
 (0)