Skip to content

Commit

Permalink
Use the reconcile-id rather than the scheduler-id
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Feb 1, 2025
1 parent bb27849 commit db57f18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pkg/controllers/provisioning/scheduling/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (

const (
ControllerLabel = "controller"
schedulingIDLabel = "scheduling_id"
schedulerIDLabel = "scheduler_id"
reconcileIDLabel = "reconcile_id"
schedulerSubsystem = "scheduler"
)

Expand Down Expand Up @@ -54,7 +55,8 @@ var (
},
[]string{
ControllerLabel,
schedulingIDLabel,
schedulerIDLabel,
reconcileIDLabel,
},
)
UnfinishedWorkSeconds = opmetrics.NewPrometheusGauge(
Expand All @@ -67,7 +69,8 @@ var (
},
[]string{
ControllerLabel,
schedulingIDLabel,
schedulerIDLabel,
reconcileIDLabel,
},
)
IgnoredPodCount = opmetrics.NewPrometheusGauge(
Expand Down
9 changes: 5 additions & 4 deletions pkg/controllers/provisioning/scheduling/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log"

v1 "sigs.k8s.io/karpenter/pkg/apis/v1"
Expand Down Expand Up @@ -225,11 +226,11 @@ func (s *Scheduler) Solve(ctx context.Context, pods []*corev1.Pod) Results {
lastLogTime := s.clock.Now()
batchSize := len(q.pods)
for {
UnfinishedWorkSeconds.Set(s.clock.Since(startTime).Seconds(), map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulingIDLabel: string(s.id)})
QueueDepth.Set(float64(len(q.pods)), map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulingIDLabel: string(s.id)})
UnfinishedWorkSeconds.Set(s.clock.Since(startTime).Seconds(), map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulerIDLabel: string(s.id), reconcileIDLabel: string(controller.ReconcileIDFromContext(ctx))})
QueueDepth.Set(float64(len(q.pods)), map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulerIDLabel: string(s.id), reconcileIDLabel: string(controller.ReconcileIDFromContext(ctx))})

if s.clock.Since(lastLogTime) > time.Minute {
log.FromContext(ctx).WithValues("pods-scheduled", batchSize-len(q.pods), "pods-remaining", len(q.pods), "duration", s.clock.Since(startTime).Truncate(time.Second), "scheduling-id", string(s.id)).Info("computing pod scheduling...")
log.FromContext(ctx).WithValues("pods-scheduled", batchSize-len(q.pods), "pods-remaining", len(q.pods), "duration", s.clock.Since(startTime).Truncate(time.Second)).Info("computing pod scheduling...")
lastLogTime = s.clock.Now()
}
// Try the next pod
Expand All @@ -253,7 +254,7 @@ func (s *Scheduler) Solve(ctx context.Context, pods []*corev1.Pod) Results {
}
}
}
UnfinishedWorkSeconds.Delete(map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulingIDLabel: string(s.id)})
UnfinishedWorkSeconds.Delete(map[string]string{ControllerLabel: injection.GetControllerName(ctx), schedulerIDLabel: string(s.id), reconcileIDLabel: string(controller.ReconcileIDFromContext(ctx))})
for _, m := range s.newNodeClaims {
m.FinalizeScheduling()
}
Expand Down

0 comments on commit db57f18

Please sign in to comment.