Skip to content

Commit

Permalink
enable cluster metrics by default
Browse files Browse the repository at this point in the history
create configurable disable_cluster_metrics
  • Loading branch information
Keksoj committed Oct 23, 2023
1 parent c008daa commit 9648cf0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bin/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ activate_listeners = true
# tagged_metrics = false
# metrics key prefix
# prefix = "sozu"
# by default, sozu register metrics for clusters, unless you want to spare ressources
# disable_cluster_metrics = true

# Listeners
# configuration options specific to a TCP listen socket
Expand Down
27 changes: 25 additions & 2 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ use crate::{
proto::command::{
request::RequestType, ActivateListener, AddBackend, AddCertificate, CertificateAndKey,
Cluster, HttpListenerConfig, HttpsListenerConfig, ListenerType, LoadBalancingAlgorithms,
LoadBalancingParams, LoadMetric, PathRule, ProxyProtocolConfig, Request,
RequestHttpFrontend, RequestTcpFrontend, RulePosition, TcpListenerConfig, TlsVersion,
LoadBalancingParams, LoadMetric, MetricsConfiguration, PathRule, ProxyProtocolConfig,
Request, RequestHttpFrontend, RequestTcpFrontend, RulePosition, TcpListenerConfig,
TlsVersion,
},
request::WorkerRequest,
ObjectKind,
Expand Down Expand Up @@ -155,6 +156,9 @@ pub const DEFAULT_COMMAND_BUFFER_SIZE: usize = 1_000_000;
/// maximum size of the buffer for the channels, in bytes. (2 MB)
pub const DEFAULT_MAX_COMMAND_BUFFER_SIZE: usize = 2_000_000;

/// wether to avoid register cluster metrics in the local drain
pub const DEFAULT_DISABLE_CLUSTER_METRICS: bool = false;

#[derive(Debug)]
pub enum IncompatibilityKind {
PublicAddress,
Expand Down Expand Up @@ -1106,6 +1110,7 @@ pub struct FileConfig {
pub worker_count: Option<u16>,
pub worker_automatic_restart: Option<bool>,
pub metrics: Option<MetricsConfig>,
pub disable_cluster_metrics: Option<bool>,
pub listeners: Option<Vec<ListenerBuilder>>,
pub clusters: Option<HashMap<String, FileClusterConfig>>,
pub handle_process_affinity: Option<bool>,
Expand Down Expand Up @@ -1229,6 +1234,9 @@ impl ConfigBuilder {
.max_connections
.unwrap_or(DEFAULT_MAX_CONNECTIONS),
metrics: file_config.metrics.clone(),
disable_cluster_metrics: file_config
.disable_cluster_metrics
.unwrap_or(DEFAULT_DISABLE_CLUSTER_METRICS),
min_buffers: std::cmp::min(
file_config.min_buffers.unwrap_or(1),
file_config.max_buffers.unwrap_or(1000),
Expand Down Expand Up @@ -1462,6 +1470,8 @@ pub struct Config {
pub worker_count: u16,
pub worker_automatic_restart: bool,
pub metrics: Option<MetricsConfig>,
#[serde(default = "default_disable_cluster_metrics")]
pub disable_cluster_metrics: bool,
pub http_listeners: Vec<HttpListenerConfig>,
pub https_listeners: Vec<HttpsListenerConfig>,
pub tcp_listeners: Vec<TcpListenerConfig>,
Expand Down Expand Up @@ -1508,6 +1518,10 @@ fn default_accept_queue_timeout() -> u32 {
DEFAULT_ACCEPT_QUEUE_TIMEOUT
}

fn default_disable_cluster_metrics() -> bool {
DEFAULT_DISABLE_CLUSTER_METRICS
}

impl Config {
/// Parse a TOML file and build a config out of it
pub fn load_from_path(path: &str) -> Result<Config, ConfigError> {
Expand Down Expand Up @@ -1602,6 +1616,15 @@ impl Config {
}
}

if self.disable_cluster_metrics {
v.push(WorkerRequest {
id: format!("CONFIG-{count}"),
content: RequestType::ConfigureMetrics(MetricsConfiguration::Disabled.into())
.into(),
});
// count += 1; // uncomment if code is added below
}

Ok(v)
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/metrics/local_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub struct LocalDrain {
cluster_metrics: BTreeMap<String, BTreeMap<String, AggregatedMetric>>,
use_tagged_metrics: bool,
origin: String,
enabled: bool,
disable_cluster_metrics: bool,
}

impl LocalDrain {
Expand All @@ -138,14 +138,14 @@ impl LocalDrain {
backend_to_cluster: BTreeMap::new(),
use_tagged_metrics: false,
origin: String::from("x"),
enabled: false,
disable_cluster_metrics: false,
}
}

pub fn configure(&mut self, config: &MetricsConfiguration) {
match config {
MetricsConfiguration::Enabled => self.enabled = true,
MetricsConfiguration::Disabled => self.enabled = false,
MetricsConfiguration::Enabled => self.disable_cluster_metrics = false,
MetricsConfiguration::Disabled => self.disable_cluster_metrics = true,
MetricsConfiguration::Clear => self.clear(),
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ impl LocalDrain {
backend_id: Option<&str>,
metric_value: MetricValue,
) {
if !self.enabled {
if self.disable_cluster_metrics {
return;
}

Expand Down

0 comments on commit 9648cf0

Please sign in to comment.