diff --git a/generator/monitor/monitor.go b/generator/monitor/monitor.go index 5b94d2e..f069add 100644 --- a/generator/monitor/monitor.go +++ b/generator/monitor/monitor.go @@ -134,6 +134,11 @@ func pprToStatus(ppr *podseidonv1a1.PodProtector) observer.MonitorWorkloads { isNonZero = 1 } + isMinCreated := 0 + if ppr.Status.Summary.Total >= ppr.Spec.MinAvailable { + isMinCreated = 1 + } + isFullyAvailable := 0 if ppr.Status.Summary.AggregatedAvailable >= ppr.Spec.MinAvailable { isFullyAvailable = 1 @@ -142,6 +147,7 @@ func pprToStatus(ppr *podseidonv1a1.PodProtector) observer.MonitorWorkloads { return observer.MonitorWorkloads{ NumWorkloads: 1, NumNonZeroWorkloads: isNonZero, + NumMinCreatedWorkloads: isMinCreated, NumAvailableWorkloads: isFullyAvailable, MinAvailable: int64(ppr.Spec.MinAvailable), TotalReplicas: int64(ppr.Status.Summary.Total), diff --git a/generator/monitor/monitor_test.go b/generator/monitor/monitor_test.go index 09c597b..2e7f1fc 100644 --- a/generator/monitor/monitor_test.go +++ b/generator/monitor/monitor_test.go @@ -102,6 +102,7 @@ func TestMonitor(t *testing.T) { Expect: observer.MonitorWorkloads{ NumWorkloads: 3, NumNonZeroWorkloads: 2, + NumMinCreatedWorkloads: 3, NumAvailableWorkloads: 2, MinAvailable: 10 + 100, TotalReplicas: 13 + 200, @@ -122,6 +123,7 @@ func TestMonitor(t *testing.T) { Expect: observer.MonitorWorkloads{ NumWorkloads: 2, NumNonZeroWorkloads: 1, + NumMinCreatedWorkloads: 2, NumAvailableWorkloads: 1, MinAvailable: 200, TotalReplicas: 200, diff --git a/generator/observer/metrics.go b/generator/observer/metrics.go index df5c3aa..748a4c5 100644 --- a/generator/observer/metrics.go +++ b/generator/observer/metrics.go @@ -88,6 +88,13 @@ func ProvideMetrics() component.Declared[Observer] { metrics.IntGauge(), func(status MonitorWorkloads) int { return status.NumNonZeroWorkloads }, ), + metrics.NewField( + "num_min_created_workloads", + "Number of workload objects managed by this generator with "+ + "the number of aggregated replicas not less than the minAvailable requirement", + metrics.IntGauge(), + func(status MonitorWorkloads) int { return status.NumMinCreatedWorkloads }, + ), metrics.NewField( "num_available_workloads", "Number of workload objects managed by this generator with minAvailable satisfied", diff --git a/generator/observer/observer.go b/generator/observer/observer.go index 7ac5d83..de98684 100644 --- a/generator/observer/observer.go +++ b/generator/observer/observer.go @@ -96,6 +96,13 @@ type MonitorWorkloads struct { // Number of workload objects managed by this generator with non-zero minAvailable. NumNonZeroWorkloads int + // Number of workload objects managed by this generator with + // the number of aggregated replicas not less than the minAvailable requirement. + // This is useful for detecting cases if aggregator is not properly deployed + // or as a less sensitive alternative of `NumAvailableWorkloads` + // to detect pods not getting created at all. + NumMinCreatedWorkloads int + // Number of workload objects managed by this generator with minAvailable satisfied. NumAvailableWorkloads int @@ -123,6 +130,7 @@ type MonitorWorkloads struct { func (dest *MonitorWorkloads) Add(delta MonitorWorkloads) { dest.NumWorkloads += delta.NumWorkloads dest.NumNonZeroWorkloads += delta.NumNonZeroWorkloads + dest.NumMinCreatedWorkloads += delta.NumMinCreatedWorkloads dest.NumAvailableWorkloads += delta.NumAvailableWorkloads dest.MinAvailable += delta.MinAvailable dest.TotalReplicas += delta.TotalReplicas @@ -135,6 +143,7 @@ func (dest *MonitorWorkloads) Add(delta MonitorWorkloads) { func (dest *MonitorWorkloads) Subtract(delta MonitorWorkloads) { dest.NumWorkloads -= delta.NumWorkloads dest.NumNonZeroWorkloads -= delta.NumNonZeroWorkloads + dest.NumMinCreatedWorkloads -= delta.NumMinCreatedWorkloads dest.NumAvailableWorkloads -= delta.NumAvailableWorkloads dest.MinAvailable -= delta.MinAvailable dest.TotalReplicas -= delta.TotalReplicas