@@ -42,6 +42,7 @@ import (
42
42
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
43
43
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
44
44
priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util"
45
+ "k8s.io/kubernetes/pkg/scheduler/metrics"
45
46
"k8s.io/kubernetes/pkg/scheduler/util"
46
47
)
47
48
@@ -283,13 +284,13 @@ func NewPriorityQueueWithClock(stop <-chan struct{}, clock util.Clock) *Priority
283
284
clock : clock ,
284
285
stop : stop ,
285
286
podBackoff : NewPodBackoffMap (1 * time .Second , 10 * time .Second ),
286
- activeQ : util .NewHeap (podInfoKeyFunc , activeQComp ),
287
- unschedulableQ : newUnschedulablePodsMap (),
287
+ activeQ : util .NewHeapWithRecorder (podInfoKeyFunc , activeQComp , metrics . NewActivePodsRecorder () ),
288
+ unschedulableQ : newUnschedulablePodsMap (metrics . NewUnschedulablePodsRecorder () ),
288
289
nominatedPods : newNominatedPodMap (),
289
290
moveRequestCycle : - 1 ,
290
291
}
291
292
pq .cond .L = & pq .lock
292
- pq .podBackoffQ = util .NewHeap (podInfoKeyFunc , pq .podsCompareBackoffCompleted )
293
+ pq .podBackoffQ = util .NewHeapWithRecorder (podInfoKeyFunc , pq .podsCompareBackoffCompleted , metrics . NewBackoffPodsRecorder () )
293
294
294
295
pq .run ()
295
296
@@ -777,16 +778,27 @@ type UnschedulablePodsMap struct {
777
778
// podInfoMap is a map key by a pod's full-name and the value is a pointer to the podInfo.
778
779
podInfoMap map [string ]* podInfo
779
780
keyFunc func (* v1.Pod ) string
781
+ // metricRecorder updates the counter when elements of an unschedulablePodsMap
782
+ // get added or removed, and it does nothing if it's nil
783
+ metricRecorder metrics.MetricRecorder
780
784
}
781
785
782
786
// Add adds a pod to the unschedulable podInfoMap.
783
787
func (u * UnschedulablePodsMap ) addOrUpdate (pInfo * podInfo ) {
784
- u .podInfoMap [u .keyFunc (pInfo .pod )] = pInfo
788
+ podID := u .keyFunc (pInfo .pod )
789
+ if _ , exists := u .podInfoMap [podID ]; ! exists && u .metricRecorder != nil {
790
+ u .metricRecorder .Inc ()
791
+ }
792
+ u .podInfoMap [podID ] = pInfo
785
793
}
786
794
787
795
// Delete deletes a pod from the unschedulable podInfoMap.
788
796
func (u * UnschedulablePodsMap ) delete (pod * v1.Pod ) {
789
- delete (u .podInfoMap , u .keyFunc (pod ))
797
+ podID := u .keyFunc (pod )
798
+ if _ , exists := u .podInfoMap [podID ]; exists && u .metricRecorder != nil {
799
+ u .metricRecorder .Dec ()
800
+ }
801
+ delete (u .podInfoMap , podID )
790
802
}
791
803
792
804
// Get returns the podInfo if a pod with the same key as the key of the given "pod"
@@ -802,13 +814,17 @@ func (u *UnschedulablePodsMap) get(pod *v1.Pod) *podInfo {
802
814
// Clear removes all the entries from the unschedulable podInfoMap.
803
815
func (u * UnschedulablePodsMap ) clear () {
804
816
u .podInfoMap = make (map [string ]* podInfo )
817
+ if u .metricRecorder != nil {
818
+ u .metricRecorder .Clear ()
819
+ }
805
820
}
806
821
807
822
// newUnschedulablePodsMap initializes a new object of UnschedulablePodsMap.
808
- func newUnschedulablePodsMap () * UnschedulablePodsMap {
823
+ func newUnschedulablePodsMap (metricRecorder metrics. MetricRecorder ) * UnschedulablePodsMap {
809
824
return & UnschedulablePodsMap {
810
- podInfoMap : make (map [string ]* podInfo ),
811
- keyFunc : util .GetPodFullName ,
825
+ podInfoMap : make (map [string ]* podInfo ),
826
+ keyFunc : util .GetPodFullName ,
827
+ metricRecorder : metricRecorder ,
812
828
}
813
829
}
814
830
0 commit comments