Skip to content

Commit 14ba9bb

Browse files
Lewis-EclaudeCopilot
authored
chore: add pre-push hook for cargo fmt and clippy (#130)
* chore: add pre-push hook for cargo fmt and clippy Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * fix: remove unnecessary u32 casts flagged by clippy Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * fix: apply cargo fmt formatting Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * fix: collapse nested if block flagged by clippy Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * chore: treat clippy warnings as errors in CI and document pre-push hook Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * fix: bias mini_agent serve() select toward shutdown over task exits When shutdown_tx fires, each transport accept loop sees shutdown_rx, drains its joinset, and returns Ok(()). Both the accept loop's JoinHandle and the supervisor's shutdown_rx.changed() then become ready in the same poll cycle. Without biased, the unbiased select! in serve() would pick a *Died arm at random, return Err(...), and abort everything without firing flusher_shutdown_tx — so the stats flusher's shutdown branch never ran and no final stats POST happened. This made test_mini_agent_*_with_real_flushers intermittently time out at 60s waiting for /api/v0.2/stats; CI run 25562651282 captured the smoking gun "Event::PipeDied: Ok(Ok(()))". biased; with shutdown_rx.changed() listed first guarantees Event::Shutdown wins whenever the shutdown signal is observable, so the supervisor always takes the graceful-flush path even if the accept loops happen to resolve first. Production main.rs never sends on shutdown_tx, so this is purely a test-only path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent cb3a20b commit 14ba9bb

6 files changed

Lines changed: 48 additions & 15 deletions

File tree

.githooks/pre-push

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo ">>> [pre-push] Running cargo fmt --check..."
5+
if ! cargo fmt --all -- --check; then
6+
echo ""
7+
echo "HOOK FAILED: cargo fmt check failed."
8+
echo "Try 'cargo fmt --all' then re-attempt the push."
9+
exit 1
10+
fi
11+
12+
echo ">>> [pre-push] Running cargo clippy..."
13+
if ! cargo clippy --workspace --all-targets --all-features -- -D warnings; then
14+
echo ""
15+
echo "HOOK FAILED: cargo clippy reported warnings or errors."
16+
echo "Fix the clippy diagnostics above, then re-attempt the push."
17+
exit 1
18+
fi
19+
20+
echo ">>> [pre-push] All checks passed."

.github/workflows/cargo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
# doesn't fail.
6161
export AWS_LC_FIPS_SYS_NO_ASM=1
6262
fi
63-
cargo clippy --workspace --all-features
63+
cargo clippy --workspace --all-features -- -D warnings
6464
6565
build:
6666
name: Build

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# Serverless Components
22

3-
A collection of libraries and binaries used for instrumenting AWS Lambda Functions, Azure Functions, and Azure Spring Apps.
3+
A collection of libraries and binaries used for instrumenting AWS Lambda Functions, Azure Functions, and Azure Spring Apps.
4+
5+
## Development
6+
7+
Install the git pre-push hook (runs `cargo fmt --check` and `cargo clippy -D warnings` before each push):
8+
9+
```sh
10+
git config core.hooksPath .githooks
11+
```

crates/datadog-trace-agent/src/mini_agent.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,19 @@ impl MiniAgent {
295295
};
296296
tokio::pin!(concentrator_exit);
297297

298+
// biased: when shutdown_tx fires, the accept loops also see
299+
// shutdown_rx and exit cleanly. Their JoinHandles resolve in the
300+
// same poll cycle as our shutdown_rx.changed(); without biased,
301+
// a *Died arm can win the race and abort the supervisor before
302+
// it has a chance to signal the stats flusher to flush.
298303
tokio::select! {
304+
biased;
305+
_ = shutdown_rx.changed() => Event::Shutdown,
299306
r = &mut tcp_exit => Event::TcpDied(format!("{r:?}")),
300307
r = &mut pipe_exit => Event::PipeDied(format!("{r:?}")),
301308
r = &mut trace_flusher_handle => Event::TraceFlusherDied(format!("{r:?}")),
302309
r = &mut stats_flusher_handle => Event::StatsFlusherDied(format!("{r:?}")),
303310
r = &mut concentrator_exit => Event::ConcentratorDied(format!("{r:?}")),
304-
_ = shutdown_rx.changed() => Event::Shutdown,
305311
}
306312
};
307313
#[cfg(not(all(windows, feature = "windows-pipes")))]
@@ -322,12 +328,14 @@ impl MiniAgent {
322328
};
323329
tokio::pin!(concentrator_exit);
324330

331+
// biased: see Windows branch above for rationale.
325332
tokio::select! {
333+
biased;
334+
_ = shutdown_rx.changed() => Event::Shutdown,
326335
r = &mut tcp_exit => Event::TcpDied(format!("{r:?}")),
327336
r = &mut trace_flusher_handle => Event::TraceFlusherDied(format!("{r:?}")),
328337
r = &mut stats_flusher_handle => Event::StatsFlusherDied(format!("{r:?}")),
329338
r = &mut concentrator_exit => Event::ConcentratorDied(format!("{r:?}")),
330-
_ = shutdown_rx.changed() => Event::Shutdown,
331339
}
332340
};
333341

crates/datadog-trace-agent/tests/integration_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ async fn test_mini_agent_tcp_with_real_flushers() {
385385
let mut server_ready = false;
386386
for _ in 0..20 {
387387
tokio::time::sleep(Duration::from_millis(50)).await;
388-
if let Ok(response) = send_tcp_request(test_port, "/info", "GET", None, &[]).await {
389-
if response.status().is_success() {
390-
server_ready = true;
391-
break;
392-
}
388+
if let Ok(response) = send_tcp_request(test_port, "/info", "GET", None, &[]).await
389+
&& response.status().is_success()
390+
{
391+
server_ready = true;
392+
break;
393393
}
394394
}
395395
assert!(

crates/dogstatsd/src/origin.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,13 @@ mod tests {
310310
timestamp: 0,
311311
};
312312
let origin = metric.find_origin(tags).unwrap();
313+
assert_eq!(origin.origin_product, OriginProduct::Serverless as u32);
313314
assert_eq!(
314-
origin.origin_product as u32,
315-
OriginProduct::Serverless as u32
316-
);
317-
assert_eq!(
318-
origin.origin_category as u32,
315+
origin.origin_category,
319316
OriginCategory::AzureFunctionsMetrics as u32
320317
);
321318
assert_eq!(
322-
origin.origin_service as u32,
319+
origin.origin_service,
323320
OriginService::ServerlessEnhanced as u32
324321
);
325322
}

0 commit comments

Comments
 (0)