-
Notifications
You must be signed in to change notification settings - Fork 1
status: use hive jobs for probes #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pr_044_before
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,12 @@ | |
| package status | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
|
|
||
| "github.com/cilium/hive/cell" | ||
| "github.com/cilium/hive/job" | ||
| "github.com/cilium/statedb" | ||
| "github.com/spf13/pflag" | ||
|
|
||
|
|
@@ -59,8 +62,8 @@ type statusParams struct { | |
| cell.In | ||
|
|
||
| Lifecycle cell.Lifecycle | ||
| JobGroup job.Group | ||
| Logger *slog.Logger | ||
| Health cell.Health | ||
|
|
||
| Config Config | ||
| DaemonConfig *option.DaemonConfig | ||
|
|
@@ -112,11 +115,30 @@ func newStatusCollector(params statusParams) StatusCollector { | |
| statusCollector: newCollector(params.Logger, params.Config), | ||
| } | ||
|
|
||
| params.JobGroup.Add(job.OneShot("probes", func(ctx context.Context, health cell.Health) error { | ||
| params.Logger.Debug("Starting probes") | ||
| collector.statusCollector.StartProbes(collector.getProbes()) | ||
| defer collector.statusCollector.Close() | ||
| params.Logger.Debug("Successfully started probes") | ||
|
|
||
| waitCtx, cancelWait := context.WithTimeout(ctx, params.Config.StatusCollectorProbeCheckTimeout) | ||
| defer cancelWait() | ||
|
|
||
| // Report health whether all probes have been executed at least once. | ||
| if err := collector.statusCollector.WaitForFirstRun(waitCtx); err != nil { | ||
| params.Logger.Debug("Not all probes successfully executed at least once") | ||
| return fmt.Errorf("not all probes successfully executed at least once: %w", err) | ||
| } | ||
|
|
||
| collector.allProbesInitialized = true | ||
|
|
||
| params.Logger.Debug("All probes executed at least once") | ||
|
|
||
| <-ctx.Done() | ||
| return nil | ||
| })) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Health parameter received but never used for reportingMedium Severity The |
||
|
|
||
| params.Lifecycle.Append(cell.Hook{ | ||
| OnStart: func(ctx cell.HookContext) error { | ||
| collector.startStatusCollector() | ||
| return nil | ||
| }, | ||
| OnStop: func(_ cell.HookContext) error { | ||
| // If the KVstore state is not OK, print help for user. | ||
| if collector.statusResponse.Kvstore != nil && | ||
|
|
@@ -131,9 +153,7 @@ func newStatusCollector(params statusParams) StatusCollector { | |
| logfields.Status, collector.statusResponse.Kvstore.Msg, | ||
| logfields.HelpMessage, helpMsg, | ||
| ) | ||
|
|
||
| } | ||
| collector.statusCollector.Close() | ||
| return nil | ||
| }, | ||
| }) | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probes stopped prematurely on initial timeout error
High Severity
When
WaitForFirstRuntimes out, returning an error causes thedefer collector.statusCollector.Close()to execute immediately, stopping all running probes. The previous implementation kept probes running even when the initial check failed, only closing them duringOnStop. Now, if any probe takes longer thanStatusCollectorProbeCheckTimeout(default 5 minutes) for its first run, the entire status collector becomes non-functional because all probes are terminated.