Skip to content

Commit afdf961

Browse files
aledbfroboquat
authored andcommitted
[ws-daemon] Use a metric for backup waiting time instead logs
1 parent 9202ddd commit afdf961

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

components/ws-daemon/pkg/content/service.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ import (
3939
"github.com/gitpod-io/gitpod/ws-daemon/pkg/quota"
4040
)
4141

42+
// Metrics combine custom metrics exported by WorkspaceService
43+
type metrics struct {
44+
BackupWaitingTimeHist prometheus.Histogram
45+
}
46+
4247
// WorkspaceService implements the InitService and WorkspaceService
4348
type WorkspaceService struct {
4449
config Config
@@ -48,6 +53,8 @@ type WorkspaceService struct {
4853
stopService context.CancelFunc
4954
runtime container.Runtime
5055

56+
metrics *metrics
57+
5158
api.UnimplementedInWorkspaceServiceServer
5259
api.UnimplementedWorkspaceContentServiceServer
5360
}
@@ -80,7 +87,13 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
8087
ctx, stopService := context.WithCancel(ctx)
8188

8289
if err := registerWorkingAreaDiskspaceGauge(cfg.WorkingArea, reg); err != nil {
83-
log.WithError(err).Warn("cannot register Prometheus gauge for working area diskspace")
90+
return nil, xerrors.Errorf("cannot register Prometheus gauge for working area diskspace: %w", err)
91+
}
92+
93+
waitingTimeHist, err := registerConcurrentBackupWaitingTime(reg)
94+
if err != nil {
95+
return nil, xerrors.Errorf("cannot register Prometheus gauge for babkup waiting time: %w", err)
96+
8497
}
8598

8699
return &WorkspaceService{
@@ -89,6 +102,8 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
89102
ctx: ctx,
90103
stopService: stopService,
91104
runtime: runtime,
105+
106+
metrics: &metrics{waitingTimeHist},
92107
}, nil
93108
}
94109

@@ -113,6 +128,21 @@ func registerWorkingAreaDiskspaceGauge(workingArea string, reg prometheus.Regist
113128
}))
114129
}
115130

131+
func registerConcurrentBackupWaitingTime(reg prometheus.Registerer) (prometheus.Histogram, error) {
132+
backupWaitingTime := prometheus.NewHistogram(prometheus.HistogramOpts{
133+
Name: "concurrent_backup_waiting_seconds",
134+
Help: "waiting time for concurrent backups to finish",
135+
Buckets: []float64{5, 10, 30, 60, 120, 180, 300, 600, 1800},
136+
})
137+
138+
err := reg.Register(backupWaitingTime)
139+
if err != nil {
140+
return nil, err
141+
}
142+
143+
return backupWaitingTime, nil
144+
}
145+
116146
// Start starts this workspace service and returns when the service gets stopped.
117147
// This function is intended to run as Go routine.
118148
func (s *WorkspaceService) Start() {
@@ -414,7 +444,9 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
414444
// Avoid too many simultaneous backups in order to avoid excessive memory utilization.
415445
waitStart := time.Now()
416446
backupWorkspaceLimiter <- true
417-
log.WithField("workspace", sess.WorkspaceID).Infof("waiting time for concurrent backups to finish was %v", time.Since(waitStart).String())
447+
448+
s.metrics.BackupWaitingTimeHist.Observe(time.Since(waitStart).Seconds())
449+
418450
defer func() {
419451
<-backupWorkspaceLimiter
420452
}()

0 commit comments

Comments
 (0)