From 8013cb933e9eb307c4c1bee462252f3a59b5a52b Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 15 Oct 2023 13:56:01 +0200 Subject: [PATCH] Fix metrics --- network/client.go | 2 ++ network/server_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/network/client.go b/network/client.go index c71e2f38..27c119a4 100644 --- a/network/client.go +++ b/network/client.go @@ -236,6 +236,8 @@ func (c *Client) Reconnect() error { if c.conn != nil { c.Close() + } else { + metrics.ServerConnections.Dec() } c.connected.Store(false) diff --git a/network/server_test.go b/network/server_test.go index 4dbb7d24..9b0643c2 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -16,6 +16,7 @@ import ( "github.com/gatewayd-io/gatewayd/logging" "github.com/gatewayd-io/gatewayd/plugin" "github.com/gatewayd-io/gatewayd/pool" + "github.com/prometheus/client_golang/prometheus" "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "google.golang.org/grpc" @@ -25,6 +26,9 @@ import ( func TestRunServer(t *testing.T) { errs := make(chan error) + // Reset prometheus metrics. + prometheus.DefaultRegisterer = prometheus.NewRegistry() + logger := logging.NewLogger(context.Background(), logging.LoggerConfig{ Output: []config.LogOutput{ config.File,