Skip to content

Commit fdcf039

Browse files
Furistoroboquat
authored andcommitted
[supervisor] Provide initializer metrics for PVC
1 parent 6da3df8 commit fdcf039

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

components/supervisor/pkg/metrics/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
type SupervisorMetrics struct {
1414
IDEReadyDurationTotal *prometheus.HistogramVec
15+
InitializerHistogram *prometheus.HistogramVec
1516
}
1617

1718
func NewMetrics() *SupervisorMetrics {
@@ -21,12 +22,18 @@ func NewMetrics() *SupervisorMetrics {
2122
Help: "the IDE startup time",
2223
Buckets: []float64{0.1, 0.5, 1, 1.5, 2, 2.5, 5, 10},
2324
}, []string{"kind"}),
25+
InitializerHistogram: prometheus.NewHistogramVec(prometheus.HistogramOpts{
26+
Name: "supervisor_initializer_bytes_second",
27+
Help: "initializer speed in bytes per second",
28+
Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12),
29+
}, []string{"kind"}),
2430
}
2531
}
2632

2733
func (m *SupervisorMetrics) Register(registry *prometheus.Registry) error {
2834
metrics := []prometheus.Collector{
2935
m.IDEReadyDurationTotal,
36+
m.InitializerHistogram,
3037
}
3138

3239
for _, metric := range metrics {

components/supervisor/pkg/metrics/reporter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func NewGrpcMetricsReporter(gitpodHost string) *GrpcMetricsReporter {
4040
"grpc_server_started_total": true,
4141
"grpc_server_handling_seconds": true,
4242
"supervisor_ide_ready_duration_total": true,
43+
"initializer_bytes_second": true,
4344
},
4445
values: make(map[string]float64),
4546
addCounter: func(name string, labels map[string]string, value uint64) {

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func Run(options ...RunOption) {
330330
shutdown = make(chan ShutdownReason, 1)
331331
)
332332
wg.Add(1)
333-
go startContentInit(ctx, cfg, &wg, cstate)
333+
go startContentInit(ctx, cfg, &wg, cstate, supervisorMetrics)
334334
wg.Add(1)
335335
go startAPIEndpoint(ctx, cfg, &wg, apiServices, tunneledPortsService, metricsReporter, apiEndpointOpts...)
336336
wg.Add(1)
@@ -1354,7 +1354,7 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP
13541354
}()
13551355
}
13561356

1357-
func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst ContentState) {
1357+
func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst ContentState, metrics *metrics.SupervisorMetrics) {
13581358
defer wg.Done()
13591359
defer log.Info("supervisor: workspace content available")
13601360

@@ -1434,6 +1434,8 @@ func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst
14341434
return
14351435
}
14361436

1437+
recordInitializerMetrics("/workspace", metrics)
1438+
14371439
err = os.Remove(fn)
14381440
if os.IsNotExist(err) {
14391441
// file is gone - we're good
@@ -1448,6 +1450,27 @@ func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst
14481450
cst.MarkContentReady(src)
14491451
}
14501452

1453+
func recordInitializerMetrics(path string, metrics *metrics.SupervisorMetrics) {
1454+
readyFile := filepath.Join(path, ".gitpod/ready")
1455+
1456+
content, err := os.ReadFile(readyFile)
1457+
if err != nil {
1458+
log.WithError(err).Errorf("could not find ready file at %v", readyFile)
1459+
return
1460+
}
1461+
1462+
var ready csapi.WorkspaceReadyMessage
1463+
err = json.Unmarshal(content, &ready)
1464+
if err != nil {
1465+
log.WithError(err).Error("could not unmarshal ready")
1466+
return
1467+
}
1468+
1469+
for _, m := range ready.Metrics {
1470+
metrics.InitializerHistogram.WithLabelValues(m.Type).Observe(float64(m.Size) / m.Duration.Seconds())
1471+
}
1472+
}
1473+
14511474
func socketActivationForDocker(ctx context.Context, wg *sync.WaitGroup, term *terminal.Mux) {
14521475
defer wg.Done()
14531476

0 commit comments

Comments
 (0)