Skip to content

Commit

Permalink
add no-clusters option on metrics query
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Jan 24, 2024
1 parent 9d5788c commit 022e5ef
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ pub enum MetricsCmd {
// parse(try_from_str = split_slash)
)]
backends: Vec<String>,
#[clap(
short,
long,
help = "get only the metrics of main process and workers only (no cluster metrics)"
)]
no_clusters: bool,
},
}

Expand Down
2 changes: 2 additions & 0 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ impl CommandManager {
metric_names: Vec<String>,
cluster_ids: Vec<String>,
backend_ids: Vec<String>,
no_clusters: bool,
) -> Result<(), anyhow::Error> {
let request: Request = RequestType::QueryMetrics(QueryMetricsOptions {
list,
cluster_ids,
backend_ids,
metric_names,
no_clusters,
})
.into();

Expand Down
3 changes: 2 additions & 1 deletion bin/src/ctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl CommandManager {
names,
clusters,
backends,
} => self.get_metrics(list, refresh, names, clusters, backends),
no_clusters,
} => self.get_metrics(list, refresh, names, clusters, backends, no_clusters),
_ => self.configure_metrics(cmd),
},
SubCmd::Logging { level } => self.logging_filter(&level),
Expand Down
2 changes: 2 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ message QueryMetricsOptions {
repeated string backend_ids = 3;
// query only these metrics
repeated string metric_names = 4;
// query only worker and main process metrics (no cluster metrics)
required bool no_clusters = 5;
}

// options to configure metrics collection
Expand Down
9 changes: 9 additions & 0 deletions lib/src/metrics/local_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,21 @@ impl LocalDrain {
cluster_ids,
backend_ids,
list,
no_clusters,
} = options;

if *list {
return self.list_all_metric_names();
}

if *no_clusters {
let proxy_metrics = self.dump_proxy_metrics(metric_names);
return Ok(ContentType::WorkerMetrics(WorkerMetrics {
proxy: proxy_metrics,
clusters: BTreeMap::new(),
}).into());
}

let worker_metrics = match (cluster_ids.is_empty(), backend_ids.is_empty()) {
(false, _) => self.query_clusters(cluster_ids, metric_names)?,
(true, false) => self.query_backends(backend_ids, metric_names)?,
Expand Down

0 comments on commit 022e5ef

Please sign in to comment.