Skip to content

Commit

Permalink
store cluster metrics in a simpler way, query them all
Browse files Browse the repository at this point in the history
This commit removes what @Geal started to work on but didn't finish.
The cluster metrics are now stored without timestamps, which reduces
the strain on the memory and thus is cleared only everyday at midgnight.
They are stored in a simple binary tree map of the form
cluster_or_backend_id -> (key, value)

This commit removes the option to enable the timed collection of metrics.
Left to do: queries for cluster and backend metrics, providing their
ids and metric names.
  • Loading branch information
Keksoj committed Aug 19, 2022
1 parent 81c94ca commit 67445c4
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 1,000 deletions.
10 changes: 2 additions & 8 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,9 @@ pub enum SubCmd {
#[derive(Subcommand, PartialEq, Clone, Debug)]
pub enum MetricsCmd {
#[clap(name = "enable", about = "Enables local metrics collection")]
Enable {
#[clap(long, help = "Enables time metrics collection")]
time: bool,
},
Enable,
#[clap(name = "disable", about = "Disables local metrics collection")]
Disable {
#[clap(long, help = "Disables time metrics collection")]
time: bool,
},
Disable,
#[clap(name = "clear", about = "Deletes local metrics data")]
Clear,
}
Expand Down
16 changes: 2 additions & 14 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,20 +538,8 @@ impl CommandManager {
//println!("will send message for metrics with id {}", id);

let configuration = match cmd {
MetricsCmd::Enable { time } => {
if time {
MetricsConfiguration::EnabledTimeMetrics(true)
} else {
MetricsConfiguration::Enabled(true)
}
}
MetricsCmd::Disable { time } => {
if time {
MetricsConfiguration::EnabledTimeMetrics(false)
} else {
MetricsConfiguration::Enabled(false)
}
}
MetricsCmd::Enable => MetricsConfiguration::Enabled(true),
MetricsCmd::Disable => MetricsConfiguration::Enabled(false),
MetricsCmd::Clear => MetricsConfiguration::Clear,
};

Expand Down
2 changes: 1 addition & 1 deletion bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn filter_worker_metrics(
}
for (cluster_id, cluster_metric_data) in cluster_metrics.iter() {
// cluster metrics
for (metric_key, filtered_value) in cluster_metric_data.data.iter() {
for (metric_key, filtered_value) in cluster_metric_data.cluster.iter() {
filtered_metrics.insert(
format!("{} {}", cluster_id, metric_key.replace("\t", ".")),
filtered_value.clone(),
Expand Down
2 changes: 1 addition & 1 deletion command/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ mod tests {
clusters: [(
String::from("cluster_1"),
ClusterMetricsData {
data: [(
cluster: [(
String::from("request_time"),
FilteredData::Percentiles(Percentiles {
samples: 42,
Expand Down
9 changes: 4 additions & 5 deletions command/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ pub struct WorkerMetrics {
/// the metrics of a given cluster, with several backends
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ClusterMetricsData {
/// TO_CHECK: key -> metric
pub data: BTreeMap<String, FilteredData>,
/// TO_CHECK: backend_id -> (key -> metric)
/// metric name -> metric value
pub cluster: BTreeMap<String, FilteredData>,
/// backend_id -> (metric name-> metric value)
pub backends: BTreeMap<String, BTreeMap<String, FilteredData>>,
}

impl ClusterMetricsData {
pub fn new() -> Self {
ClusterMetricsData {
data: BTreeMap::new(),
cluster: BTreeMap::new(),
backends: BTreeMap::new(),
}
}
Expand Down Expand Up @@ -782,7 +782,6 @@ pub struct TcpListener {
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MetricsConfiguration {
Enabled(bool),
EnabledTimeMetrics(bool),
Clear,
}

Expand Down

0 comments on commit 67445c4

Please sign in to comment.