Skip to content

feat: export BaseMetrics for forward-compatible custom implementations#2

Merged
ankurs merged 2 commits intomainfrom
feat/base-metrics
Apr 5, 2026
Merged

feat: export BaseMetrics for forward-compatible custom implementations#2
ankurs merged 2 commits intomainfrom
feat/base-metrics

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 5, 2026

Summary

  • Export BaseMetrics struct with no-op implementations of all Metrics methods
  • Custom implementations embed BaseMetrics so new methods added to the interface get safe no-op defaults instead of breaking builds
  • Remove redundant NoopMetrics var — use &BaseMetrics{} directly
  • Default when no WithMetrics is passed is &BaseMetrics{} (zero overhead)
type myMetrics struct {
    workers.BaseMetrics // forward-compatible
    client *statsd.Client
}

func (m *myMetrics) WorkerStarted(name string) {
    m.client.Incr("worker.started", []string{"worker:" + name}, 1)
}
// All other methods default to no-op via BaseMetrics

Test plan

  • go test -race ./... passes
  • make lint — 0 issues

Replace unexported noopMetrics with exported BaseMetrics. Custom
Metrics implementations embed BaseMetrics so that new methods added
to the interface get safe no-op defaults. Remove redundant NoopMetrics
var — use &BaseMetrics{} directly.
Copilot AI review requested due to automatic review settings April 5, 2026 15:29
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Warning

Rate limit exceeded

@ankurs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 46 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 1 minutes and 46 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b4e1cf8-24f9-465a-b681-156d899caa7e

📥 Commits

Reviewing files that changed from the base of the PR and between efe3938 and 4b76a30.

📒 Files selected for processing (4)
  • README.md
  • metrics.go
  • run.go
  • worker.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/base-metrics

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

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 introduces an exported BaseMetrics no-op implementation intended to be embedded by custom Metrics implementations, and updates defaults to use BaseMetrics instead of NoopMetrics.

Changes:

  • Add exported BaseMetrics with no-op implementations for all Metrics methods.
  • Switch default metrics behavior in Run/worker context resolution from NoopMetrics to &BaseMetrics{}.
  • Update README/docs to document BaseMetrics and remove NoopMetrics references.

Reviewed changes

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

File Description
worker.go Default nil metrics to &BaseMetrics{} in worker context creation.
run.go Default metrics in config and resolution now use &BaseMetrics{}; docs updated accordingly.
metrics.go Replaces NoopMetrics/noopMetrics with exported BaseMetrics type and no-op methods.
README.md Adds BaseMetrics docs and updates references from NoopMetrics to BaseMetrics.
Comments suppressed due to low confidence (1)

run.go:27

  • WithMetrics currently accepts nil and will set c.metrics to nil, which can lead to nil-interface panics in code paths that call metrics methods (e.g., the suture EventHook). Consider treating a nil argument as “disable metrics” by defaulting to BaseMetrics (or rejecting nil).
// WithMetrics sets the metrics implementation for all workers started by Run.
// Workers inherit this unless they override via Worker.WithMetrics.
// If not set, &BaseMetrics{} is used.
func WithMetrics(m Metrics) RunOption {
	return func(c *runConfig) {
		c.metrics = m
	}

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

@ankurs ankurs merged commit 0c62e84 into main Apr 5, 2026
4 checks passed
@ankurs ankurs deleted the feat/base-metrics branch April 5, 2026 15:45
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