diff --git a/bin/src/cli.rs b/bin/src/cli.rs index 6e06784e6..c6e429a29 100644 --- a/bin/src/cli.rs +++ b/bin/src/cli.rs @@ -180,7 +180,7 @@ pub enum SubCmd { #[clap(subcommand)] cmd: ConfigCmd, }, - #[clap(name = "events", about = "receive sozu events")] + #[clap(name = "events", about = "receive sozu events about the status of backends")] Events, } diff --git a/bin/src/ctl/command.rs b/bin/src/ctl/command.rs index 59e0b07a0..c47f4b20d 100644 --- a/bin/src/ctl/command.rs +++ b/bin/src/ctl/command.rs @@ -46,6 +46,12 @@ impl CommandManager { if !self.json { debug!("Processing: {}", response.message); } + if let Some(ResponseContent { + content_type: Some(ContentType::Event(event)), + }) = response.content + { + info!("{}, {}", response.message, event); + } } ResponseStatus::Failure => return Err(CtlError::Failure(response.message)), ResponseStatus::Ok => return Ok(response), diff --git a/command/src/command.proto b/command/src/command.proto index 2487e5ef4..caa9a1fe2 100644 --- a/command/src/command.proto +++ b/command/src/command.proto @@ -522,6 +522,7 @@ message ClusterInformation { repeated AddBackend backends = 5; } +// an event produced by a worker to notify about backends status message Event { required EventKind kind = 1; optional string cluster_id = 2; diff --git a/command/src/proto/display.rs b/command/src/proto/display.rs index 4d91d7777..3302f7512 100644 --- a/command/src/proto/display.rs +++ b/command/src/proto/display.rs @@ -14,10 +14,11 @@ use crate::{ filtered_metrics, protobuf_endpoint, request::RequestType, response_content::ContentType, AggregatedMetrics, AvailableMetrics, CertificateAndKey, CertificateSummary, CertificatesWithFingerprints, ClusterMetrics, CustomHttpAnswers, - FilteredMetrics, HttpEndpoint, HttpListenerConfig, HttpsListenerConfig, - ListOfCertificatesByAddress, ListedFrontends, ListenersList, ProtobufEndpoint, - QueryCertificatesFilters, RequestCounts, Response, ResponseContent, ResponseStatus, - RunState, SocketAddress, TlsVersion, WorkerInfos, WorkerMetrics, WorkerResponses, + Event, EventKind, FilteredMetrics, HttpEndpoint, HttpListenerConfig, + HttpsListenerConfig, ListOfCertificatesByAddress, ListedFrontends, ListenersList, + ProtobufEndpoint, QueryCertificatesFilters, RequestCounts, Response, ResponseContent, + ResponseStatus, RunState, SocketAddress, TlsVersion, WorkerInfos, WorkerMetrics, + WorkerResponses, }, DisplayError, }, @@ -1006,3 +1007,26 @@ impl CustomHttpAnswers { rows } } + +impl Display for Event { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + let kind = match self.kind() { + EventKind::BackendDown => "backend down", + EventKind::BackendUp => "backend up", + EventKind::NoAvailableBackends => "no available backends", + EventKind::RemovedBackendHasNoConnections => "removed backend has no connections", + }; + let address = match &self.address { + Some(a) => a.to_string(), + None => String::new(), + }; + write!( + f, + "{}, backend={}, cluster={}, address={}", + kind, + self.backend_id(), + self.cluster_id(), + address, + ) + } +} diff --git a/doc/configure_cli.md b/doc/configure_cli.md index e30248fbe..fc368ca75 100644 --- a/doc/configure_cli.md +++ b/doc/configure_cli.md @@ -94,3 +94,14 @@ sozu --config /etc/sozu/config.toml state load --file state.json ``` You should be able to request your cluster like before the shutdown. + +### Monitor status of backends with events + +This CLI command: + +```bash +sozu --config /path/to/config.toml events +``` + +listens to events sent by Sōzu workers whenever a backend is down, up again, +or when no backend is available.