wrapper/monitoring/prometheus: use default registry (#532)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-04-16 01:10:43 +03:00
parent 16b5bac080
commit 53940dda18
2 changed files with 10 additions and 8 deletions

View File

@ -60,17 +60,15 @@ func NewHandlerWrapper(opts ...server.Option) server.HandlerWrapper {
[]string{"method"}, []string{"method"},
) )
reg := prometheus.NewRegistry() wrapreg := prometheus.WrapRegistererWith(md, prometheus.DefaultRegisterer)
wrapreg := prometheus.WrapRegistererWith(md, reg)
wrapreg.MustRegister( wrapreg.MustRegister(
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}), //prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
prometheus.NewGoCollector(), //prometheus.NewGoCollector(),
opsCounter, opsCounter,
timeCounterSummary, timeCounterSummary,
timeCounterHistogram, timeCounterHistogram,
) )
prometheus.DefaultGatherer = reg
prometheus.DefaultRegisterer = wrapreg prometheus.DefaultRegisterer = wrapreg
return func(fn server.HandlerFunc) server.HandlerFunc { return func(fn server.HandlerFunc) server.HandlerFunc {

View File

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/micro/go-micro/v2/broker"
bmemory "github.com/micro/go-micro/v2/broker/memory"
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/client/selector"
"github.com/micro/go-micro/v2/registry/memory" "github.com/micro/go-micro/v2/registry/memory"
@ -34,8 +36,9 @@ func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestRes
func TestPrometheusMetrics(t *testing.T) { func TestPrometheusMetrics(t *testing.T) {
// setup // setup
registry := memory.NewRegistry() reg := memory.NewRegistry()
sel := selector.NewSelector(selector.Registry(registry)) brk := bmemory.NewBroker(broker.Registry(reg))
sel := selector.NewSelector(selector.Registry(reg))
name := "test" name := "test"
id := "id-1234567890" id := "id-1234567890"
@ -50,7 +53,8 @@ func TestPrometheusMetrics(t *testing.T) {
server.Name(name), server.Name(name),
server.Version(version), server.Version(version),
server.Id(id), server.Id(id),
server.Registry(registry), server.Registry(reg),
server.Broker(brk),
server.WrapHandler( server.WrapHandler(
NewHandlerWrapper( NewHandlerWrapper(
server.Metadata(md), server.Metadata(md),