Skip to content

Increase test coverage to 83.8% and fix SetupHystrixPrometheus panic#43

Merged
ankurs merged 4 commits intomainfrom
feat/test-coverage-and-sync-once
Mar 24, 2026
Merged

Increase test coverage to 83.8% and fix SetupHystrixPrometheus panic#43
ankurs merged 4 commits intomainfrom
feat/test-coverage-and-sync-once

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Mar 23, 2026

Summary

  • Add comprehensive test suite (core_coverage_test.go) covering server lifecycle, HTTP handler routing, initializers, VTProto codec, and utility functions
  • Bug fix: Wrap SetupHystrixPrometheus with sync.Once to prevent panic on duplicate Prometheus collector registration
  • Coverage: 21.3% → 83.8%
  • Regenerate READMEs via gomarkdoc

Test plan

  • go test -race -cover ./... passes with 83.8% coverage
  • Verify SetupHystrixPrometheus no longer panics when called multiple times

Summary by CodeRabbit

  • Documentation

    • Updated API reference documentation with corrected line references for core package initializers
    • Revised service startup documentation to reflect current health check endpoints
  • Bug Fixes

    • Fixed duplicate Prometheus collector registration panic that could occur on multiple initializations
  • Tests

    • Added comprehensive test suite covering core package functionality and edge cases

…panic

- Add comprehensive test suite (core_coverage_test.go) covering server
  lifecycle, HTTP handler routing, initializers, VTProto codec, and
  utility functions
- Fix SetupHystrixPrometheus to use sync.Once, preventing panic on
  duplicate Prometheus collector registration
- Regenerate READMEs via gomarkdoc
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Documentation updates for API reference line ranges and health endpoint changes; introduction of a comprehensive 912-line test suite for the core package; and modification of SetupHystrixPrometheus to use sync.Once for thread-safe Prometheus collector registration.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md, config/README.md
Updated API reference line ranges for core package functions and extended SetupHystrixPrometheus description to mention sync.Once usage. Changed health endpoint documentation from single GET /healthz to GET /healthcheck and GET /readycheck.
Test Suite
core_coverage_test.go
New comprehensive test file covering openAPI handlers, TLS credentials, HTTP tracing, gRPC server options, process config mutations, gRPC/HTTP initialization, server lifecycle (Stop, Run), and initializer functions (logger, sentry, New Relic, OpenTelemetry, VTProto codec).
Thread-Safety Fix
initializers.go
Modified SetupHystrixPrometheus to guard Prometheus collector registration with sync.Once, preventing duplicate registration panics on multiple invocations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • vestor
  • fajran
  • kevinjom
  • svetha-cvl

Poem

🐰 Hop, hop! The tests now bloom so bright,
With coverage spanning left and right,
sync.Once guards the Prometheus call,
No duplicate panics shall befall!
Docs updated, endpoints re-aligned—
A safety net, beautifully designed!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the two main changes in the PR: comprehensive test coverage improvement (21.3% to 83.8%) and the bug fix for SetupHystrixPrometheus panic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/test-coverage-and-sync-once

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

This PR improves reliability and test confidence in the core package by making Hystrix Prometheus setup idempotent and adding a broad, coverage-oriented test suite, along with regenerated gomarkdoc READMEs.

Changes:

  • Prevent SetupHystrixPrometheus from panicking on duplicate registration by guarding it with sync.Once.
  • Add core_coverage_test.go covering server lifecycle, HTTP routing, initializers, VTProto codec, and utility helpers to substantially increase coverage.
  • Regenerate README documentation via gomarkdoc (including updated API reference line links and descriptions).

Reviewed changes

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

File Description
README.md Regenerated API docs and updated SetupHystrixPrometheus description to mention sync.Once.
initializers.go Wrap Hystrix Prometheus collector setup in sync.Once to avoid duplicate-registration panics.
core_coverage_test.go New comprehensive test suite exercising many previously uncovered branches and behaviors.
config/README.md Updates quick-start docs line describing health check endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core_coverage_test.go
Comment thread config/README.md
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core_coverage_test.go
Comment thread initializers.go
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core_coverage_test.go Outdated
Comment thread core_coverage_test.go Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

41-41: ⚠️ Potential issue | 🟠 Major

Don't advertise probe endpoints that core doesn't register.

The core HTTP handler only wires swagger, pprof, and metrics; /healthcheck and /readycheck are not added by core. Publishing these paths in the generated README(s) will send users toward failing liveness/readiness probes, so please either add the routes or update the gomarkdoc source to match the actual surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 41, The README advertises /healthcheck and /readycheck but
the core HTTP handler only registers swagger, pprof and metrics; either register
the probe endpoints or remove them from the generated docs. Fix by updating the
core HTTP handler to add health and ready routes (the function that wires HTTP
routes where swagger, pprof and metrics are registered) or modify the gomarkdoc
generation configuration / README template to stop listing /healthcheck and
/readycheck so docs match the actual surface.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core_coverage_test.go`:
- Around line 764-772: The fixed time.Sleep should be replaced with explicit
synchronization so Stop() doesn't race reading c.grpcServer/c.httpServer; update
the service lifecycle to signal when Run() has finished assigning servers (for
example add/close a channel like svc.started or use a sync.WaitGroup) and have
the test wait on that channel instead of sleeping after waiting on svc.ready;
modify the Run() implementation to close svc.started (or call wg.Done()) after
it sets c.grpcServer and c.httpServer, and change the test to wait for that
signal before calling Stop().
- Around line 362-367: The test TestSetupHystrixPrometheus_CalledTwice is
ineffective because prior tests call processConfig(), which already invokes
SetupHystrixPrometheus() and causes hystrixOnce to be set; update the test to
either reset the hystrixOnce/global registration state before calling
SetupHystrixPrometheus twice or execute the two-call assertion in a fresh
subprocess; specifically locate the SetupHystrixPrometheus and hystrixOnce
symbols and either reinitialize hystrixOnce (or the related registration
globals) at the start of TestSetupHystrixPrometheus_CalledTwice or change the
test to spawn a new process that calls SetupHystrixPrometheus twice to ensure
the registration path is exercised.

---

Outside diff comments:
In `@README.md`:
- Line 41: The README advertises /healthcheck and /readycheck but the core HTTP
handler only registers swagger, pprof and metrics; either register the probe
endpoints or remove them from the generated docs. Fix by updating the core HTTP
handler to add health and ready routes (the function that wires HTTP routes
where swagger, pprof and metrics are registered) or modify the gomarkdoc
generation configuration / README template to stop listing /healthcheck and
/readycheck so docs match the actual surface.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f71fa99e-b0e5-42d9-8f97-8c79fde50d7e

📥 Commits

Reviewing files that changed from the base of the PR and between 1c4f62c and 8f444b8.

📒 Files selected for processing (4)
  • README.md
  • config/README.md
  • core_coverage_test.go
  • initializers.go

Comment thread core_coverage_test.go
Comment thread core_coverage_test.go
@ankurs ankurs merged commit b1cdf33 into main Mar 24, 2026
8 checks passed
@ankurs ankurs deleted the feat/test-coverage-and-sync-once branch March 24, 2026 04:08
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.

2 participants