Skip to content

Commit

Permalink
[supervisor] add ssh tunnel metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Sep 25, 2023
1 parent f690f87 commit f18f7ca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
10 changes: 10 additions & 0 deletions components/supervisor/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
type SupervisorMetrics struct {
IDEReadyDurationTotal *prometheus.HistogramVec
InitializerHistogram *prometheus.HistogramVec
SSHTunnelOpenedTotal *prometheus.CounterVec
SSHTunnelClosedTotal *prometheus.CounterVec
}

func NewMetrics() *SupervisorMetrics {
Expand All @@ -27,6 +29,14 @@ func NewMetrics() *SupervisorMetrics {
Help: "initializer speed in bytes per second",
Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12),
}, []string{"kind"}),
SSHTunnelOpenedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "supervisor_ssh_tunnel_opened_total",
Help: "Total number of SSH tunnels opened by the supervisor",
}, []string{}),
SSHTunnelClosedTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "supervisor_ssh_tunnel_closed_total",
Help: "Total number of SSH tunnels closed by the supervisor",
}, []string{"code"}),
}
}

Expand Down
2 changes: 2 additions & 0 deletions components/supervisor/pkg/metrics/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func NewGrpcMetricsReporter(gitpodHost string) *GrpcMetricsReporter {
"supervisor_initializer_bytes_second": true,
"supervisor_client_handled_total": true,
"supervisor_client_handling_seconds": true,
"supervisor_ssh_tunnel_opened_total": true,
"supervisor_ssh_tunnel_closed_total": true,
},
values: make(map[string]float64),
addCounter: func(name string, labels map[string]string, value uint64) {
Expand Down
14 changes: 12 additions & 2 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func Run(options ...RunOption) {
}

wg.Add(1)
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, apiEndpointOpts...)
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, supervisorMetrics, apiEndpointOpts...)

wg.Add(1)
go startSSHServer(ctx, cfg, &wg)
Expand Down Expand Up @@ -1187,7 +1187,7 @@ func isBlacklistedEnvvar(name string) bool {
return false
}

func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, services []RegisterableService, tunneled *ports.TunneledPortsService, metricsReporter *metrics.GrpcMetricsReporter, opts ...grpc.ServerOption) {
func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, services []RegisterableService, tunneled *ports.TunneledPortsService, metricsReporter *metrics.GrpcMetricsReporter, supervisorMetrics *metrics.SupervisorMetrics, opts ...grpc.ServerOption) {
defer wg.Done()
defer log.Debug("startAPIEndpoint shutdown")

Expand Down Expand Up @@ -1308,6 +1308,16 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
tunnelOverWebSocket(tunneled, conn)
}))
routes.Handle("/_supervisor/tunnel/ssh", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
supervisorMetrics.SSHTunnelOpenedTotal.WithLabelValues().Inc()
defer func() {
code := "unknown"
if err != nil {
if e, ok := err.(*websocket.CloseError); ok {
code = strconv.Itoa(e.Code)
}
}
supervisorMetrics.SSHTunnelClosedTotal.WithLabelValues(code).Inc()
}()
wsConn, err := upgrader.Upgrade(rw, r, nil)
if err != nil {
log.WithError(err).Error("tunnel ssh: upgrade to the WebSocket protocol failed")
Expand Down
16 changes: 16 additions & 0 deletions install/installer/pkg/components/ide-metrics/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
},
},
},
{
Name: "supervisor_ssh_tunnel_opened_total",
Help: "Total number of SSH tunnels opened by the supervisor",
Labels: []config.LabelAllowList{},
},
{
Name: "supervisor_ssh_tunnel_closed_total",
Help: "Total number of SSH tunnels closed by the supervisor",
Labels: []config.LabelAllowList{
{
Name: "code",
AllowValues: []string{"*"},
DefaultValue: "unknown",
},
},
},
}

histogramMetrics := []config.HistogramMetricsConfiguration{
Expand Down

0 comments on commit f18f7ca

Please sign in to comment.