Skip to content

Commit

Permalink
apply clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 5, 2023
1 parent def32c2 commit 6fa15e5
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 130 deletions.
20 changes: 9 additions & 11 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl CommandServer {
old_worker.channel.set_blocking(false);
*/
let (sockets_return_tx, mut sockets_return_rx) = futures::channel::mpsc::channel(3);
let id = format!("{}-return-sockets", client_id);
let id = format!("{client_id}-return-sockets");
self.in_flight.insert(id.clone(), (sockets_return_tx, 1));
old_worker
.send(
Expand Down Expand Up @@ -678,7 +678,7 @@ impl CommandServer {
old_worker.run_state = RunState::Stopping;

let (softstop_tx, mut softstop_rx) = futures::channel::mpsc::channel(10);
let softstop_id = format!("{}-softstop", client_id);
let softstop_id = format!("{client_id}-softstop");
self.in_flight.insert(softstop_id.clone(), (softstop_tx, 1));
old_worker
.send(
Expand Down Expand Up @@ -754,7 +754,7 @@ impl CommandServer {
let activate_requests = self.state.generate_activate_requests();
for (count, request) in activate_requests.into_iter().enumerate() {
new_worker
.send(format!("{}-ACTIVATE-{}", client_id, count), request)
.send(format!("{client_id}-ACTIVATE-{count}"), request)
.await;
}

Expand Down Expand Up @@ -882,7 +882,7 @@ impl CommandServer {
// create a status list with the available info of the main process
let mut worker_info_map: BTreeMap<String, WorkerInfo> = BTreeMap::new();

let prefix = format!("{}-status-", client_id);
let prefix = format!("{client_id}-status-");

return_processing(
self.command_tx.clone(),
Expand Down Expand Up @@ -988,7 +988,7 @@ impl CommandServer {
self.in_flight.insert(req_id, (metrics_tx.clone(), 1));
}

let prefix = format!("{}-metrics-", client_id);
let prefix = format!("{client_id}-metrics-");

let command_tx = self.command_tx.clone();
let thread_client_id = client_id.clone();
Expand Down Expand Up @@ -1125,11 +1125,9 @@ impl CommandServer {
let mut worker_responses: BTreeMap<String, ResponseContent> = responses
.into_iter()
.filter_map(|(worker_id, proxy_response)| {
if let Some(response_content) = proxy_response.content {
Some((worker_id.to_string(), response_content))
} else {
None
}
proxy_response
.content
.map(|response_content| (worker_id.to_string(), response_content))
})
.collect();

Expand Down Expand Up @@ -1407,7 +1405,7 @@ impl CommandServer {
Some(client_tx) => {
trace!("sending from main process to client loop");
client_tx.send(command_response).await.with_context(|| {
format!("Could not notify client {} about request", client_id)
format!("Could not notify client {client_id} about request")
})?;
}
None => bail!(format!("Could not find client {client_id}")),
Expand Down
7 changes: 3 additions & 4 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl CommandManager {
} else {
println!("Success: {}", response.message);
}
match response.content {
Some(response_content) => match response_content.content_type {
if let Some(response_content) = response.content {
match response_content.content_type {
Some(ContentType::FrontendList(frontends)) => {
print_frontend_list(frontends)
}
Expand All @@ -79,8 +79,7 @@ impl CommandManager {
}
Some(ContentType::ListenersList(list)) => print_listeners(list),
_ => {}
},
None => {}
}
}
break;
}
Expand Down
46 changes: 21 additions & 25 deletions bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,8 @@ fn print_percentiles(filtered_metrics: &BTreeMap<String, FilteredMetrics>) {
let mut percentile_titles: Vec<String> = filtered_metrics
.iter()
.filter_map(|(title, filtered_data)| match filtered_data.inner.clone() {
Some(filtered_metrics) => match filtered_metrics {
filtered_metrics::Inner::Percentiles(_) => Some(title.to_owned()),
_ => None,
},
None => None,
Some(filtered_metrics::Inner::Percentiles(_)) => Some(title.to_owned()),
_ => None,
})
.collect();

Expand All @@ -354,24 +351,23 @@ fn print_percentiles(filtered_metrics: &BTreeMap<String, FilteredMetrics>) {
]));

for title in percentile_titles {
match filtered_metrics.get(&title) {
Some(filtered_metrics) => match filtered_metrics.inner.clone() {
Some(filtered_metrics::Inner::Percentiles(p)) => {
percentile_table.add_row(Row::new(vec![
cell!(title),
cell!(p.samples),
cell!(p.p_50),
cell!(p.p_90),
cell!(p.p_99),
cell!(p.p_99_9),
cell!(p.p_99_99),
cell!(p.p_99_999),
cell!(p.p_100),
]));
}
_ => {}
},
None => println!("Something went VERY wrong here"),
if let Some(FilteredMetrics {
inner: Some(filtered_metrics::Inner::Percentiles(percentiles)),
}) = filtered_metrics.get(&title)
{
percentile_table.add_row(Row::new(vec![
cell!(title),
cell!(percentiles.samples),
cell!(percentiles.p_50),
cell!(percentiles.p_90),
cell!(percentiles.p_99),
cell!(percentiles.p_99_9),
cell!(percentiles.p_99_99),
cell!(percentiles.p_99_999),
cell!(percentiles.p_100),
]));
} else {
println!("Something went VERY wrong here");
}
}

Expand Down Expand Up @@ -655,7 +651,7 @@ pub fn print_certificates(
println!(
"\t\t{}:\t{}",
summary.domain,
hex::encode(summary.fingerprint.to_owned())
hex::encode(&summary.fingerprint)
);
}

Expand Down Expand Up @@ -694,7 +690,7 @@ pub fn print_available_metrics(available_metrics: &AvailableMetrics) -> anyhow::
Ok(())
}

fn list_string_vec(vec: &Vec<String>) -> String {
fn list_string_vec(vec: &[String]) -> String {
let mut output = String::new();
for item in vec.iter() {
output.push_str(item);
Expand Down
3 changes: 2 additions & 1 deletion bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl CommandManager {
cluster_id: id,
sticky_session,
https_redirect,
proxy_protocol: proxy_protocol.and_then(|pp| Some(pp as i32)),
proxy_protocol: proxy_protocol.map(|pp| pp as i32),
load_balancing: load_balancing_policy as i32,
..Default::default()
})),
Expand Down Expand Up @@ -512,6 +512,7 @@ impl CommandManager {
})
}

#[allow(clippy::too_many_arguments)]
pub fn replace_certificate(
&mut self,
address: String,
Expand Down
2 changes: 0 additions & 2 deletions command/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use prost_build;

pub fn main() {
prost_build::Config::new()
.btree_map(["."])
Expand Down
6 changes: 3 additions & 3 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ impl HttpClusterConfig {
proxy_protocol: None,
load_balancing: self.load_balancing as i32,
answer_503: self.answer_503.clone(),
load_metric: self.load_metric.and_then(|s| Some(s as i32)),
load_metric: self.load_metric.map(|s| s as i32),
})),
}];

Expand Down Expand Up @@ -869,9 +869,9 @@ impl TcpClusterConfig {
cluster_id: self.cluster_id.clone(),
sticky_session: false,
https_redirect: false,
proxy_protocol: self.proxy_protocol.and_then(|s| Some(s as i32)),
proxy_protocol: self.proxy_protocol.map(|s| s as i32),
load_balancing: self.load_balancing as i32,
load_metric: self.load_metric.and_then(|s| Some(s as i32)),
load_metric: self.load_metric.map(|s| s as i32),
answer_503: None,
})),
}];
Expand Down
2 changes: 1 addition & 1 deletion command/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ impl From<command::response_content::ContentType> for command::ResponseContent {
content_type: Some(value),
}
}
}
}
8 changes: 4 additions & 4 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ impl Request {

/// True if the request is a SoftStop or a HardStop
pub fn is_a_stop(&self) -> bool {
match self.request_type {
Some(RequestType::SoftStop(_)) | Some(RequestType::HardStop(_)) => true,
_ => false,
}
matches!(
self.request_type,
Some(RequestType::SoftStop(_)) | Some(RequestType::HardStop(_))
)
}
}

Expand Down
44 changes: 22 additions & 22 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,33 @@ pub struct HttpFrontend {
pub tags: Option<BTreeMap<String, String>>,
}

impl Into<RequestHttpFrontend> for HttpFrontend {
fn into(self) -> RequestHttpFrontend {
let tags = match self.tags {
impl From<HttpFrontend> for RequestHttpFrontend {
fn from(val: HttpFrontend) -> Self {
let tags = match val.tags {
Some(tags) => tags,
None => BTreeMap::new(),
};
RequestHttpFrontend {
cluster_id: self.cluster_id,
address: self.address.to_string(),
hostname: self.hostname,
path: self.path,
method: self.method,
position: self.position.into(),
cluster_id: val.cluster_id,
address: val.address.to_string(),
hostname: val.hostname,
path: val.path,
method: val.method,
position: val.position.into(),
tags,
}
}
}

impl Into<AddBackend> for Backend {
fn into(self) -> AddBackend {
impl From<Backend> for AddBackend {
fn from(val: Backend) -> Self {
AddBackend {
cluster_id: self.cluster_id,
backend_id: self.backend_id,
address: self.address.to_string(),
sticky_id: self.sticky_id,
load_balancing_parameters: self.load_balancing_parameters,
backup: self.backup,
cluster_id: val.cluster_id,
backend_id: val.backend_id,
address: val.address.to_string(),
sticky_id: val.sticky_id,
load_balancing_parameters: val.load_balancing_parameters,
backup: val.backup,
}
}
}
Expand Down Expand Up @@ -150,12 +150,12 @@ pub struct TcpFrontend {
pub tags: BTreeMap<String, String>,
}

impl Into<RequestTcpFrontend> for TcpFrontend {
fn into(self) -> RequestTcpFrontend {
impl From<TcpFrontend> for RequestTcpFrontend {
fn from(val: TcpFrontend) -> Self {
RequestTcpFrontend {
cluster_id: self.cluster_id,
address: self.address.to_string(),
tags: self.tags.clone(),
cluster_id: val.cluster_id,
address: val.address.to_string(),
tags: val.tags,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl ConfigState {
bail!("This tcp frontend is already present: {:?}", tcp_frontend);
}

tcp_frontends.push(tcp_frontend.clone());
tcp_frontends.push(tcp_frontend);
Ok(())
}

Expand Down Expand Up @@ -1157,15 +1157,15 @@ impl ConfigState {
let mut tcp_frontends = Vec::new();
let mut backends = Vec::new();

for (_k, http_frontend) in &self.http_fronts {
for http_frontend in self.http_fronts.values() {
if let Some(id) = &http_frontend.cluster_id {
if id == cluster_id {
http_frontends.push(http_frontend.clone().into());
}
}
}

for (_k, https_frontend) in &self.https_fronts {
for https_frontend in self.https_fronts.values() {
if let Some(id) = &https_frontend.cluster_id {
if id == cluster_id {
https_frontends.push(https_frontend.clone().into());
Expand Down
6 changes: 3 additions & 3 deletions e2e/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,13 @@ pub fn try_blue_geen() -> State {
"PRIMARY",
primary_address,
aggrerator.clone(),
AsyncBackend::http_handler(format!("pong_primary")),
AsyncBackend::http_handler("pong_primary".to_string()),
);
let mut secondary = AsyncBackend::spawn_detached_backend(
"SECONDARY",
secondary_address,
aggrerator.clone(),
AsyncBackend::http_handler(format!("pong_secondary")),
aggrerator,
AsyncBackend::http_handler("pong_secondary".to_string()),
);

worker.send_proxy_request(Request {
Expand Down
1 change: 1 addition & 0 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct HttpSession {
}

impl HttpSession {
#[allow(clippy::too_many_arguments)]
pub fn new(
answers: Rc<RefCell<HttpAnswers>>,
configured_backend_timeout: Duration,
Expand Down
13 changes: 6 additions & 7 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub struct HttpsSession {
}

impl HttpsSession {
#[allow(clippy::too_many_arguments)]
pub fn new(
answers: Rc<RefCell<HttpAnswers>>,
configured_backend_timeout: Duration,
Expand Down Expand Up @@ -985,14 +986,12 @@ impl HttpsProxy {
let resolver = unwrap_msg!(owned.resolver.0.lock());
let mut certificate_summaries = vec![];

resolver
.domain_lookup(domain.as_bytes(), true)
.map(|(k, fingerprint)| {
certificate_summaries.push(CertificateSummary {
domain: String::from_utf8(k.to_vec()).unwrap(),
fingerprint: fingerprint.to_string(),
});
if let Some((k, fingerprint)) = resolver.domain_lookup(domain.as_bytes(), true) {
certificate_summaries.push(CertificateSummary {
domain: String::from_utf8(k.to_vec()).unwrap(),
fingerprint: fingerprint.to_string(),
});
}
CertificatesByAddress {
address: owned.address.to_string(),
certificate_summaries,
Expand Down
3 changes: 1 addition & 2 deletions lib/src/metrics/local_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ impl LocalDrain {
.context(format!("No metrics found for backend with id {backend_id}"))?
.to_owned();

let mut backends = Vec::new();
backends.push(self.metrics_of_one_backend(backend_id, metric_names)?);
let backends = vec![self.metrics_of_one_backend(backend_id, metric_names)?];

clusters.insert(
cluster_id,
Expand Down

0 comments on commit 6fa15e5

Please sign in to comment.