Skip to content

Commit

Permalink
display events in the CLI, document the use
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Jun 25, 2024
1 parent 0323a7b commit 97c9f30
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 6 additions & 0 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 28 additions & 4 deletions command/src/proto/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
)
}
}
11 changes: 11 additions & 0 deletions doc/configure_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 97c9f30

Please sign in to comment.