Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #22 from puppetlabs/tasks/add-noop-instrumentation…
Browse files Browse the repository at this point in the history
…-delegate

Update: Add noop metrics delegate for testing
  • Loading branch information
kyleterry authored Feb 10, 2020
2 parents 0f0780e + 28e8bb7 commit 9b00391
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions instrumentation/metrics/delegates/delegates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/puppetlabs/horsehead/v2/instrumentation/metrics/collectors"
"github.com/puppetlabs/horsehead/v2/instrumentation/metrics/internal/noop"
"github.com/puppetlabs/horsehead/v2/instrumentation/metrics/internal/prometheus"
)

Expand All @@ -22,13 +23,16 @@ type DelegateType string
const (
// PrometheusDelegate is a const that represents the prometheus backend
PrometheusDelegate DelegateType = "prometheus"
NoopDelegate DelegateType = "noop"
)

// New looks up t and returns a new Delegate matching that type
func New(namespace string, t DelegateType) (Delegate, error) {
switch t {
case PrometheusDelegate:
return prometheus.New(namespace), nil
case NoopDelegate:
return noop.New(), nil
}

return nil, errors.New("no delegate found")
Expand Down
29 changes: 29 additions & 0 deletions instrumentation/metrics/internal/noop/noop.go
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{}
}

0 comments on commit 9b00391

Please sign in to comment.