This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Add noop metrics delegate for testing
This commit adds a noop delegate to instrumentation/metrics that will just do nothing. It will not register metrics or record them. This is used for testing packages that use Horsehead for instrumenetation. Prometheus registers everything in a global registry at the moment, so errors can arise in the lifecycle of tests related to metrics already having been registered. This can create issues when inspecting the call stack and output logs of tests.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package noop | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/puppetlabs/horsehead/v2/instrumentation/metrics/collectors" | ||
) | ||
|
||
type Noop struct{} | ||
|
||
func (n *Noop) NewCounter(name string, opts collectors.CounterOptions) (collectors.Counter, error) { | ||
return &Counter{}, nil | ||
} | ||
|
||
func (n *Noop) NewTimer(name string, opts collectors.TimerOptions) (collectors.Timer, error) { | ||
return &Timer{}, nil | ||
} | ||
|
||
func (n *Noop) NewDurationMiddleware(name string, opts collectors.DurationMiddlewareOptions) (collectors.DurationMiddleware, error) { | ||
return &DurationMiddleware{}, nil | ||
} | ||
|
||
func (n *Noop) NewHandler() http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}) | ||
} | ||
|
||
func New() *Noop { | ||
return &Noop{} | ||
} |