From 2386fc6b3972d42a8223e3c62d8cdc769736d896 Mon Sep 17 00:00:00 2001 From: Yusuke Kato Date: Thu, 7 Nov 2024 21:56:45 +0900 Subject: [PATCH] Update internal/client/v1/client/discoverer/discover.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Yusuke Kato Signed-off-by: kpango --- internal/client/v1/client/discoverer/discover.go | 10 ++++++---- pkg/index/job/correction/usecase/corrector.go | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/client/v1/client/discoverer/discover.go b/internal/client/v1/client/discoverer/discover.go index b271ddc6b5..c8afd0916d 100644 --- a/internal/client/v1/client/discoverer/discover.go +++ b/internal/client/v1/client/discoverer/discover.go @@ -358,6 +358,9 @@ func (c *client) discoverNodes(ctx context.Context) (nodes *payload.Info_Nodes, return nil, err } slices.SortFunc(nodes.Nodes, func(left, right *payload.Info_Node) int { + if left.GetMemory() == nil || right.GetMemory() == nil { + return 0 // Default comparison value; adjust as needed. + } return cmp.Compare(left.GetMemory().GetUsage(), right.GetMemory().GetUsage()) }) return nodes, nil @@ -379,14 +382,13 @@ func (c *client) discoverAddrs( maxPodLen = l } slices.SortFunc(nodes.Nodes[i].Pods.Pods, func(left, right *payload.Info_Pod) int { + if left.GetMemory() == nil || right.GetMemory() == nil { + return 0 // Default comparison value; adjust as needed. + } return cmp.Compare(left.GetMemory().GetUsage(), right.GetMemory().GetUsage()) }) } } - nbody, err := nodes.MarshalJSON() - if err == nil && nbody != nil { - log.Debug(string(nbody)) - } addrs = make([]string, 0, podLength) for i := 0; i < maxPodLen; i++ { for _, node := range nodes.GetNodes() { diff --git a/pkg/index/job/correction/usecase/corrector.go b/pkg/index/job/correction/usecase/corrector.go index 5bf3b6b267..f7651547c0 100644 --- a/pkg/index/job/correction/usecase/corrector.go +++ b/pkg/index/job/correction/usecase/corrector.go @@ -16,7 +16,6 @@ package usecase import ( "context" "os" - "slices" "syscall" "time" @@ -86,10 +85,6 @@ func New(cfg *config.Data) (r runner.Runner, err error) { discoverer.WithDiscoverDuration(cfg.Corrector.Discoverer.Duration), discoverer.WithOptions(acOpts...), discoverer.WithNodeName(cfg.Corrector.NodeName), - discoverer.WithOnDiscoverFunc(func(_ context.Context, _ discoverer.Client, addrs []string) error { - slices.Reverse(addrs) - return nil - }), ) if err != nil { return nil, err