@@ -19,13 +19,15 @@ package controller
19
19
import (
20
20
"context"
21
21
"sort"
22
+ "strconv"
22
23
"time"
23
24
24
25
v1 "k8s.io/api/core/v1"
25
26
"k8s.io/apimachinery/pkg/fields"
26
27
"sigs.k8s.io/controller-runtime/pkg/client"
27
28
28
29
mcadv1beta1 "github.com/project-codeflare/mcad/api/v1beta1"
30
+ "github.com/prometheus/client_golang/prometheus"
29
31
)
30
32
31
33
// Compute available cluster capacity
@@ -78,12 +80,21 @@ func (r *AppWrapperReconciler) listAppWrappers(ctx context.Context) (map[int]Wei
78
80
}
79
81
requests := map [int ]Weights {} // total request per priority level
80
82
queue := []* mcadv1beta1.AppWrapper {} // queued appWrappers
83
+
84
+ appWrapperCount := map [phaseStepPriority ]int {}
85
+
81
86
for _ , appWrapper := range appWrappers .Items {
82
87
// get phase from cache if available as reconciler cache may be lagging
83
88
phase , step := r .getCachedPhase (& appWrapper )
89
+ priority := int (appWrapper .Spec .Priority )
90
+ key := phaseStepPriority {phase , step , priority }
91
+ if _ , exists := appWrapperCount [key ]; ! exists {
92
+ appWrapperCount [key ] = 0
93
+ }
94
+ appWrapperCount [key ]++
84
95
// make sure to initialize weights for every known priority level
85
- if requests [int ( appWrapper . Spec . Priority ) ] == nil {
86
- requests [int ( appWrapper . Spec . Priority ) ] = Weights {}
96
+ if requests [priority ] == nil {
97
+ requests [priority ] = Weights {}
87
98
}
88
99
if step != mcadv1beta1 .Idle {
89
100
// use max request among AppWrapper request and total request of non-terminated AppWrapper pods
@@ -109,6 +120,13 @@ func (r *AppWrapperReconciler) listAppWrappers(ctx context.Context) (map[int]Wei
109
120
queue = append (queue , & copy )
110
121
}
111
122
}
123
+ // update AppWrapper count metric
124
+ appWrappersCount .Reset ()
125
+ for key , count := range appWrapperCount {
126
+ appWrappersCount .With (
127
+ prometheus.Labels {"phase" : string (key .phase ), "step" : string (key .step ), "priority" : strconv .Itoa (key .priority )},
128
+ ).Set (float64 (count ))
129
+ }
112
130
// propagate reservations at all priority levels to all levels below
113
131
assertPriorities (requests )
114
132
// order AppWrapper queue based on priority and precedence (creation time)
0 commit comments