@@ -39,6 +39,11 @@ import (
39
39
"github.com/gitpod-io/gitpod/ws-daemon/pkg/quota"
40
40
)
41
41
42
+ // Metrics combine custom metrics exported by WorkspaceService
43
+ type metrics struct {
44
+ BackupWaitingTimeHist prometheus.Histogram
45
+ }
46
+
42
47
// WorkspaceService implements the InitService and WorkspaceService
43
48
type WorkspaceService struct {
44
49
config Config
@@ -48,6 +53,8 @@ type WorkspaceService struct {
48
53
stopService context.CancelFunc
49
54
runtime container.Runtime
50
55
56
+ metrics * metrics
57
+
51
58
api.UnimplementedInWorkspaceServiceServer
52
59
api.UnimplementedWorkspaceContentServiceServer
53
60
}
@@ -80,7 +87,13 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
80
87
ctx , stopService := context .WithCancel (ctx )
81
88
82
89
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
+
84
97
}
85
98
86
99
return & WorkspaceService {
@@ -89,6 +102,8 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
89
102
ctx : ctx ,
90
103
stopService : stopService ,
91
104
runtime : runtime ,
105
+
106
+ metrics : & metrics {waitingTimeHist },
92
107
}, nil
93
108
}
94
109
@@ -113,6 +128,21 @@ func registerWorkingAreaDiskspaceGauge(workingArea string, reg prometheus.Regist
113
128
}))
114
129
}
115
130
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
+
116
146
// Start starts this workspace service and returns when the service gets stopped.
117
147
// This function is intended to run as Go routine.
118
148
func (s * WorkspaceService ) Start () {
@@ -414,7 +444,9 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
414
444
// Avoid too many simultaneous backups in order to avoid excessive memory utilization.
415
445
waitStart := time .Now ()
416
446
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
+
418
450
defer func () {
419
451
<- backupWorkspaceLimiter
420
452
}()
0 commit comments