Skip to content

Commit

Permalink
remove ProxyResponseContent, put its variant in ResponseContent
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Mar 22, 2023
1 parent e0643f4 commit 0e62f8d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 48 deletions.
6 changes: 2 additions & 4 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use serde::{Deserialize, Serialize};
use sozu_command_lib::{
config::Config,
request::{MetricsConfiguration, Request, WorkerRequest},
response::{
ProxyResponseContent, Response, ResponseContent, ResponseStatus, RunState, WorkerResponse,
},
response::{Response, ResponseContent, ResponseStatus, RunState, WorkerResponse},
scm_socket::{Listeners, ScmSocket},
state::ConfigState,
};
Expand Down Expand Up @@ -709,7 +707,7 @@ impl CommandServer {
response: WorkerResponse,
) -> anyhow::Result<Success> {
// Notify the client with Processing in case of a proxy event
if let Some(ProxyResponseContent::Event(event)) = response.content {
if let Some(ResponseContent::Event(event)) = response.content {
for client_id in self.event_subscribers.iter() {
if let Some(client_tx) = self.clients.get_mut(client_id) {
let event = Response::new(
Expand Down
6 changes: 3 additions & 3 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use sozu_command_lib::{
parser::parse_several_commands,
request::{FrontendFilters, MetricsConfiguration, QueryClusterType, Request, WorkerRequest},
response::{
AggregatedMetricsData, ListedFrontends, ListenersList, ProxyResponseContent, QueryAnswer,
Response, ResponseContent, ResponseStatus, RunState, WorkerInfo,
AggregatedMetricsData, ListedFrontends, ListenersList, QueryAnswer, Response,
ResponseContent, ResponseStatus, RunState, WorkerInfo,
},
scm_socket::Listeners,
state::get_cluster_ids_by_domain,
Expand Down Expand Up @@ -1106,7 +1106,7 @@ impl CommandServer {
let mut query_answers: BTreeMap<String, QueryAnswer> = responses
.into_iter()
.filter_map(|(worker_id, proxy_response)| {
if let Some(ProxyResponseContent::Query(d)) = proxy_response.content {
if let Some(ResponseContent::Query(d)) = proxy_response.content {
Some((worker_id.to_string(), d))
} else {
None
Expand Down
6 changes: 5 additions & 1 deletion bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl CommandManager {
ResponseContent::Workers(_)
| ResponseContent::Metrics(_)
| ResponseContent::WorkerResponses(_)
| ResponseContent::WorkerMetrics(_)
| ResponseContent::Query(_)
| ResponseContent::Event(_) => {}
ResponseContent::State(state) => match json {
true => print_json_response(&state)?,
Expand Down Expand Up @@ -416,7 +418,9 @@ impl CommandManager {
}
ResponseStatus::Ok => {
match response.content {
Some(ResponseContent::WorkerResponses(data)) => print_certificates(data, json)?,
Some(ResponseContent::WorkerResponses(data)) => {
print_certificates(data, json)?
}
_ => bail!("unexpected response: {:?}", response.content),
}
break;
Expand Down
13 changes: 8 additions & 5 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ pub enum ResponseContent {
/// all listeners
ListenersList(ListenersList),



/// contains proxy & cluster metrics
WorkerMetrics(WorkerMetrics),
Query(QueryAnswer),
}

/// details of an query answer, sent by a worker
Expand Down Expand Up @@ -431,7 +432,7 @@ pub struct WorkerResponse {
pub id: MessageId,
pub status: ResponseStatus,
pub message: String,
pub content: Option<ProxyResponseContent>,
pub content: Option<ResponseContent>,
}

impl WorkerResponse {
Expand All @@ -447,7 +448,7 @@ impl WorkerResponse {
}
}

pub fn ok_with_content<T>(id: T, content: ProxyResponseContent) -> Self
pub fn ok_with_content<T>(id: T, content: ResponseContent) -> Self
where
T: ToString,
{
Expand Down Expand Up @@ -503,14 +504,16 @@ impl fmt::Display for WorkerResponse {
}
}

/*
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ProxyResponseContent {
pub enum ResponseContent {
/// contains proxy & cluster metrics
Metrics(WorkerMetrics),
Query(QueryAnswer),
Event(Event),
}
*/

/// Aggregated metrics of main process & workers, for the CLI
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
47 changes: 19 additions & 28 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ use crate::{
ReplaceCertificate, Request, WorkerRequest,
},
response::{
HttpFrontend, HttpsListenerConfig, ProxyResponseContent, QueryAnswer,
QueryAnswerCertificate, Route, WorkerResponse,
HttpFrontend, HttpsListenerConfig, QueryAnswer, QueryAnswerCertificate,
ResponseContent, Route, WorkerResponse,
},
scm_socket::ScmSocket,
state::ClusterId,
Expand Down Expand Up @@ -874,7 +874,7 @@ impl HttpsProxy {
pub fn remove_listener(
&mut self,
remove: RemoveListener,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let len = self.listeners.len();

self.listeners
Expand Down Expand Up @@ -929,18 +929,15 @@ impl HttpsProxy {
Ok(())
}

pub fn logging(
&mut self,
logging_filter: String,
) -> anyhow::Result<Option<ProxyResponseContent>> {
pub fn logging(&mut self, logging_filter: String) -> anyhow::Result<Option<ResponseContent>> {
logging::LOGGER.with(|l| {
let directives = logging::parse_logging_spec(&logging_filter);
l.borrow_mut().set_directives(directives);
});
Ok(None)
}

pub fn query_all_certificates(&mut self) -> anyhow::Result<Option<ProxyResponseContent>> {
pub fn query_all_certificates(&mut self) -> anyhow::Result<Option<ResponseContent>> {
let certificates = self
.listeners
.values()
Expand All @@ -963,15 +960,15 @@ impl HttpsProxy {
certificates
);

Ok(Some(ProxyResponseContent::Query(
QueryAnswer::Certificates(QueryAnswerCertificate::All(certificates)),
)))
Ok(Some(ResponseContent::Query(QueryAnswer::Certificates(
QueryAnswerCertificate::All(certificates),
))))
}

pub fn query_certificate_for_domain(
&mut self,
domain: String,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let certificates = self
.listeners
.values()
Expand All @@ -992,9 +989,9 @@ impl HttpsProxy {
domain, certificates
);

Ok(Some(ProxyResponseContent::Query(
QueryAnswer::Certificates(QueryAnswerCertificate::Domain(certificates)),
)))
Ok(Some(ResponseContent::Query(QueryAnswer::Certificates(
QueryAnswerCertificate::Domain(certificates),
))))
}

pub fn activate_listener(
Expand Down Expand Up @@ -1046,10 +1043,7 @@ impl HttpsProxy {
})
}

pub fn add_cluster(
&mut self,
mut cluster: Cluster,
) -> anyhow::Result<Option<ProxyResponseContent>> {
pub fn add_cluster(&mut self, mut cluster: Cluster) -> anyhow::Result<Option<ResponseContent>> {
if let Some(answer_503) = cluster.answer_503.take() {
for listener in self.listeners.values() {
listener
Expand All @@ -1063,10 +1057,7 @@ impl HttpsProxy {
Ok(None)
}

pub fn remove_cluster(
&mut self,
cluster_id: &str,
) -> anyhow::Result<Option<ProxyResponseContent>> {
pub fn remove_cluster(&mut self, cluster_id: &str) -> anyhow::Result<Option<ResponseContent>> {
self.clusters.remove(cluster_id);
for listener in self.listeners.values() {
listener
Expand All @@ -1082,7 +1073,7 @@ impl HttpsProxy {
pub fn add_https_frontend(
&mut self,
front: RequestHttpFrontend,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let front = front.to_frontend()?;

match self
Expand All @@ -1105,7 +1096,7 @@ impl HttpsProxy {
pub fn remove_https_frontend(
&mut self,
front: RequestHttpFrontend,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let front = front.to_frontend()?;

if let Some(listener) = self
Expand All @@ -1125,7 +1116,7 @@ impl HttpsProxy {
pub fn add_certificate(
&mut self,
add_certificate: AddCertificate,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let address = add_certificate.address.parse()?;
match self
.listeners
Expand All @@ -1149,7 +1140,7 @@ impl HttpsProxy {
pub fn remove_certificate(
&mut self,
remove_certificate: RemoveCertificate,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let address = remove_certificate.address.parse()?;
match self
.listeners
Expand All @@ -1173,7 +1164,7 @@ impl HttpsProxy {
pub fn replace_certificate(
&mut self,
replace_certificate: ReplaceCertificate,
) -> anyhow::Result<Option<ProxyResponseContent>> {
) -> anyhow::Result<Option<ResponseContent>> {
let address = replace_certificate.address.parse()?;
match self
.listeners
Expand Down
14 changes: 7 additions & 7 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use sozu_command::{
QueryCertificateType, QueryClusterType, RemoveBackend, Request, WorkerRequest,
},
response::{
Event, HttpListenerConfig, HttpsListenerConfig, MessageId, ProxyResponseContent,
QueryAnswer, QueryAnswerCertificate, ResponseStatus,
Event, HttpListenerConfig, HttpsListenerConfig, MessageId, QueryAnswer,
QueryAnswerCertificate, ResponseContent, ResponseStatus,
TcpListenerConfig as CommandTcpListener, WorkerResponse,
},
scm_socket::{Listeners, ScmSocket},
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn push_event(event: Event) {
id: "EVENT".to_string(),
message: String::new(),
status: ResponseStatus::Processing,
content: Some(ProxyResponseContent::Event(event)),
content: Some(ResponseContent::Event(event)),
});
});
}
Expand Down Expand Up @@ -882,7 +882,7 @@ impl Server {
Request::QueryClustersHashes => {
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ProxyResponseContent::Query(QueryAnswer::ClustersHashes(
ResponseContent::Query(QueryAnswer::ClustersHashes(
self.config_state.hash_state(),
)),
));
Expand All @@ -909,7 +909,7 @@ impl Server {
};
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ProxyResponseContent::Query(query_answer),
ResponseContent::Query(query_answer),
));
return;
}
Expand All @@ -922,7 +922,7 @@ impl Server {
QueryCertificateType::Fingerprint(f) => {
push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ProxyResponseContent::Query(QueryAnswer::Certificates(
ResponseContent::Query(QueryAnswer::Certificates(
QueryAnswerCertificate::Fingerprint(get_certificate(
&self.config_state,
f,
Expand All @@ -939,7 +939,7 @@ impl Server {

push_queue(WorkerResponse::ok_with_content(
message.id.clone(),
ProxyResponseContent::Query(QueryAnswer::Metrics(data)),
ResponseContent::Query(QueryAnswer::Metrics(data)),
));
});
return;
Expand Down

0 comments on commit 0e62f8d

Please sign in to comment.