From 2b20399a804e5e16d0221480ef5d798fdb7931b4 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Tue, 2 Jun 2026 19:23:45 +0200 Subject: [PATCH] feat(gotenberg): add ConversionsSinceRestart accessor to ProcessSupervisor --- pkg/gotenberg/mocks.go | 19 ++++++++++++------- pkg/gotenberg/supervisor.go | 11 +++++++++++ pkg/gotenberg/supervisor_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/pkg/gotenberg/mocks.go b/pkg/gotenberg/mocks.go index 2b413dd..e0e8c34 100644 --- a/pkg/gotenberg/mocks.go +++ b/pkg/gotenberg/mocks.go @@ -152,13 +152,14 @@ func (p *ProcessMock) Healthy(logger *slog.Logger) bool { // ProcessSupervisorMock is a mock for the [ProcessSupervisor] interface. type ProcessSupervisorMock struct { - LaunchMock func() error - ShutdownMock func() error - HealthyMock func() bool - RunMock func(ctx context.Context, logger *slog.Logger, task func() error) error - ReqQueueSizeMock func() int64 - RestartsCountMock func() int64 - ActiveTasksCountMock func() int64 + LaunchMock func() error + ShutdownMock func() error + HealthyMock func() bool + RunMock func(ctx context.Context, logger *slog.Logger, task func() error) error + ReqQueueSizeMock func() int64 + RestartsCountMock func() int64 + ActiveTasksCountMock func() int64 + ConversionsSinceRestartMock func() int64 } func (s *ProcessSupervisorMock) Launch() error { @@ -189,6 +190,10 @@ func (s *ProcessSupervisorMock) ActiveTasksCount() int64 { return s.ActiveTasksCountMock() } +func (s *ProcessSupervisorMock) ConversionsSinceRestart() int64 { + return s.ConversionsSinceRestartMock() +} + // MetricsProviderMock is a mock for the [MetricsProvider] interface. type MetricsProviderMock struct { MetricsMock func() ([]Metric, error) diff --git a/pkg/gotenberg/supervisor.go b/pkg/gotenberg/supervisor.go index 2c4ba9a..5b5a597 100644 --- a/pkg/gotenberg/supervisor.go +++ b/pkg/gotenberg/supervisor.go @@ -76,6 +76,10 @@ type ProcessSupervisor interface { // ActiveTasksCount returns the current number of active tasks. ActiveTasksCount() int64 + + // ConversionsSinceRestart returns the number of tasks handled since the + // last process (re)start. + ConversionsSinceRestart() int64 } // healthCheckCacheTTL caches successful health probe results so kubelet- @@ -577,6 +581,13 @@ func (s *processSupervisor) ActiveTasksCount() int64 { return s.activeTasks.Load() } +// ConversionsSinceRestart returns the number of tasks handled since the last +// process (re)start. reqCounter is reset to zero on every restart and idle +// shutdown. +func (s *processSupervisor) ConversionsSinceRestart() int64 { + return s.reqCounter.Load() +} + // Interface guards. var ( _ ProcessSupervisor = (*processSupervisor)(nil) diff --git a/pkg/gotenberg/supervisor_test.go b/pkg/gotenberg/supervisor_test.go index f87276c..2081f58 100644 --- a/pkg/gotenberg/supervisor_test.go +++ b/pkg/gotenberg/supervisor_test.go @@ -1091,3 +1091,28 @@ func TestProcessSupervisor_IdleShutdownSkippedWhenActive(t *testing.T) { close(taskDone) } + +func TestProcessSupervisor_ConversionsSinceRestart(t *testing.T) { + process := &ProcessMock{ + StartMock: func(*slog.Logger) error { return nil }, + StopMock: func(*slog.Logger) error { return nil }, + HealthyMock: func(*slog.Logger) bool { return true }, + } + s := NewProcessSupervisor(slog.New(slog.DiscardHandler), process, 0, 0, 1, 0).(*processSupervisor) + + if got := s.ConversionsSinceRestart(); got != 0 { + t.Errorf("expected 0 conversions initially, got %d", got) + } + + s.reqCounter.Store(7) + if got := s.ConversionsSinceRestart(); got != 7 { + t.Errorf("expected 7 conversions, got %d", got) + } + + if err := s.restart(); err != nil { + t.Fatalf("restart: %v", err) + } + if got := s.ConversionsSinceRestart(); got != 0 { + t.Errorf("expected 0 conversions after restart, got %d", got) + } +}