|
1 | 1 | use asap_planner::{Controller, RuntimeOptions, SQLController, SQLRuntimeOptions, StreamingEngine}; |
2 | 2 | use clap::Parser; |
| 3 | +use promql_utilities::data_model::KeyByLabelNames; |
3 | 4 | use sketch_db_common::enums::QueryLanguage; |
4 | 5 | use std::path::PathBuf; |
5 | 6 |
|
@@ -56,6 +57,19 @@ enum EngineArg { |
56 | 57 | Precompute, |
57 | 58 | } |
58 | 59 |
|
| 60 | +/// Build a `PromQLSchema` from the `metrics` hints in a controller config file. |
| 61 | +fn schema_from_config_file(path: &PathBuf) -> anyhow::Result<asap_planner::PromQLSchema> { |
| 62 | + let yaml_str = std::fs::read_to_string(path)?; |
| 63 | + let config: asap_planner::ControllerConfig = serde_yaml::from_str(&yaml_str)?; |
| 64 | + let mut schema = asap_planner::PromQLSchema::new(); |
| 65 | + if let Some(metrics) = &config.metrics { |
| 66 | + for m in metrics { |
| 67 | + schema = schema.add_metric(m.metric.clone(), KeyByLabelNames::new(m.labels.clone())); |
| 68 | + } |
| 69 | + } |
| 70 | + Ok(schema) |
| 71 | +} |
| 72 | + |
59 | 73 | fn main() -> anyhow::Result<()> { |
60 | 74 | let args = Args::parse(); |
61 | 75 |
|
@@ -89,19 +103,19 @@ fn main() -> anyhow::Result<()> { |
89 | 103 | (Some(config_path), None, Some(url)) => { |
90 | 104 | Controller::from_file(&config_path, opts, &url)? |
91 | 105 | } |
92 | | - (Some(config_path), None, None) => Controller::from_file_with_schema( |
93 | | - &config_path, |
94 | | - asap_planner::PromQLSchema::new(), |
95 | | - opts, |
96 | | - )?, |
| 106 | + (Some(config_path), None, None) => { |
| 107 | + let schema = schema_from_config_file(&config_path)?; |
| 108 | + Controller::from_file_with_schema(&config_path, schema, opts)? |
| 109 | + } |
97 | 110 | (None, Some(log_path), Some(url)) => { |
98 | 111 | Controller::from_query_log(&log_path, opts, &url)? |
99 | 112 | } |
100 | | - (None, Some(log_path), None) => Controller::from_query_log_with_schema( |
101 | | - &log_path, |
102 | | - asap_planner::PromQLSchema::new(), |
103 | | - opts, |
104 | | - )?, |
| 113 | + (None, Some(_log_path), None) => { |
| 114 | + anyhow::bail!( |
| 115 | + "--prometheus-url is required when using --query-log \ |
| 116 | + (query logs have no metrics hint to fall back on)" |
| 117 | + ) |
| 118 | + } |
105 | 119 | _ => anyhow::bail!( |
106 | 120 | "exactly one of --input_config or --query-log must be provided for PromQL mode" |
107 | 121 | ), |
|
0 commit comments