Skip to content

refactor: Rust best practices — doctest, test consolidation, Display, must_use, linker docs - #910

Merged
strawgate merged 4 commits into
masterfrom
refactor/rust-best-practices
Apr 4, 2026
Merged

strawgate merged 4 commits into
masterfrom
refactor/rust-best-practices

Conversation

@strawgate

Copy link
Copy Markdown
Owner

Summary

Applies Rust community best practices from the API Guidelines, matklad's build optimization advice, and blessed.rs.

Build & compile time (#892)

  • [lib] doctest = false on all 9 internal crates — each doctest compiles as a separate binary, unnecessary for unpublished crates with comprehensive unit tests and Kani proofs

  • Consolidate integration tests into single tests/it/main.rs per crate:

    Crate Consolidated Kept separate (#[global_allocator])
    logfwd-core 3 files —
    logfwd-io 2 files allocation_churn.rs
    logfwd-transform 3 files —
    logfwd 3 files allocation_e2e.rs, allocation_scaling.rs
    logfwd-output 2 files allocation_regression.rs

    Reduces test binary count from 18 → 10 (each re-links the crate, so fewer = faster).

  • Faster linker documentation in DEVELOPING.md — mold (Linux) and lld (macOS) as opt-in tips (not in .cargo/config.toml to avoid breaking builds for devs without them installed)

API quality (#893)

  • Display impls for InputType, OutputType, Format config enums (Rust API Guidelines C-COMMON-TRAITS)
  • #[must_use] on ConfigError and SendResult types (C-MUST-USE). Not added to Result-returning functions since Result itself is already #[must_use] (avoids double_must_use clippy lint).

Not changed (intentionally)

  • missing_docs lint — too noisy to enable workspace-wide under -D warnings; should be done incrementally per crate
  • Linker config in .cargo/config.toml — would break builds for devs without mold/lld
  • must_use_candidate / return_self_not_must_use clippy lints — deliberately allowed in workspace config

CI status

  • cargo fmt --check ✅
  • cargo clippy -- -D warnings ✅
  • 3 pre-existing flaky async pipeline tests fail on base branch too (timing-dependent)

Closes #892
Closes #893

strawgate and others added 2 commits April 4, 2026 01:00
Move non-global_allocator integration tests into tests/it/ modules
so each crate compiles one test binary instead of one per file.
This reduces test compile time by eliminating redundant linking.

Affected crates:
- logfwd-core: 3 test files → tests/it/main.rs
- logfwd-io: 2 test files → tests/it/main.rs (allocation_churn.rs kept separate)
- logfwd-transform: 3 test files → tests/it/main.rs
- logfwd: 3 test files → tests/it/main.rs (allocation_e2e/scaling kept separate)
- logfwd-output: 2 test files → tests/it/main.rs (allocation_regression kept separate)

Files using #[global_allocator] remain as standalone binaries since
only one global allocator per binary is allowed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… must_use, linker docs

Apply Rust community best practices from API Guidelines, matklad's build
optimization advice, and blessed.rs recommendations:

Build & compile time:
- Add [lib] doctest = false to all 9 internal crates (each doctest compiles
  as a separate binary — unnecessary for unpublished crates with unit tests)
- Consolidate integration tests into single binary per crate (tests/it/main.rs)
  for logfwd-core (3 files), logfwd-io (2), logfwd-transform (3), logfwd (3),
  logfwd-output (2). Tests with #[global_allocator] kept separate.
  Reduces test link count from 18 binaries to 10. (Ref: matklad)
- Document faster linker setup (mold/lld) in DEVELOPING.md as opt-in tip

API quality:
- Add Display impls for InputType, OutputType, Format config enums
  (Rust API Guidelines C-COMMON-TRAITS)
- Add #[must_use] to ConfigError and SendResult types
  (Rust API Guidelines C-MUST-USE — types only, not Result-returning fns
  which already inherit must_use from Result itself)

Closes #892
Closes #893

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Apr 4, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@strawgate has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 19 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 19 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: b9b0a62e-9bf4-4535-b128-b56ddb0d6f9b

📥 Commits

Reviewing files that changed from the base of the PR and between 97d8b74 and c4a5a1e.

📒 Files selected for processing (3)
  • crates/logfwd-config/src/lib.rs
  • crates/logfwd-output/Cargo.toml
  • crates/logfwd-output/tests/it/main.rs

Walkthrough

This PR implements three compile-time optimization strategies across the workspace: disabling doc tests via doctest = false in all internal crate Cargo.toml files (9 crates), consolidating integration tests into single binaries by adding module declarations to tests/it/main.rs files (6 crates), and adding linker configuration guidance to DEVELOPING.md for faster incremental rebuilds. Additionally, Display trait implementations are added for InputType, OutputType, and Format enums in logfwd-config, and #[must_use] attributes are applied to ConfigError and SendResult. A test include path is corrected in vectorization\_canary.rs.

Possibly related PRs


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
High-Quality Rust Practices ❌ Error PR includes elasticsearch_sink_sends_bulk_data test without #[ignore] attribute, violating test reliability practices. Add #[ignore = "requires running Elasticsearch service"] to elasticsearch_sink_sends_bulk_data and related ES-dependent tests.
Documentation Thoroughly Updated ⚠️ Warning PR adds four public impl fmt::Display blocks in crates/logfwd-config/src/lib.rs without required /// doc comments per guidance. Add /// doc comments to each of the four impl fmt::Display blocks explaining the string format each produces.
Maintainer Fitness ⚠️ Warning PR consolidates Rust best practices effectively but fails to proactively address unignored elasticsearch_integration tests introduced by consolidation, creating environmental flakiness. Add #[ignore] attributes to elasticsearch-dependent tests and document the decision in PR description before merging.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed All primary objectives from #892 (doctest, linker docs, test consolidation) and #893 (Display, must_use) are implemented and addressed.
Out of Scope Changes check ✅ Passed All changes directly address the linked issues. DEVELOPING.md guidance and all Cargo.toml/test module changes align with stated objectives.
Formal Verification Coverage ✅ Passed PR reorganizes existing logfwd-core modules with comprehensive verification documentation. VERIFICATION.md added with per-module proof counts; no new unverified public functions in logfwd-core.
Crate Boundary And Dependency Integrity ✅ Passed PR maintains crate boundary and dependency integrity with no changes to workspace members, external dependencies, or crate boundaries.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/logfwd-config/src/lib.rs`:
- Around line 122-137: The Display impl for OutputType duplicates the strings
returned by the helper output_type_name; update the Display implementation to
delegate to that helper instead of repeating the match. Locate impl fmt::Display
for OutputType and replace its match body so it calls
f.write_str(output_type_name(self)), keeping output_type_name as the single
source of truth for the &str names (or conversely make output_type_name call
self.to_string() if you prefer Display-driven behavior).

In `@crates/logfwd-output/tests/it/main.rs`:
- Around line 1-2: Gate the ES-dependent module so integration runs only when
explicitly enabled: replace the unconditional `mod elasticsearch_integration;`
with a feature-gated pair—add `#[cfg(feature =
"elasticsearch_integration_tests")] mod elasticsearch_integration;` and a noop
stub `#[cfg(not(feature = "elasticsearch_integration_tests"))] mod
elasticsearch_integration {}` to keep the module path valid when the feature is
off; also mark or gate tests inside `elasticsearch_integration.rs` (or add
`#[cfg(feature = "elasticsearch_integration_tests")]` at the top of that file)
so CI only runs them when the feature is enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: b7348363-e326-4e1b-aafa-a4fc95dd66d5

📥 Commits

Reviewing files that changed from the base of the PR and between 38ce422 and 97d8b74.

📒 Files selected for processing (31)
  • DEVELOPING.md
  • crates/logfwd-arrow/Cargo.toml
  • crates/logfwd-config/Cargo.toml
  • crates/logfwd-config/src/lib.rs
  • crates/logfwd-core/Cargo.toml
  • crates/logfwd-core/tests/it/compliance_data.rs
  • crates/logfwd-core/tests/it/main.rs
  • crates/logfwd-core/tests/it/scanner_conformance.proptest-regressions
  • crates/logfwd-core/tests/it/scanner_conformance.rs
  • crates/logfwd-core/tests/it/vectorization_canary.rs
  • crates/logfwd-ebpf-proto/Cargo.toml
  • crates/logfwd-io/Cargo.toml
  • crates/logfwd-io/tests/it/checkpoint_state_machine.rs
  • crates/logfwd-io/tests/it/main.rs
  • crates/logfwd-io/tests/it/transport_e2e.rs
  • crates/logfwd-output/Cargo.toml
  • crates/logfwd-output/src/sink.rs
  • crates/logfwd-output/tests/it/elasticsearch_arrow_ipc.rs
  • crates/logfwd-output/tests/it/elasticsearch_integration.rs
  • crates/logfwd-output/tests/it/main.rs
  • crates/logfwd-test-utils/Cargo.toml
  • crates/logfwd-transform/Cargo.toml
  • crates/logfwd-transform/tests/it/json_udf_tests.rs
  • crates/logfwd-transform/tests/it/main.rs
  • crates/logfwd-transform/tests/it/raw_first_bench.rs
  • crates/logfwd-transform/tests/it/scanner_datafusion_boundary.rs
  • crates/logfwd/Cargo.toml
  • crates/logfwd/tests/it/compliance.rs
  • crates/logfwd/tests/it/compliance_file.rs
  • crates/logfwd/tests/it/integration.rs
  • crates/logfwd/tests/it/main.rs

Comment thread crates/logfwd-config/src/lib.rs Resolved
Comment on lines +1 to +2
mod elasticsearch_arrow_ipc;
mod elasticsearch_integration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Gate Elasticsearch-dependent tests before including elasticsearch_integration.

Line 2 includes elasticsearch_integration in default integration execution, but that module contains unignored tests (e.g., crates/logfwd-output/tests/it/elasticsearch_integration.rs, Line 56). This can make CI/environment-default runs flaky or fail when ES is unavailable.

Suggested fix (apply in crates/logfwd-output/tests/it/elasticsearch_integration.rs)
 #[test]
+#[ignore = "requires running Elasticsearch (see examples/elasticsearch/)"]
 fn elasticsearch_sink_sends_bulk_data() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/logfwd-output/tests/it/main.rs` around lines 1 - 2, Gate the
ES-dependent module so integration runs only when explicitly enabled: replace
the unconditional `mod elasticsearch_integration;` with a feature-gated pair—add
`#[cfg(feature = "elasticsearch_integration_tests")] mod
elasticsearch_integration;` and a noop stub `#[cfg(not(feature =
"elasticsearch_integration_tests"))] mod elasticsearch_integration {}` to keep
the module path valid when the feature is off; also mark or gate tests inside
`elasticsearch_integration.rs` (or add `#[cfg(feature =
"elasticsearch_integration_tests")]` at the top of that file) so CI only runs
them when the feature is enabled.

strawgate and others added 2 commits April 4, 2026 01:40
… source of truth

Address CodeRabbit review: the output_type_name helper duplicated the
same strings as the new Display impl for OutputType. Replace all 4 call
delete the now-unused helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add elasticsearch_integration_tests feature flag to logfwd-output.
The elasticsearch_integration module now only compiles when explicitly
enabled with --features elasticsearch_integration_tests, preventing
CI from running ES-dependent tests without infrastructure.

Addresses CodeRabbit review item 2 on PR #910.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant