Skip to content

Commit

Permalink
Merge pull request #194 from vinted/feature/fix-lint-errors
Browse files Browse the repository at this point in the history
Fix lint issues and enable errors in CI
  • Loading branch information
ernestas-vinted authored Oct 30, 2023
2 parents b57f99e + 10a41c3 commit 7b50bc5
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
override: true
- name: Run cargo check
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
continue-on-error: false
with:
command: check
test:
Expand All @@ -38,7 +38,7 @@ jobs:
override: true
- name: Run cargo test
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
continue-on-error: false
with:
command: test
lints:
Expand All @@ -56,13 +56,13 @@ jobs:
components: rustfmt, clippy
- name: Run cargo fmt
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
continue-on-error: false
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
continue-on-error: false
with:
command: clippy
args: -- -D warnings
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
1 change: 1 addition & 0 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async fn wait_for_signal(tx: Sender<()>) {
pub fn signal_channel() -> Receiver<()> {
let (signal_tx, signal_rx) = unit_channel();

#[allow(clippy::let_underscore_future)]
let _ = tokio::spawn(wait_for_signal(signal_tx));

signal_rx
Expand Down
1 change: 1 addition & 0 deletions src/bin/elasticsearch_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

match Exporter::new(options).await {
Ok(exporter) => {
#[allow(clippy::let_underscore_future)]
let _ = tokio::spawn(exporter.spawn());
}
Err(e) => {
Expand Down
8 changes: 4 additions & 4 deletions src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Collection {
};

if let Some(fgauge) = self.fgauges.get(key) {
let _ = set_labels(fgauge, &mut self.fgauges_lifetime)?;
set_labels(fgauge, &mut self.fgauges_lifetime)?;
} else {
// If metric is skippable and haven't been registered skip it
// until value is not zero
Expand All @@ -108,7 +108,7 @@ impl Collection {
&labels.keys().map(|s| s.as_str()).collect::<Vec<&str>>(),
)?;

let _ = set_labels(&new_fgauge, &mut self.fgauges_lifetime)?;
set_labels(&new_fgauge, &mut self.fgauges_lifetime)?;

// Register new metric
default_registry().register(Box::new(new_fgauge.clone()))?;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Collection {
};

if let Some(gauge) = self.gauges.get(key) {
let _ = set_labels(gauge, &mut self.gauges_lifetime)?;
set_labels(gauge, &mut self.gauges_lifetime)?;
} else {
// If metric is skippable and haven't been registered skip it
// until value is not zero
Expand All @@ -175,7 +175,7 @@ impl Collection {
&labels.keys().map(|s| s.as_str()).collect::<Vec<&str>>(),
)?;

let _ = set_labels(&new_gauge, &mut self.gauges_lifetime)?;
set_labels(&new_gauge, &mut self.gauges_lifetime)?;

// Register new metric
default_registry().register(Box::new(new_gauge.clone()))?;
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
private_in_public,
private_bounds,
private_interfaces,
unconditional_recursion,
unused,
unused_allocation,
Expand Down Expand Up @@ -173,6 +174,7 @@ impl Exporter {
self.spawn_stats();

if self.options().enable_metadata_refresh() {
#[allow(clippy::let_underscore_future)]
let _ = tokio::spawn(metadata::node_data::poll(self));
}
}
Expand Down Expand Up @@ -245,6 +247,7 @@ impl Exporter {
macro_rules! is_metric_enabled {
($exporter:expr, $metric:ident) => {
if $exporter.options().is_metric_enabled($metric::SUBSYSTEM) {
#[allow(clippy::let_underscore_future)]
let _ = tokio::spawn($metric::poll($exporter.clone()));
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/metric/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub fn from_value(value: Value) -> Vec<Metrics> {
output
}

fn _from_value<'f>(
fn _from_value(
prefix: &str,
output: &mut Vec<Metrics>,
value: &'f Value,
value: &Value,
) -> Result<Metrics, MetricError> {
let mut metrics = Metrics::new();

Expand All @@ -51,9 +51,9 @@ fn _from_value<'f>(
{
metrics.push(Metric::try_from((prefix, value))?);
} else if let Some(obj) = value.as_object() {
let _ = _from_map(prefix, output, obj)?;
_from_map(prefix, output, obj)?;
} else if let Some(array) = value.as_array() {
let _ = from_array(prefix, output, array)?;
from_array(prefix, output, array)?;
} else {
unreachable!()
}
Expand Down
2 changes: 1 addition & 1 deletion src/metric/metric_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'s> TryFrom<RawMetric<'s>> for MetricType {
value
.as_str()
// .replace is handling string percent notation, e.g.: "3.44%"
.map(|n| n.replace("%", "").parse::<f64>())
.map(|n| n.replace('%', "").parse::<f64>())
.ok_or_else(unknown)?
.map_err(|e| MetricError::from_parse_float(e, Some(value.clone())))
}
Expand Down
15 changes: 4 additions & 11 deletions src/metric/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ impl<'s> TryFrom<RawMetric<'s>> for Metric {
type Error = MetricError;

fn try_from(metric: RawMetric) -> Result<Self, MetricError> {
let mut key: String = metric
.0
.replace(".", "_")
.replace("-", "_")
.replace("+", "_");
let mut key: String = metric.0.replace(['.', '-', '+'], "_");

let underscore_index = key.rfind('_').unwrap_or(0);

Expand All @@ -63,13 +59,10 @@ impl<'s> TryFrom<RawMetric<'s>> for Metric {
key = key
.replace("_kilobytes", "_bytes")
.replace("_millis", "_seconds")
.replace(" ", "_")
.replace(' ', "_")
.replace(":_", "_") // should come before removing single colon
.replace(":", "_")
.replace("/", "_")
.replace("\\", "_")
.replace("[", ":")
.replace("]", ":")
.replace([':', '/', '\\'], "_")
.replace(['[', ']'], ":")
.to_lowercase();

debug_assert!(!key.contains(' '), "Key contains space: {}", key);
Expand Down
4 changes: 3 additions & 1 deletion src/metrics/_cat/shards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use super::responses::CatResponse;
pub(crate) const SUBSYSTEM: &str = "cat_shards";

async fn metrics(exporter: &Exporter) -> Result<Vec<Metrics>, elasticsearch::Error> {
let filter_path = exporter.options().query_filter_path_for_subsystem(SUBSYSTEM);
let filter_path = exporter
.options()
.query_filter_path_for_subsystem(SUBSYSTEM);

let cat = exporter.client().cat();

Expand Down
6 changes: 2 additions & 4 deletions src/metrics/_cluster/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ const COLORS: [&str; 3] = ["red", "green", "yellow"];
fn inject_cluster_health(map: &mut SerdeMap<String, Value>) {
let cluster_status: String = map
.get("status")
.map(|v| v.as_str())
.flatten()
.and_then(|v| v.as_str())
.map(ToOwned::to_owned)
.unwrap_or_else(|| "red".into());

let cluster_name: String = map
.get("cluster_name")
.map(|v| v.as_str())
.flatten()
.and_then(|v| v.as_str())
.map(ToOwned::to_owned)
.expect("/_cluster/health must contain cluster_name");

Expand Down
4 changes: 3 additions & 1 deletion src/metrics/_stats/_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pub(crate) const SUBSYSTEM: &str = "stats";

async fn metrics(exporter: &Exporter) -> Result<Vec<Metrics>, elasticsearch::Error> {
let fields = exporter.options().query_fields_for_subsystem(SUBSYSTEM);
let filter_path = exporter.options().query_filter_path_for_subsystem(SUBSYSTEM);
let filter_path = exporter
.options()
.query_filter_path_for_subsystem(SUBSYSTEM);

let indices = exporter.client().indices();

Expand Down
8 changes: 4 additions & 4 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ macro_rules! poll_metrics {
use std::cmp;
use std::time::Duration;

use crate::collection::{lifetime, lifetime::MetricLifetimeMap, Collection};
use crate::exporter_metrics::SUBSYSTEM_REQ_HISTOGRAM;
use crate::metric::{self, Metrics};
use crate::Exporter;
use $crate::collection::{lifetime, lifetime::MetricLifetimeMap, Collection};
use $crate::exporter_metrics::SUBSYSTEM_REQ_HISTOGRAM;
use $crate::metric::{self, Metrics};
use $crate::Exporter;

#[allow(unused)]
pub(crate) async fn poll(exporter: Exporter) {
Expand Down

0 comments on commit 7b50bc5

Please sign in to comment.