Skip to content

Commit

Permalink
feat(generator): add num_min_created_workloads metric
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Jan 2, 2025
1 parent 0f6265d commit 987b497
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generator/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions generator/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -122,6 +123,7 @@ func TestMonitor(t *testing.T) {
Expect: observer.MonitorWorkloads{
NumWorkloads: 2,
NumNonZeroWorkloads: 1,
NumMinCreatedWorkloads: 2,
NumAvailableWorkloads: 1,
MinAvailable: 200,
TotalReplicas: 200,
Expand Down
7 changes: 7 additions & 0 deletions generator/observer/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions generator/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 987b497

Please sign in to comment.