Skip to content
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

Johnaz/issue 239 #249

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions internal/controllers/watchdog/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ func (c *watchdogController) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, err
}

var inputsMissing int
var notInLockstep int
var withoutSynthesizers int
var pendingInit int
var pending int
var unready int
var terminal int
for _, comp := range list.Items {
if c.hasNoSynthesizer(&comp, ctx) {
withoutSynthesizers++
}
if c.waitingOnInputs(&comp, ctx) {
inputsMissing++
}
if c.getNotInLockstep(&comp, ctx) {
notInLockstep++
}
if c.pendingInitialReconciliation(&comp) {
pendingInit++
}
Expand All @@ -54,6 +66,9 @@ func (c *watchdogController) Reconcile(ctx context.Context, req ctrl.Request) (c
}
}

waitingOnInputs.Set(float64(inputsMissing))
inputsNotInLockstep.Set(float64(notInLockstep))
compositionsWithoutSynthesizers.Set(float64(withoutSynthesizers))
pendingInitialReconciliation.Set(float64(pendingInit))
stuckReconciling.Set(float64(pending))
pendingReadiness.Set(float64(unready))
Expand All @@ -62,6 +77,32 @@ func (c *watchdogController) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, nil
}

func (c *watchdogController) getSynthesizer(comp *apiv1.Composition, ctx context.Context) (*apiv1.Synthesizer, error) {
syn := &apiv1.Synthesizer{}
syn.Name = comp.Spec.Synthesizer.Name
err := c.client.Get(ctx, client.ObjectKeyFromObject(syn), syn)
return syn, err
}

func (c *watchdogController) hasNoSynthesizer(comp *apiv1.Composition, ctx context.Context) bool {
_, err := c.getSynthesizer(comp, ctx)
return err != nil
}

func (c *watchdogController) getInputsExist(comp *apiv1.Composition, ctx context.Context) bool {
syn, err := c.getSynthesizer(comp, ctx)
return (err != nil) || comp.InputsExist(syn)
jveski marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *watchdogController) getNotInLockstep(comp *apiv1.Composition, ctx context.Context) bool {
syn, err := c.getSynthesizer(comp, ctx)
return (err != nil) || comp.InputsOutOfLockstep(syn)
}

func (c *watchdogController) waitingOnInputs(comp *apiv1.Composition, ctx context.Context) bool {
return !c.getInputsExist(comp, ctx) && time.Since(comp.CreationTimestamp.Time) > c.threshold
}

func (c *watchdogController) pendingInitialReconciliation(comp *apiv1.Composition) bool {
return !synthesisHasReconciled(comp.Status.CurrentSynthesis) &&
!synthesisHasReconciled(comp.Status.PreviousSynthesis) &&
Expand Down
23 changes: 22 additions & 1 deletion internal/controllers/watchdog/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ import (
)

var (
waitingOnInputs = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "eno_compositions_inputs_missing_total",
Help: "Number of compositions that are missing input resources",
},
)

inputsNotInLockstep = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "eno_compositions_inputs_not_in_lockstep_total",
Help: "Number of compositions that have input resources that are not in lockstep with the composition's current state",
},
)

compositionsWithoutSynthesizers = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "eno_compositions_without_synthesizers_total",
Help: "Number of compositions that do not have synthesizers",
},
)

pendingInitialReconciliation = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "eno_compositions_pending_initial_reconciliation",
Expand Down Expand Up @@ -36,5 +57,5 @@ var (
)

func init() {
metrics.Registry.MustRegister(pendingInitialReconciliation, stuckReconciling, pendingReadiness, terminalErrors)
metrics.Registry.MustRegister(waitingOnInputs, inputsNotInLockstep, compositionsWithoutSynthesizers, pendingInitialReconciliation, stuckReconciling, pendingReadiness, terminalErrors)
}
Loading