Skip to content

chore: fix clippy warnings#147

Merged
duncanpharvey merged 2 commits into
mainfrom
duncan-harvey/clippy
Jul 17, 2026
Merged

chore: fix clippy warnings#147
duncanpharvey merged 2 commits into
mainfrom
duncan-harvey/clippy

Conversation

@duncanpharvey

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes clippy warnings.

Motivation

https://github.com/DataDog/serverless-components/actions/runs/29588791501/job/87912458431?pr=146

error: redundant reference in `format!` argument
  --> crates/dogstatsd/src/datadog/shipping.rs:46:47
   |
46 |         let url = format!("{}/api/v2/series", &self.metrics_intake_url_prefix);
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the redundant `&`: `self.metrics_intake_url_prefix`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#useless_borrows_in_formatting
   = note: `-D clippy::useless-borrows-in-formatting` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::useless_borrows_in_formatting)]`

error: redundant reference in `format!` argument
  --> crates/dogstatsd/src/datadog/shipping.rs:57:51
   |
57 |         let url = format!("{}/api/beta/sketches", &self.metrics_intake_url_prefix);
   |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the redundant `&`: `self.metrics_intake_url_prefix`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#useless_borrows_in_formatting

error: this block may be rewritten with the `?` operator
  --> crates/dogstatsd/src/util.rs:43:5
   |
43 | /     if let Some(first_char) = chars.next() {
44 | |         if !first_char.is_ascii_alphabetic() {
45 | |             tracing::error!(
46 | |                 "DD_STATSD_METRIC_NAMESPACE must start with a letter, got: '{}'. Ignoring namespace.",
...  |
52 | |         return None;
53 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#question_mark
   = note: `-D clippy::question-mark` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::question_mark)]`
help: replace it with
   |
43 ~     {
44 +         let first_char = chars.next()?;
45 +         if !first_char.is_ascii_alphabetic() {
46 +             tracing::error!(
47 +                 "DD_STATSD_METRIC_NAMESPACE must start with a letter, got: '{}'. Ignoring namespace.",
48 +                 trimmed
49 +             );
50 +             return None;
51 +         }
52 +     }
   |

Additional Notes

Describe how to test/QA your changes

@duncanpharvey
duncanpharvey marked this pull request as ready for review July 17, 2026 14:57
@duncanpharvey
duncanpharvey requested a review from a team as a code owner July 17, 2026 14:57
Copilot AI review requested due to automatic review settings July 17, 2026 14:57
@duncanpharvey
duncanpharvey requested a review from a team as a code owner July 17, 2026 14:57
@duncanpharvey
duncanpharvey requested review from apiarian-datadog and jchrostek-dd and removed request for a team July 17, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Rust Clippy warnings in the DogStatsD crate, keeping CI green under -D warnings while preserving existing behavior.

Changes:

  • Simplified parse_metric_namespace control flow by using the ? operator for early-return on missing first character.
  • Removed redundant borrows in format! calls when constructing Datadog intake URLs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/dogstatsd/src/util.rs Refactors namespace parsing to use ? for Option early-return and satisfy Clippy.
crates/dogstatsd/src/datadog/shipping.rs Cleans up format! argument borrowing to satisfy Clippy.
Comments suppressed due to low confidence (1)

crates/dogstatsd/src/datadog/shipping.rs:50

  • trace!("Sending body: {:?}", series) logs the full metrics payload. Metric tags/names can contain customer identifiers; logging the full payload risks leaking sensitive data and can be very noisy. Prefer logging only counts/sizes.
        let safe_body = serde_json::to_vec(&series)
            .map_err(|e| ShippingError::Payload(format!("Failed to serialize series: {e}")))?;
        trace!("Sending body: {:?}", &series);
        self.ship_data(url, safe_body, "application/json").await

Comment thread crates/dogstatsd/src/datadog/shipping.rs Outdated
@duncanpharvey
duncanpharvey merged commit cf0855a into main Jul 17, 2026
27 checks passed
@duncanpharvey
duncanpharvey deleted the duncan-harvey/clippy branch July 17, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants