From a879144417ca8fcfb443707fe1b3abc09147e129 Mon Sep 17 00:00:00 2001 From: Prabhsimran Singh Date: Wed, 5 Jul 2023 16:09:24 +0530 Subject: [PATCH] fix: grpc_server_started_total metric not reporting custom labels --- server_reporter.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server_reporter.go b/server_reporter.go index d44adc0..dbae3c0 100644 --- a/server_reporter.go +++ b/server_reporter.go @@ -17,22 +17,27 @@ type serverReporter struct { startTime time.Time clientUuid string flowUuid string + first bool } func newServerReporter(m *ServerMetrics, rpcType grpcType, fullMethod string) *serverReporter { r := &serverReporter{ metrics: m, rpcType: rpcType, + first: true, } if r.metrics.serverHandledHistogramEnabled { r.startTime = time.Now() } r.serviceName, r.methodName = splitMethodName(fullMethod) - r.metrics.serverStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, r.clientUuid, r.flowUuid).Inc() return r } func (r *serverReporter) ReceivedMessage() { + if r.first { + r.metrics.serverStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, r.clientUuid, r.flowUuid).Inc() + r.first = false + } r.metrics.serverStreamMsgReceived.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, r.clientUuid, r.flowUuid).Inc() if r.metrics.serverHandledHistogramEnabled { r.startTime = time.Now()