Skip to content

Commit

Permalink
Johnaz/issue 239 (#249)
Browse files Browse the repository at this point in the history
Added a gauge metric to keep track of the number of compositions waiting
for inputs.
Uncovered the need for another gauge metric to keep track of the number
of compositions without synthesizers.
  • Loading branch information
johnazariah authored Nov 21, 2024
1 parent c33e81b commit 3b7a52c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
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)
}

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)
}

0 comments on commit 3b7a52c

Please sign in to comment.