Skip to content

refactor(stats): take stats_url as a StatsFlusher::new parameter#1210

Merged
lucaspimentel merged 1 commit intomainfrom
lpimentel/stats-flusher-url-param
May 5, 2026
Merged

refactor(stats): take stats_url as a StatsFlusher::new parameter#1210
lucaspimentel merged 1 commit intomainfrom
lpimentel/stats-flusher-url-param

Conversation

@lucaspimentel
Copy link
Copy Markdown
Member

@lucaspimentel lucaspimentel commented Apr 24, 2026

Summary of changes

Refactor StatsFlusher::new to accept a stats_url: String parameter instead of deriving the URL internally from config.site.

Reason for change

  1. Removes internal duplicationtrace_stats_url(&self.config.site) was being called in two separate places inside StatsFlusher (in get_or_init and again in the retry loop). It's now computed once at the call site.
  2. Enables future flexibility — callers can supply any URL (e.g. a custom endpoint or test harness) without StatsFlusher needing to know about it.
  3. Better separation of concernsStatsFlusher no longer owns URL resolution; it simply uses the URL it's given. This mirrors how TraceFlusher already works, where the URL comes from outside via SendData's embedded Endpoint.

Implementation details

  • Added a stats_url: String field to StatsFlusher and a corresponding parameter to StatsFlusher::new.
  • Removed the trace_stats_url import from stats_flusher.rs; the call now lives in main.rs::start_trace_agent.
  • Replaced the two internal trace_stats_url(&self.config.site) calls with self.stats_url.
  • Retry-loop debug logs now report endpoint.url so they reflect the URL actually contacted instead of a re-derived site URL.

Test coverage

No new tests — this is a pure refactor of an internal constructor signature with no behavior change. Verified existing checks pass:

  • cargo build on the bottlecap crate
  • cargo check --workspace — clean
  • RUSTFLAGS="-D warnings" cargo clippy --workspace --all-targets --features default — clean
  • cargo fmt --all -- --check — clean
  • cargo nextest run --workspace — 526/526 passed

@lucaspimentel lucaspimentel changed the title refactor(stats): take stats_url as a StatsFlusher::new parameter refactor(stats): take stats_url as a StatsFlusher::new parameter Apr 24, 2026
@lucaspimentel lucaspimentel marked this pull request as ready for review April 24, 2026 17:43
@lucaspimentel lucaspimentel requested review from a team as code owners April 24, 2026 17:43
@lucaspimentel lucaspimentel requested review from Copilot and lym953 April 24, 2026 17:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors StatsFlusher so its stats intake URL is provided by the caller instead of being derived internally, enabling future use cases like redirecting stats flushing to alternate endpoints (e.g., a fake intake for integration tests).

Changes:

  • Add a stats_url: String parameter to StatsFlusher::new and store it on the flusher.
  • Move trace_stats_url(&config.site) computation into bottlecap’s main.rs at the call site.
  • Update retry-loop debug logs to report the actual endpoint.url used for requests.

Reviewed changes

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

File Description
bottlecap/src/traces/stats_flusher.rs Accepts/stores stats_url, uses it to build the Endpoint, and logs the contacted endpoint URL.
bottlecap/src/bin/bottlecap/main.rs Computes trace_stats_url(&config.site) and passes it into StatsFlusher::new.

Comment thread bottlecap/src/traces/stats_flusher.rs
Comment thread bottlecap/src/traces/stats_flusher.rs
@lucaspimentel lucaspimentel force-pushed the lpimentel/stats-flusher-url-param branch from 8f52b41 to 6fbe14b Compare April 24, 2026 21:07
@lucaspimentel lucaspimentel force-pushed the lpimentel/stats-flusher-url-param branch from 6fbe14b to 56162d9 Compare April 28, 2026 19:52
StatsFlusher derived its intake URL internally via
trace_stats_url(&config.site), which hardcodes
https://trace.agent.{site}/api/v0.2/stats. Lift the URL to the caller:
main.rs now computes trace_stats_url at the call site and passes it in.

Mirrors how TraceFlusher already works (URL comes from outside via
SendData's embedded Endpoint) and unblocks redirecting StatsFlusher to
alternate endpoints such as in-process test harnesses.

Retry-loop debug logs now report endpoint.url so they match the URL
actually contacted.

Co-Authored-By: Claude <noreply@anthropic.com>
@lucaspimentel lucaspimentel force-pushed the lpimentel/stats-flusher-url-param branch from 56162d9 to 1850777 Compare May 5, 2026 17:10
@lucaspimentel lucaspimentel merged commit dfe419b into main May 5, 2026
55 of 56 checks passed
@lucaspimentel lucaspimentel deleted the lpimentel/stats-flusher-url-param branch May 5, 2026 20:27
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.

3 participants