Skip to content

Commit

Permalink
feat: searcher can not found candidate scheduler clusters, return all…
Browse files Browse the repository at this point in the history
… scheduler clusters (#1991)

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Jan 10, 2023
1 parent 5f3ca6f commit da0cf8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions manager/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ var (
Help: "Gauge of the number of peer.",
}, []string{"version", "commit"})

SearchSchedulerClusterFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.SchedulerMetricsName,
Name: "search_scheduler_cluster_failure_total",
Help: "Counter of the number of failed of searching scheduler cluster.",
}, []string{"version", "commit"})

VersionGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.ManagerMetricsName,
Expand Down
20 changes: 14 additions & 6 deletions manager/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,20 +544,28 @@ func (s *Server) ListSchedulers(ctx context.Context, req *managerv1.ListSchedule
if err := s.db.WithContext(ctx).Preload("SecurityGroup.SecurityRules").Preload("SeedPeerClusters.SeedPeers", "state = ?", "active").Preload("Schedulers", "state = ?", "active").Find(&schedulerClusters).Error; err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}
log.Debugf("list scheduler clusters %v with hostInfo %#v", getSchedulerClusterNames(schedulerClusters), req.HostInfo)

// Search optimal scheduler clusters.
log.Debugf("list scheduler clusters %v with hostInfo %#v", getSchedulerClusterNames(schedulerClusters), req.HostInfo)
schedulerClusters, err := s.searcher.FindSchedulerClusters(ctx, schedulerClusters, req)
// If searcher can not found candidate scheduler cluster,
// return all scheduler clusters.
var (
candidateSchedulerClusters []model.SchedulerCluster
err error
)
candidateSchedulerClusters, err = s.searcher.FindSchedulerClusters(ctx, schedulerClusters, req)
if err != nil {
candidateSchedulerClusters = schedulerClusters

log.Error(err)
return nil, status.Error(codes.NotFound, "scheduler cluster not found")
metrics.SearchSchedulerClusterFailureCount.WithLabelValues(req.Version, req.Commit).Inc()
}
log.Debugf("find matching scheduler cluster %v", getSchedulerClusterNames(schedulerClusters))

schedulers := []model.Scheduler{}
for _, schedulerCluster := range schedulerClusters {
for _, scheduler := range schedulerCluster.Schedulers {
scheduler.SchedulerCluster = schedulerCluster
for _, candidateSchedulerCluster := range candidateSchedulerClusters {
for _, scheduler := range candidateSchedulerCluster.Schedulers {
scheduler.SchedulerCluster = candidateSchedulerCluster
schedulers = append(schedulers, scheduler)
}
}
Expand Down

0 comments on commit da0cf8d

Please sign in to comment.