wrapper/monitoring/prometheus: use default registry (#532)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
16b5bac080
commit
53940dda18
@ -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 {
|
||||||
|
@ -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),
|
||||||
|
Loading…
Reference in New Issue
Block a user