Skip to content

Commit

Permalink
Add RecordConditionMetric method helper
Browse files Browse the repository at this point in the history
To allow recording metrics for conditions other than just the readiness
status.

The `RecordReadinessMetric` method is kept in place for API consumption
convenience.

Signed-off-by: Hidde Beydals <hello@hidde.co>
  • Loading branch information
hiddeco committed Apr 14, 2021
1 parent e552145 commit 2144df2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions runtime/controller/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,31 @@ func (m Metrics) RecordDuration(ref *corev1.ObjectReference, startTime time.Time
}
}

func (m Metrics) RecordSuspend(ref *corev1.ObjectReference, suspend bool) {
if m.MetricsRecorder != nil {
m.MetricsRecorder.RecordSuspend(*ref, suspend)
}
}

type readinessMetricsable interface {
metav1.Object
meta.ObjectWithStatusConditions
}

func (m Metrics) RecordReadinessMetric(ref *corev1.ObjectReference, obj readinessMetricsable) {
m.RecordConditionMetric(ref, obj, meta.ReadyCondition)
}

func (m Metrics) RecordConditionMetric(ref *corev1.ObjectReference, obj readinessMetricsable, conditionType string) {
if m.MetricsRecorder == nil {
return
}
if rc := apimeta.FindStatusCondition(*obj.GetStatusConditions(), meta.ReadyCondition); rc != nil {
m.MetricsRecorder.RecordCondition(*ref, *rc, !obj.GetDeletionTimestamp().IsZero())
} else {
m.MetricsRecorder.RecordCondition(*ref, metav1.Condition{
Type: meta.ReadyCondition,
rc := apimeta.FindStatusCondition(*obj.GetStatusConditions(), conditionType)
if rc == nil {
rc = &metav1.Condition{
Type: conditionType,
Status: metav1.ConditionUnknown,
}, !obj.GetDeletionTimestamp().IsZero())
}
}
m.MetricsRecorder.RecordCondition(*ref, *rc, !obj.GetDeletionTimestamp().IsZero())
}

0 comments on commit 2144df2

Please sign in to comment.