Skip to content

Commit 4aae78d

Browse files
Add metrics on proxy service created (#144)
* Add metrics on proxy service created * Fix lint
1 parent 62369b4 commit 4aae78d

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

metrics/prometheus_defs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ var (
2929

3030
// /proxy/proxy.go
3131

32-
GRPCServerMetrics = GetStandardGRPCInterceptor("direction")
33-
ProxyStartCount = DefaultCounter("proxy_start_count", "Emitted once per startup")
32+
GRPCServerMetrics = GetStandardGRPCInterceptor("direction")
33+
ProxyStartCount = DefaultCounter("proxy_start_count", "Emitted once on Go process start")
34+
ProxyServiceCreated = DefaultCounterVec("proxy_service_created", "Emitted once per service start", "direction")
35+
ProxyServiceStopped = DefaultCounterVec("proxy_service_stopped", "Emitted on service shutdown", "direction")
36+
ProxyServiceRestarted = DefaultCounterVec("proxy_service_restarted", "Emitted on service shutdown", "direction")
3437

3538
// /transport/grpc.go
3639
// Gratuitous hack: Until https://github.com/grpc-ecosystem/go-grpc-middleware/issues/783 is addressed,
@@ -84,6 +87,9 @@ func init() {
8487

8588
prometheus.MustRegister(GRPCServerMetrics)
8689
prometheus.MustRegister(ProxyStartCount)
90+
prometheus.MustRegister(ProxyServiceCreated)
91+
prometheus.MustRegister(ProxyServiceStopped)
92+
prometheus.MustRegister(ProxyServiceRestarted)
8793

8894
prometheus.MustRegister(GRPCOutboundClientMetrics)
8995
prometheus.MustRegister(GRPCInboundClientMetrics)

proxy/proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type (
2929
logger log.Logger
3030
server *TemporalAPIServer
3131
transManager *transport.TransportManager
32+
metricLabels prometheus.Labels
3233
shutDownCh chan struct{}
3334
}
3435

@@ -184,10 +185,11 @@ func (ps *ProxyServer) start() error {
184185

185186
go func() {
186187
for {
188+
metrics.ProxyServiceCreated.With(ps.metricLabels).Inc()
187189
// If using mux transport underneath, Open call will be blocked until
188190
// underlying connection is established.
189191
// Also note: GRPC requires the client interceptors (like metrics) to be defined on the transport, not on the client.
190-
clientTransport, err := ps.transManager.OpenClient(prometheus.Labels{"direction": ps.opts.directionLabel()}, clientConfig)
192+
clientTransport, err := ps.transManager.OpenClient(clientConfig)
191193
if err != nil {
192194
ps.logger.Error("Open client transport is failed", tag.Error(err))
193195
return
@@ -215,10 +217,12 @@ func (ps *ProxyServer) start() error {
215217

216218
select {
217219
case <-ps.shutDownCh:
220+
metrics.ProxyServiceStopped.With(ps.metricLabels).Inc()
218221
ps.stopServer()
219222
return
220223
case <-retryCh:
221224
// If any closable transport is closed, try to restart the proxy server.
225+
metrics.ProxyServiceRestarted.With(ps.metricLabels).Inc()
222226
ps.stopServer()
223227
}
224228
}
@@ -243,6 +247,7 @@ func newProxyServer(
243247
opts: opts,
244248
transManager: transManager,
245249
logger: logger,
250+
metricLabels: prometheus.Labels{"direction": opts.directionLabel()},
246251
shutDownCh: make(chan struct{}),
247252
}
248253
}

proxy/test/echo_server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/gogo/status"
9-
"github.com/prometheus/client_golang/prometheus"
109
"go.temporal.io/api/workflowservice/v1"
1110
"go.temporal.io/server/api/adminservice/v1"
1211
replicationpb "go.temporal.io/server/api/replication/v1"
@@ -149,7 +148,7 @@ func newEchoServer(
149148
logger.Fatal("Failed to create server transport", tag.Error(err))
150149
}
151150

152-
clientTransport, err := tm.OpenClient(prometheus.Labels{}, clientConfig)
151+
clientTransport, err := tm.OpenClient(clientConfig)
153152
if err != nil {
154153
logger.Fatal("Failed to create client transport", tag.Error(err))
155154
}

transport/transport.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
7-
prometheus "github.com/prometheus/client_golang/prometheus"
87
"go.temporal.io/server/common/log"
98
"google.golang.org/grpc"
109

@@ -66,7 +65,7 @@ func (tm *TransportManager) IsMuxActive(name string) bool {
6665
return tm.muxConnManagers[name].status.Load() == int32(statusStarted)
6766
}
6867

69-
func (tm *TransportManager) OpenClient(metricLabels prometheus.Labels, clientConfig config.ProxyClientConfig) (ClientTransport, error) {
68+
func (tm *TransportManager) OpenClient(clientConfig config.ProxyClientConfig) (ClientTransport, error) {
7069
if clientConfig.Type == config.MuxTransport {
7170
return tm.openMuxTransport(clientConfig.MuxTransportName)
7271
}

0 commit comments

Comments
 (0)