Skip to content

Commit

Permalink
Add a clippy CI check (#416) (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstinus authored Dec 22, 2023
1 parent a818f50 commit 52f5a50
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ jobs:
run: rustup default stable
- name: Run Benchmarks
run: cargo bench --all-features --workspace --exclude=metrics-observer
clippy:
name: Clippy ${{ matrix.rust_version }}
runs-on: ubuntu-latest
strategy:
matrix:
rust_version: ['1.61.0', 'stable', 'nightly']
steps:
- uses: actions/checkout@v3
- name: Install Protobuf Compiler
run: sudo apt-get install protobuf-compiler
- name: Install Rust ${{ matrix.rust_version }}
run: rustup default ${{ matrix.rust_version }}
- name: Run Clippy
run: cargo clippy --all-features --workspace --exclude=metrics-observer
3 changes: 2 additions & 1 deletion metrics-exporter-prometheus/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl PrometheusBuilder {
///
/// If there is an error while building the recorder and exporter, an error variant will be
/// returned describing the error.
#[warn(clippy::too_many_lines)]
#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "http-listener", feature = "push-gateway"))))]
#[cfg_attr(not(feature = "http-listener"), allow(unused_mut))]
Expand Down Expand Up @@ -501,7 +502,7 @@ impl PrometheusBuilder {
.map(|mut b| b.copy_to_bytes(b.remaining()))
.map(|b| b[..].to_vec())
.and_then(|s| String::from_utf8(s).map_err(|_| ()))
.unwrap_or_else(|_| {
.unwrap_or_else(|()| {
String::from("<failed to read response body>")
});
error!(
Expand Down
5 changes: 3 additions & 2 deletions metrics-exporter-prometheus/src/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Distribution {

impl Distribution {
/// Creates a histogram distribution.
#[warn(clippy::missing_panics_doc)]
pub fn new_histogram(buckets: &[f64]) -> Distribution {
let hist = Histogram::new(buckets).expect("buckets should never be empty");
Distribution::Histogram(hist)
Expand Down Expand Up @@ -83,7 +84,7 @@ impl DistributionBuilder {
/// Returns a distribution for the given metric key.
pub fn get_distribution(&self, name: &str) -> Distribution {
if let Some(ref overrides) = self.bucket_overrides {
for (matcher, buckets) in overrides.iter() {
for (matcher, buckets) in overrides {
if matcher.matches(name) {
return Distribution::new_histogram(buckets);
}
Expand All @@ -104,7 +105,7 @@ impl DistributionBuilder {
}

if let Some(ref overrides) = self.bucket_overrides {
for (matcher, _) in overrides.iter() {
for (matcher, _) in overrides {
if matcher.matches(name) {
return "histogram";
}
Expand Down
2 changes: 1 addition & 1 deletion metrics-exporter-prometheus/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Inner {
let mut wg = self.distributions.write().unwrap_or_else(PoisonError::into_inner);
let entry = wg
.entry(name.clone())
.or_insert_with(IndexMap::new)
.or_default()
.entry(labels)
.or_insert_with(|| self.distribution_builder.get_distribution(name.as_str()));

Expand Down

0 comments on commit 52f5a50

Please sign in to comment.