Metrics interface and Prometheus implementation (#1929)

* Metrics interface

* Prometheus implementation

* NoOp implementation

Co-authored-by: chris <chris@Profanity.local>
This commit is contained in:
Prawn
2020-08-18 19:27:50 +12:00
committed by GitHub
parent e1248f90f4
commit da4159513e
14 changed files with 577 additions and 1 deletions

37
metrics/noop/reporter.go Normal file
View File

@@ -0,0 +1,37 @@
package noop
import (
"time"
log "github.com/micro/go-micro/v3/logger"
"github.com/micro/go-micro/v3/metrics"
)
// Reporter is an implementation of metrics.Reporter:
type Reporter struct {
options metrics.Options
}
// New returns a configured noop reporter:
func New(opts ...metrics.Option) *Reporter {
log.Info("Metrics/NoOp - not doing anything")
return &Reporter{
options: metrics.NewOptions(opts...),
}
}
// Count implements the metrics.Reporter interface Count method:
func (r *Reporter) Count(metricName string, value int64, tags metrics.Tags) error {
return nil
}
// Gauge implements the metrics.Reporter interface Gauge method:
func (r *Reporter) Gauge(metricName string, value float64, tags metrics.Tags) error {
return nil
}
// Timing implements the metrics.Reporter interface Timing method:
func (r *Reporter) Timing(metricName string, value time.Duration, tags metrics.Tags) error {
return nil
}

View File

@@ -0,0 +1,20 @@
package noop
import (
"testing"
"github.com/micro/go-micro/v3/metrics"
"github.com/stretchr/testify/assert"
)
func TestNoopReporter(t *testing.T) {
// Make a Reporter:
reporter := New(metrics.Path("/noop"))
assert.NotNil(t, reporter)
assert.Equal(t, "/noop", reporter.options.Path)
// Check that our implementation is valid:
assert.Implements(t, new(metrics.Reporter), reporter)
}