diff --git a/cmd/orbit/main.go b/cmd/orbit/main.go index 26f6676..24d570c 100644 --- a/cmd/orbit/main.go +++ b/cmd/orbit/main.go @@ -119,7 +119,9 @@ func run() error { call, cancel := context.WithTimeout(workflowCtx, 5*time.Second) _, err := workflows.Tick(call, 100) cancel() - metrics.RecordBatch("workflow", started, err) + if metrics != nil { + metrics.RecordBatch("workflow", started, err) + } if err != nil && workflowCtx.Err() == nil { slog.Error("workflow batch failed", "node_id", node) } @@ -142,7 +144,9 @@ func run() error { call, cancel := context.WithTimeout(scheduleCtx, 5*time.Second) _, err := schedules.Tick(call, 100) cancel() - metrics.RecordBatch("schedule", started, err) + if metrics != nil { + metrics.RecordBatch("schedule", started, err) + } if err != nil && scheduleCtx.Err() == nil { slog.Error("schedule batch failed", "node_id", node) } @@ -170,7 +174,9 @@ func run() error { call, cancel := context.WithTimeout(recoveryCtx, 5*time.Second) _, err := executions.Recover(call, 100) cancel() - metrics.RecordBatch("execution_recovery", started, err) + if metrics != nil { + metrics.RecordBatch("execution_recovery", started, err) + } if err != nil && recoveryCtx.Err() == nil { slog.Error("execution recovery batch failed", "node_id", node) } diff --git a/cmd/orbit/metrics_integration_test.go b/cmd/orbit/metrics_integration_test.go index c48ecda..7510f3f 100644 --- a/cmd/orbit/metrics_integration_test.go +++ b/cmd/orbit/metrics_integration_test.go @@ -135,6 +135,13 @@ func TestIntegrationMetricsProcess(t *testing.T) { } else if metrics != "" { t.Fatal("disabled metrics listener was started") } + if !enabled { + select { + case <-done: + t.Fatal("server exited after metrics was disabled") + case <-time.After(2200 * time.Millisecond): + } + } if err := cmd.Process.Signal(syscall.SIGTERM); err != nil { t.Fatal(err) }