Skip to content

Commit

Permalink
create type ClusterInformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 28, 2023
1 parent 30e602d commit f005d9a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
19 changes: 10 additions & 9 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use sozu_command_lib::{
logging,
parser::parse_several_commands,
proto::command::{
request::RequestType, AggregatedMetrics, AvailableMetrics, ClusterHashes, FrontendFilters,
ListenersList, MetricsConfiguration, Request, ResponseStatus, ReturnListenSockets,
RunState, SoftStop, Status, WorkerInfo, WorkerInfos,
request::RequestType, AggregatedMetrics, AvailableMetrics, ClusterHashes,
ClusterInformations, FrontendFilters, ListenersList, MetricsConfiguration, Request,
ResponseStatus, ReturnListenSockets, RunState, SoftStop, Status, WorkerInfo, WorkerInfos,
},
request::WorkerRequest,
response::{ListedFrontends, Response, ResponseContent},
Expand Down Expand Up @@ -1082,24 +1082,25 @@ impl CommandServer {
Some(RequestType::QueryClustersHashes(_)) => {
main_response_content = Some(ResponseContent::ClustersHashes(ClusterHashes {
map: self.state.hash_state(),
}));
}))
}
Some(RequestType::QueryClusterById(cluster_id)) => {
main_response_content = Some(ResponseContent::Clusters(vec![self
.state
.cluster_state(cluster_id)]))
main_response_content = Some(ResponseContent::Clusters(ClusterInformations {
vec: vec![self.state.cluster_state(cluster_id)],
}))
}
Some(RequestType::QueryClustersByDomain(domain)) => {
let cluster_ids = get_cluster_ids_by_domain(
&self.state,
domain.hostname.clone(),
domain.path.clone(),
);
let clusters = cluster_ids
let vec = cluster_ids
.iter()
.map(|cluster_id| self.state.cluster_state(cluster_id))
.collect();
main_response_content = Some(ResponseContent::Clusters(clusters));
main_response_content =
Some(ResponseContent::Clusters(ClusterInformations { vec }));
}
_ => {}
};
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 @@ -440,7 +440,7 @@ pub fn print_query_response_data(
for (key, metrics) in data.iter() {
//let m: u8 = metrics;
if let ResponseContent::Clusters(clusters) = metrics {
for cluster in clusters.iter() {
for cluster in clusters.vec.iter() {
let entry = cluster_data.entry(cluster).or_insert(Vec::new());
entry.push(key.to_owned());

Expand Down
4 changes: 4 additions & 0 deletions command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ enum MetricsConfiguration {
CLEAR = 2;
}

message ClusterInformations {
repeated ClusterInformation vec = 1;
}

// Information about a given cluster
// Contains types usually used in requests, because they are readily available in protobuf
message ClusterInformation {
Expand Down
8 changes: 4 additions & 4 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::{
use crate::{
proto::command::{
AddBackend, AggregatedMetrics, AvailableMetrics, CertificateSummary, ClusterHashes,
ClusterInformation, Event, FilteredTimeSerie, ListenersList, LoadBalancingParams, PathRule,
PathRuleKind, RequestHttpFrontend, RequestTcpFrontend, ResponseStatus, RulePosition,
RunState, WorkerInfos, WorkerMetrics,
ClusterInformations, Event, FilteredTimeSerie, ListenersList, LoadBalancingParams,
PathRule, PathRuleKind, RequestHttpFrontend, RequestTcpFrontend, ResponseStatus,
RulePosition, RunState, WorkerInfos, WorkerMetrics,
},
request::PROTOCOL_VERSION,
state::ClusterId,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub enum ResponseContent {
/// Lists of metrics that are available
AvailableMetrics(AvailableMetrics),

Clusters(Vec<ClusterInformation>),
Clusters(ClusterInformations),
/// cluster id -> hash of cluster information
ClustersHashes(ClusterHashes),

Expand Down
14 changes: 8 additions & 6 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use sozu_command::{
config::Config,
proto::command::{
request::RequestType, ActivateListener, AddBackend, Cluster, ClusterHashes,
DeactivateListener, Event, HttpListenerConfig, HttpsListenerConfig, ListenerType,
LoadBalancingAlgorithms, LoadMetric, MetricsConfiguration, RemoveBackend, ResponseStatus,
TcpListenerConfig as CommandTcpListener,
ClusterInformations, DeactivateListener, Event, HttpListenerConfig, HttpsListenerConfig,
ListenerType, LoadBalancingAlgorithms, LoadMetric, MetricsConfiguration, RemoveBackend,
ResponseStatus, TcpListenerConfig as CommandTcpListener,
},
ready::Ready,
request::WorkerRequest,
Expand Down Expand Up @@ -891,7 +891,9 @@ impl Server {
Some(RequestType::QueryClusterById(cluster_id)) => {
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ResponseContent::Clusters(vec![self.config_state.cluster_state(cluster_id)]),
ResponseContent::Clusters(ClusterInformations {
vec: vec![self.config_state.cluster_state(cluster_id)],
}),
));
}
Some(RequestType::QueryClustersByDomain(domain)) => {
Expand All @@ -900,14 +902,14 @@ impl Server {
domain.hostname.clone(),
domain.path.clone(),
);
let answer = cluster_ids
let vec = cluster_ids
.iter()
.map(|cluster_id| self.config_state.cluster_state(cluster_id))
.collect();

push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ResponseContent::Clusters(answer),
ResponseContent::Clusters(ClusterInformations { vec }),
));
return;
}
Expand Down

0 comments on commit f005d9a

Please sign in to comment.