Skip to content

Commit

Permalink
write LoadMetric in protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 5, 2023
1 parent 6716f8a commit 4e1e7d0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
10 changes: 10 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ enum ProxyProtocolConfig {
EXPECT_HEADER = 0;
SEND_HEADER = 1;
RELAY_HEADER = 2;
}

// how sozu measures which backend is less loaded
enum LoadMetric {
// number of TCP connections
CONNECTIONS = 0;
// number of active HTTP requests
REQUESTS = 1;
// time to connect to the backend, weighted by the number of active connections (peak EWMA)
CONNECTION_TIME = 2;
}
8 changes: 4 additions & 4 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use toml;
use crate::{
certificate::split_certificate_chain,
proto::command::{
AddCertificate, CertificateAndKey, LoadBalancingAlgorithms, PathRule, ProxyProtocolConfig,
RequestHttpFrontend, RulePosition, TlsVersion,
AddCertificate, CertificateAndKey, LoadBalancingAlgorithms, LoadMetric, PathRule,
ProxyProtocolConfig, RequestHttpFrontend, RulePosition, TlsVersion,
},
request::{
ActivateListener, AddBackend, Cluster, ListenerType, LoadBalancingParams, LoadMetric,
Request, RequestTcpFrontend, WorkerRequest,
ActivateListener, AddBackend, Cluster, ListenerType, LoadBalancingParams, Request,
RequestTcpFrontend, WorkerRequest,
},
response::{HttpListenerConfig, HttpsListenerConfig, TcpListenerConfig},
};
Expand Down
22 changes: 1 addition & 21 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::Context;
use crate::{
certificate::Fingerprint,
proto::command::{
AddCertificate, FrontendFilters, LoadBalancingAlgorithms, PathRuleKind,
AddCertificate, FrontendFilters, LoadBalancingAlgorithms, LoadMetric, PathRuleKind,
ProxyProtocolConfig, RemoveCertificate, ReplaceCertificate, RequestHttpFrontend,
RulePosition,
},
Expand Down Expand Up @@ -232,18 +232,6 @@ pub struct Cluster {
pub load_metric: Option<LoadMetric>,
}

/// how sozu measures which backend is less loaded
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LoadMetric {
/// number of TCP connections
Connections,
/// number of active HTTP requests
Requests,
/// time to connect to the backend, weighted by the number of active connections (peak EWMA)
ConnectionTime,
}

pub fn default_sticky_name() -> String {
String::from("SOZUBALANCEID")
}
Expand Down Expand Up @@ -366,14 +354,6 @@ pub struct QueryMetricsOptions {
pub metric_names: Vec<String>,
}

/*
impl Default for LoadBalancingAlgorithms {
fn default() -> Self {
LoadBalancingAlgorithms::RoundRobin
}
}
*/

#[derive(Debug)]
pub struct ParseErrorLoadBalancing;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use anyhow::{bail, Context};
use mio::net::TcpStream;

use sozu_command::{
proto::command::LoadBalancingAlgorithms, request::LoadMetric, response::Event, state::ClusterId,
proto::command::{LoadBalancingAlgorithms, LoadMetric},
response::Event,
state::ClusterId,
};

use crate::server::push_event;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/load_balancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::{
thread_rng, Rng,
};

use crate::{sozu_command::request::LoadMetric, Backend};
use crate::{sozu_command::proto::command::LoadMetric, Backend};

pub trait LoadBalancingAlgorithm: Debug {
fn next_available_backend(
Expand Down Expand Up @@ -177,7 +177,7 @@ impl LoadBalancingAlgorithm for PowerOfTwo {
mod test {
use super::*;
use crate::retry::{ExponentialBackoffPolicy, RetryPolicyWrapper};
use crate::sozu_command::request::LoadMetric;
use crate::sozu_command::proto::command::LoadMetric;
use crate::{BackendStatus, PeakEWMA};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

Expand Down

0 comments on commit 4e1e7d0

Please sign in to comment.