wrapper: prometheus attach labels to all metrics
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
6aff955f07
commit
d927ad4673
@ -37,7 +37,6 @@ func NewHandlerWrapper(opts ...server.Option) server.HandlerWrapper {
|
||||
prometheus.CounterOpts{
|
||||
Name: fmt.Sprintf("%s_request_total", defaultMetricPrefix),
|
||||
Help: "How many go-micro requests processed, partitioned by method and status",
|
||||
ConstLabels: md,
|
||||
},
|
||||
[]string{"method", "status"},
|
||||
)
|
||||
@ -46,7 +45,6 @@ func NewHandlerWrapper(opts ...server.Option) server.HandlerWrapper {
|
||||
prometheus.SummaryOpts{
|
||||
Name: fmt.Sprintf("%s_upstream_latency_microseconds", defaultMetricPrefix),
|
||||
Help: "Service backend method request latencies in microseconds",
|
||||
ConstLabels: md,
|
||||
},
|
||||
[]string{"method"},
|
||||
)
|
||||
@ -55,14 +53,22 @@ func NewHandlerWrapper(opts ...server.Option) server.HandlerWrapper {
|
||||
prometheus.HistogramOpts{
|
||||
Name: fmt.Sprintf("%s_request_duration_seconds", defaultMetricPrefix),
|
||||
Help: "Service method request time in seconds",
|
||||
ConstLabels: md,
|
||||
},
|
||||
[]string{"method"},
|
||||
)
|
||||
|
||||
prometheus.MustRegister(opsCounter)
|
||||
prometheus.MustRegister(timeCounterSummary)
|
||||
prometheus.MustRegister(timeCounterHistogram)
|
||||
reg := prometheus.NewRegistry()
|
||||
wrapreg := prometheus.WrapRegistererWith(md, reg)
|
||||
wrapreg.MustRegister(
|
||||
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
|
||||
prometheus.NewGoCollector(),
|
||||
opsCounter,
|
||||
timeCounterSummary,
|
||||
timeCounterHistogram,
|
||||
)
|
||||
|
||||
prometheus.DefaultGatherer = reg
|
||||
prometheus.DefaultRegisterer = wrapreg
|
||||
|
||||
return func(fn server.HandlerFunc) server.HandlerFunc {
|
||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||
|
@ -87,6 +87,10 @@ func TestPrometheusMetrics(t *testing.T) {
|
||||
|
||||
metric := findMetricByName(list, dto.MetricType_SUMMARY, "micro_upstream_latency_microseconds")
|
||||
|
||||
if metric == nil || metric.Metric == nil || len(metric.Metric) == 0 {
|
||||
t.Fatalf("no metrics returned")
|
||||
}
|
||||
|
||||
for _, v := range metric.Metric[0].Label {
|
||||
switch *v.Name {
|
||||
case "micro_dc":
|
||||
|
Loading…
Reference in New Issue
Block a user