From 93240f040eabfc7da3c9fc16ca616075c72b3a0a Mon Sep 17 00:00:00 2001 From: Ivan Ou Date: Tue, 29 Mar 2022 14:41:00 +0800 Subject: [PATCH] feature: add prometheus lab --- pkg/otelkit/prometheus.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pkg/otelkit/prometheus.go b/pkg/otelkit/prometheus.go index 65e4985..9e28d22 100644 --- a/pkg/otelkit/prometheus.go +++ b/pkg/otelkit/prometheus.go @@ -34,9 +34,9 @@ type PrometheusServiceMeterConfig struct { type PrometheusServiceMeter struct { metric.Meter - server *http.Server - requestCounter syncint64.Counter - requestErrorCounter syncint64.Counter + server *http.Server + requestCounter syncint64.Counter + // TODO responseTimeHistogram syncint64.Histogram } @@ -54,10 +54,8 @@ func (m *PrometheusServiceMeter) UnaryServerInterceptor() func(ctx context.Conte resp, err := handler(ctx, req) - // error count request - if err != nil { - m.requestErrorCounter.Add(ctx, 1, attributes...) - } + // update error request counter when error occurs + // TODO // measure response time responseTime := time.Since(start) @@ -88,10 +86,8 @@ func NewPrometheusServiceMeter(ctx context.Context, conf *PrometheusServiceMeter logger.Fatal("failed to create requests counter", zap.Error(err)) } - requestErrorCounter, err := meter.SyncInt64().Counter("error_request", instrument.WithDescription("count number of error requests")) - if err != nil { - logger.Fatal("failed to create error requests counter", zap.Error(err)) - } + // initiate error request counter + // TODO responseTimeHistogram, err := meter.SyncInt64().Histogram("response_time", instrument.WithDescription("measure response time")) if err != nil { @@ -99,9 +95,9 @@ func NewPrometheusServiceMeter(ctx context.Context, conf *PrometheusServiceMeter } return &PrometheusServiceMeter{ - server: server, - requestCounter: requestCounter, - requestErrorCounter: requestErrorCounter, + server: server, + requestCounter: requestCounter, + // TODO responseTimeHistogram: responseTimeHistogram, } }