Skip to content

Commit 6da3df8

Browse files
Furistoroboquat
authored andcommitted
[ws-daemon] Provide initializer metrics for object storage
1 parent 7653505 commit 6da3df8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
type metrics struct {
4545
BackupWaitingTimeHist prometheus.Histogram
4646
BackupWaitingTimeoutCounter prometheus.Counter
47+
InitializerHistogram prometheus.HistogramVec
4748
}
4849

4950
// WorkspaceService implements the InitService and WorkspaceService
@@ -108,6 +109,17 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
108109
return nil, xerrors.Errorf("cannot register Prometheus counter for backup waiting timeouts: %w", err)
109110
}
110111

112+
initializerHistogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{
113+
Name: "initializer_bytes_second",
114+
Help: "initializer speed in bytes per second",
115+
Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 15),
116+
}, []string{"kind"})
117+
118+
err = reg.Register(initializerHistogram)
119+
if err != nil {
120+
return nil, xerrors.Errorf("cannot register Prometheus counter for initializer speed per second: %w", err)
121+
}
122+
111123
return &WorkspaceService{
112124
config: cfg,
113125
store: store,
@@ -118,6 +130,7 @@ func NewWorkspaceService(ctx context.Context, cfg Config, kubernetesNamespace st
118130
metrics: &metrics{
119131
BackupWaitingTimeHist: waitingTimeHist,
120132
BackupWaitingTimeoutCounter: waitingTimeoutCounter,
133+
InitializerHistogram: *initializerHistogram,
121134
},
122135
// we permit five concurrent backups at any given time, hence the five in the channel
123136
backupWorkspaceLimiter: make(chan struct{}, 5),
@@ -282,6 +295,8 @@ func (s *WorkspaceService) InitWorkspace(ctx context.Context, req *api.InitWorks
282295
log.WithError(err).WithField("workspaceId", req.Id).Error("cannot initialize workspace")
283296
return nil, status.Error(codes.FailedPrecondition, err.Error())
284297
}
298+
299+
s.recordInitializerMetrics(workspace.Location)
285300
}
286301

287302
if req.PersistentVolumeClaim {
@@ -310,6 +325,27 @@ func (s *WorkspaceService) InitWorkspace(ctx context.Context, req *api.InitWorks
310325
return &api.InitWorkspaceResponse{}, nil
311326
}
312327

328+
func (s *WorkspaceService) recordInitializerMetrics(path string) {
329+
readyFile := filepath.Join(path, wsinit.WorkspaceReadyFile)
330+
331+
content, err := os.ReadFile(readyFile)
332+
if err != nil {
333+
log.WithError(err).Errorf("could not find ready file at %v", readyFile)
334+
return
335+
}
336+
337+
var ready csapi.WorkspaceReadyMessage
338+
err = json.Unmarshal(content, &ready)
339+
if err != nil {
340+
log.WithError(err).Error("could not unmarshal ready")
341+
return
342+
}
343+
344+
for _, m := range ready.Metrics {
345+
s.metrics.InitializerHistogram.WithLabelValues(m.Type).Observe(float64(m.Size) / m.Duration.Seconds())
346+
}
347+
}
348+
313349
func (s *WorkspaceService) creator(req *api.InitWorkspaceRequest) session.WorkspaceFactory {
314350
var checkoutLocation string
315351
allLocations := csapi.GetCheckoutLocationsFromInitializer(req.Initializer)

0 commit comments

Comments
 (0)