mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
feat(gotenberg): add ConversionsSinceRestart accessor to ProcessSupervisor
This commit is contained in:
@@ -152,13 +152,14 @@ func (p *ProcessMock) Healthy(logger *slog.Logger) bool {
|
|||||||
|
|
||||||
// ProcessSupervisorMock is a mock for the [ProcessSupervisor] interface.
|
// ProcessSupervisorMock is a mock for the [ProcessSupervisor] interface.
|
||||||
type ProcessSupervisorMock struct {
|
type ProcessSupervisorMock struct {
|
||||||
LaunchMock func() error
|
LaunchMock func() error
|
||||||
ShutdownMock func() error
|
ShutdownMock func() error
|
||||||
HealthyMock func() bool
|
HealthyMock func() bool
|
||||||
RunMock func(ctx context.Context, logger *slog.Logger, task func() error) error
|
RunMock func(ctx context.Context, logger *slog.Logger, task func() error) error
|
||||||
ReqQueueSizeMock func() int64
|
ReqQueueSizeMock func() int64
|
||||||
RestartsCountMock func() int64
|
RestartsCountMock func() int64
|
||||||
ActiveTasksCountMock func() int64
|
ActiveTasksCountMock func() int64
|
||||||
|
ConversionsSinceRestartMock func() int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProcessSupervisorMock) Launch() error {
|
func (s *ProcessSupervisorMock) Launch() error {
|
||||||
@@ -189,6 +190,10 @@ func (s *ProcessSupervisorMock) ActiveTasksCount() int64 {
|
|||||||
return s.ActiveTasksCountMock()
|
return s.ActiveTasksCountMock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ProcessSupervisorMock) ConversionsSinceRestart() int64 {
|
||||||
|
return s.ConversionsSinceRestartMock()
|
||||||
|
}
|
||||||
|
|
||||||
// MetricsProviderMock is a mock for the [MetricsProvider] interface.
|
// MetricsProviderMock is a mock for the [MetricsProvider] interface.
|
||||||
type MetricsProviderMock struct {
|
type MetricsProviderMock struct {
|
||||||
MetricsMock func() ([]Metric, error)
|
MetricsMock func() ([]Metric, error)
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ type ProcessSupervisor interface {
|
|||||||
|
|
||||||
// ActiveTasksCount returns the current number of active tasks.
|
// ActiveTasksCount returns the current number of active tasks.
|
||||||
ActiveTasksCount() int64
|
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-
|
// healthCheckCacheTTL caches successful health probe results so kubelet-
|
||||||
@@ -577,6 +581,13 @@ func (s *processSupervisor) ActiveTasksCount() int64 {
|
|||||||
return s.activeTasks.Load()
|
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.
|
// Interface guards.
|
||||||
var (
|
var (
|
||||||
_ ProcessSupervisor = (*processSupervisor)(nil)
|
_ ProcessSupervisor = (*processSupervisor)(nil)
|
||||||
|
|||||||
@@ -1091,3 +1091,28 @@ func TestProcessSupervisor_IdleShutdownSkippedWhenActive(t *testing.T) {
|
|||||||
|
|
||||||
close(taskDone)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user