Skip to content

Remove dead code that needed test edits rather than deletions - #397

Open
dpage wants to merge 1 commit into
mainfrom
dead-code-round2
Open

Remove dead code that needed test edits rather than deletions#397
dpage wants to merge 1 commit into
mainfrom
dead-code-round2

Conversation

@dpage

@dpage dpage commented Aug 7, 2026

Copy link
Copy Markdown
Member

The third and final pass over the reachability findings, completing the
set alongside #395 and #396.

#395 deliberately deferred 42 functions because deleting them broke tests
that also cover live code, so each needed its tests edited rather
than removed. Working through them one at a time, 18 turned out to be
genuinely removable and 24 did not
, which is the most useful result
here: the deferral list was not a backlog of easy wins.

What was removed

Lines
Production Go 286 (18 functions)
Tests 567
Total 853 deletions, 12 insertions (changelog)

The largest group is the alerter's notification-channel write API:
ten methods covering channel create/update/delete, email recipients,
connection links, notification history and reminder state, none with a
caller. The alerter reads notification channels; the server owns every
write. Those went with the five integration tests that existed solely to
exercise them, and their assertions in the shared closed-pool error-path
test were excised individually so the remaining assertions still run.

The rest: a datastore pool accessor, a monitored-pool max-connections
getter, two compaction analytics reporters, a probe-availability lookup,
and three session tracing helpers.

What was deliberately kept, and why

This is the substantive half. Twenty-four were left in place because
removing them would mean weakening tests of live code:

  • Injection seams that exist so tests can substitute fakes:
    AlertHandler.setAlertResolver and setUnacknowledgeFn,
    newVisibilityListerWithSource, overview.NewHandler, and
    NewWebhookNotifierAllowInternal — whose sibling's doc comment
    explicitly says "Use NewWebhookNotifierAllowInternal for testing
    against localhost endpoints".
  • Accessors their own tests depend on: CompactionCache.Clear and
    ReloadableConfig.Get. Both are worth singling out, because excising
    the call left tests that still compiled, still linted clean, and
    silently failed
    : without Clear(), TestCompactionCache_Size
    asserts a size of 0 against a cache holding two entries. Also
    Hub.Count and GetAnomalyCandidateByID, the latter being how a test
    verifies the live CreateAnomalyCandidate round-trips.
  • The logging level setters SetLevel and SetLogLevel.
    internal/logging defaults to LevelError and the database logger to
    LogLevelNone, so without the setter their tests cannot exercise
    filtering of live logging code at all.
  • MessageClass.String, a Stringer used for test diagnostics;
    removing it degrades failure messages to bare integers.
  • AuthHandler.Close, which stops h.totalRateLimiter and is called
    by nothing in cmd/mcp-server. That reads as a leaked ticker
    goroutine in production
    rather than dead code, so it wants wiring up
    rather than deleting. Flagged for a follow-up.

Four more are blocked until #395 merges, because their only remaining
callers are themselves deleted there: IsAPITokenFromContext (called
from access.go), Logger.Trace (from LogQueryTrace), and cron's
Parser.Validate (from the package-level Validate).

Verification

Module main This branch
collector 85.5% 85.6%
server 55.5% 55.5%
alerter 65.9% 64.4%

The alerter drop is the arithmetic of removing well-covered code: 193
production lines and 344 test lines of notification CRUD that were
thoroughly tested. It stays above the 60% repository goal, and no new
code is added so the 90% floor for new and modified code does not apply.

⚠️ Merge order

This branch is cut from main so CI runs against it, but it conflicts
with #395
and must be rebased after that merges. I verified this with a
trial merge; the conflicts are in:

collector/src/database/monitored_pool.go
collector/src/database/monitored_pool_test.go
server/src/internal/compactor/analytics.go
server/src/internal/compactor/analytics_test.go
docs/changelog.md

All are cases where #395 removed one function from a file and this PR
removes another. There is no conflict with #396. Happy to do the
rebase once #395 lands.

Summary by CodeRabbit

  • Removed

    • Removed unused database management operations for notification channels, email recipients, connection links, notification history, and reminder states.
    • Removed probe-availability lookups and several internal accessors for connection pools, compaction analytics, and tracing.
    • Removed related integration and verification tests for discontinued functionality.
  • Documentation

    • Added an unreleased changelog entry documenting the removed capabilities across the platform.

The third and final pass over the reachability findings. The earlier
mechanical pass deferred 42 functions because deleting them broke tests
that also cover live code, so those needed the tests editing rather than
removing. Working through them individually, 18 turned out to be
genuinely removable and the rest did not.

The largest group is the alerter's notification-channel write API: ten
methods covering channel create, update and delete, email recipients,
connection links, notification history and reminder state, none of which
has a caller. The alerter reads notification channels; the server owns
every write. Those went along with the five integration tests that
existed solely to exercise them, and their assertions in the shared
closed-pool error-path test were excised individually so the remaining
assertions still run.

The rest are a datastore pool accessor, a monitored-pool max-connections
getter, two compaction analytics reporters, a probe-availability lookup,
and three session tracing helpers.

Twenty-four of the 42 are deliberately left in place, because deleting
them would have meant weakening tests that exercise live code:

  - Injection seams that exist so tests can substitute fakes:
    AlertHandler.setAlertResolver and setUnacknowledgeFn,
    newVisibilityListerWithSource, NewWebhookNotifierAllowInternal
    (whose sibling's doc comment explicitly points at it for localhost
    testing), and overview.NewHandler.
  - Accessors their own tests depend on: CompactionCache.Clear and
    ReloadableConfig.Get, both of which had tests that silently inverted
    when the call was excised, plus Hub.Count and
    GetAnomalyCandidateByID, which verifies a live write path.
  - The logging level setters SetLevel and SetLogLevel. Both packages
    default to a level that suppresses output, so their tests need the
    setter to exercise filtering of live logging code at all.
  - MessageClass.String, a Stringer used for test diagnostics.
  - AuthHandler.Close, which stops h.totalRateLimiter and is called by
    nothing in cmd/mcp-server. That looks like a leaked goroutine in
    production rather than dead code, and wants fixing rather than
    deleting; noted for a follow-up.

Four more are blocked until the earlier branch merges, because the only
remaining callers are themselves being deleted there:
IsAPITokenFromContext (called from access.go), Logger.Trace (from
LogQueryTrace) and cron's Parser.Validate (from the package-level
Validate).

Coverage: collector 85.6% (from 85.5%), server 55.5% (unchanged),
alerter 64.4% (from 65.9%). The alerter drop is the arithmetic of
removing well-covered code, and it stays above the 60% repository goal.
The only failing tests are the two pre-existing vector(3) fixture
failures from #337, which reproduce identically on unmodified main.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change removes unused APIs from alerter database access, collector pool management, compactor analytics, and tracing. It also removes dedicated tests, adjusts remaining integration assertions, and documents the removals in the changelog.

Changes

Unused API removal

Layer / File(s) Summary
Alerter database API cleanup
alerter/src/internal/database/datastore.go, alerter/src/internal/database/notification_queries.go, alerter/src/internal/database/queries.go, alerter/src/internal/database/*_test.go
Removed the pool accessor, probe-availability lookup, notification write operations, connection-channel operations, notification-history retrieval, and reminder-state mutations. Related tests were removed or changed to retain notification query error checks.
Collector pool accessor cleanup
collector/src/database/monitored_pool.go, collector/src/database/monitored_pool_test.go
Removed GetMaxConnections. Tests retain setup and setter calls but no longer assert maximum-connection values.
Compactor analytics cleanup
server/src/internal/compactor/analytics.go, server/src/internal/compactor/analytics_test.go
Removed GetMetrics and GetEfficiencyReport. Analytics tests no longer validate metric, efficiency, reset, timestamp, concurrency, or empty-state results.
Tracing cleanup and release record
server/src/internal/tracing/tracer.go, server/src/internal/tracing/tracer_test.go, docs/changelog.md
Removed tracing file-path and session lifecycle helpers, deleted their assertions, and documented the removed APIs in the unreleased changelog.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: susan-pgedge

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing unused code while retaining and editing tests that cover live code.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dead-code-round2

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

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/changelog.md`:
- Around line 258-266: Update the removed-function count in the changelog entry
from 18 to 17 so it matches the listed groups: 10 notification-channel methods,
1 pool accessor, 2 analytics reporters, 1 probe lookup, and 3 tracing helpers.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0355baa-ab05-46ee-9d85-05dc7b99f8c9

📥 Commits

Reviewing files that changed from the base of the PR and between 19c645d and ec161ba.

📒 Files selected for processing (14)
  • alerter/src/internal/database/datastore.go
  • alerter/src/internal/database/datastore_test.go
  • alerter/src/internal/database/error_paths_integration_test.go
  • alerter/src/internal/database/notification_queries.go
  • alerter/src/internal/database/notification_queries_full_integration_test.go
  • alerter/src/internal/database/queries.go
  • alerter/src/internal/database/queries_full_integration_test.go
  • collector/src/database/monitored_pool.go
  • collector/src/database/monitored_pool_test.go
  • docs/changelog.md
  • server/src/internal/compactor/analytics.go
  • server/src/internal/compactor/analytics_test.go
  • server/src/internal/tracing/tracer.go
  • server/src/internal/tracing/tracer_test.go
💤 Files with no reviewable changes (13)
  • collector/src/database/monitored_pool.go
  • alerter/src/internal/database/datastore_test.go
  • server/src/internal/tracing/tracer_test.go
  • alerter/src/internal/database/queries.go
  • server/src/internal/tracing/tracer.go
  • alerter/src/internal/database/datastore.go
  • collector/src/database/monitored_pool_test.go
  • alerter/src/internal/database/notification_queries.go
  • alerter/src/internal/database/queries_full_integration_test.go
  • server/src/internal/compactor/analytics.go
  • alerter/src/internal/database/error_paths_integration_test.go
  • server/src/internal/compactor/analytics_test.go
  • alerter/src/internal/database/notification_queries_full_integration_test.go

Comment thread docs/changelog.md
Comment on lines +258 to +266
- Remove a further 18 unused functions across the collector, server, and
alerter, together with the tests that existed only to exercise them.
The largest group is the alerter's notification-channel write API,
where ten methods covering channel creation, updates, deletion, email
recipients, connection links, notification history, and reminder state
had no caller; the alerter reads notification channels, whilst the
server owns every write. The rest are a pool accessor, two compaction
analytics reporters, a probe-availability lookup, and three session
tracing helpers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the removed-function count.

The listed groups total 17 functions: 10 notification-channel methods, 1 pool accessor, 2 analytics reporters, 1 probe lookup, and 3 tracing helpers. Change 18 to 17, or add the missing function to the list.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/changelog.md` around lines 258 - 266, Update the removed-function count
in the changelog entry from 18 to 17 so it matches the listed groups: 10
notification-channel methods, 1 pool accessor, 2 analytics reporters, 1 probe
lookup, and 3 tracing helpers.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -46 complexity · -4 duplication

Metric Results
Complexity -46
Duplication -4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant