From 4f8e925b542fe35cdb6757e47bd72c6115cac30e Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Fri, 17 Aug 2018 19:26:43 -0500 Subject: [PATCH] Move topk and delay heap to separate packages under lib --- command/alloc_status_test.go | 27 ++++++++++++-------- lib/{ => delayheap}/delay_heap.go | 2 +- lib/{ => delayheap}/delay_heap_test.go | 2 +- {helper/lib => lib/kheap}/score_heap.go | 2 +- {helper/lib => lib/kheap}/score_heap_test.go | 2 +- nomad/eval_broker.go | 8 +++--- nomad/structs/structs.go | 6 ++--- 7 files changed, 27 insertions(+), 22 deletions(-) rename lib/{ => delayheap}/delay_heap.go (99%) rename lib/{ => delayheap}/delay_heap_test.go (99%) rename {helper/lib => lib/kheap}/score_heap.go (99%) rename {helper/lib => lib/kheap}/score_heap_test.go (99%) diff --git a/command/alloc_status_test.go b/command/alloc_status_test.go index 2c91c3955..3a65c2843 100644 --- a/command/alloc_status_test.go +++ b/command/alloc_status_test.go @@ -254,14 +254,20 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) { mockNode1 := mock.Node() mockNode2 := mock.Node() a.Metrics = &structs.AllocMetric{ - ScoreMetaData: map[string][]*structs.NodeScoreMeta{ - "binpack": { - {NodeID: mockNode1.ID, Score: 0.77}, - {NodeID: mockNode2.ID, Score: 0.75}, + ScoreMetaData: []*structs.NodeScoreMeta{ + { + NodeID: mockNode1.ID, + Scores: map[string]float64{ + "binpack": 0.77, + "node-affinity": 0.5, + }, }, - "node-affinity": { - {NodeID: mockNode1.ID, Score: 0.5}, - {NodeID: mockNode2.ID, Score: 0.33}, + { + NodeID: mockNode2.ID, + Scores: map[string]float64{ + "binpack": 0.75, + "node-affinity": 0.33, + }, }, }, } @@ -272,10 +278,9 @@ func TestAllocStatusCommand_ScoreMetrics(t *testing.T) { } out := ui.OutputWriter.String() require.Contains(out, "Placement Metrics") - require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode1.ID)) - require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode2.ID)) - require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "node-affinity", mockNode1.ID)) - require.Contains(out, fmt.Sprintf("Scorer %q, Node %q", "binpack", mockNode2.ID)) + require.Contains(out, mockNode1.ID) + require.Contains(out, mockNode2.ID) + require.Contains(out, "Final Score") } func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) { diff --git a/lib/delay_heap.go b/lib/delayheap/delay_heap.go similarity index 99% rename from lib/delay_heap.go rename to lib/delayheap/delay_heap.go index 155583198..4e8ba669c 100644 --- a/lib/delay_heap.go +++ b/lib/delayheap/delay_heap.go @@ -1,4 +1,4 @@ -package lib +package delayheap import ( "container/heap" diff --git a/lib/delay_heap_test.go b/lib/delayheap/delay_heap_test.go similarity index 99% rename from lib/delay_heap_test.go rename to lib/delayheap/delay_heap_test.go index ddf640677..3b44acc19 100644 --- a/lib/delay_heap_test.go +++ b/lib/delayheap/delay_heap_test.go @@ -1,4 +1,4 @@ -package lib +package delayheap import ( "testing" diff --git a/helper/lib/score_heap.go b/lib/kheap/score_heap.go similarity index 99% rename from helper/lib/score_heap.go rename to lib/kheap/score_heap.go index d20dee98d..9ad9e0b3a 100644 --- a/helper/lib/score_heap.go +++ b/lib/kheap/score_heap.go @@ -1,4 +1,4 @@ -package lib +package kheap import ( "container/heap" diff --git a/helper/lib/score_heap_test.go b/lib/kheap/score_heap_test.go similarity index 99% rename from helper/lib/score_heap_test.go rename to lib/kheap/score_heap_test.go index edda8d97f..932c08ccf 100644 --- a/helper/lib/score_heap_test.go +++ b/lib/kheap/score_heap_test.go @@ -1,4 +1,4 @@ -package lib +package kheap import ( "container/heap" diff --git a/nomad/eval_broker.go b/nomad/eval_broker.go index 77de255a4..e507a060c 100644 --- a/nomad/eval_broker.go +++ b/nomad/eval_broker.go @@ -12,7 +12,7 @@ import ( "github.com/armon/go-metrics" "github.com/hashicorp/nomad/helper/uuid" - "github.com/hashicorp/nomad/lib" + "github.com/hashicorp/nomad/lib/delayheap" "github.com/hashicorp/nomad/nomad/structs" ) @@ -86,7 +86,7 @@ type EvalBroker struct { // delayHeap is a heap used to track incoming evaluations that are // not eligible to enqueue until their WaitTime - delayHeap *lib.DelayHeap + delayHeap *delayheap.DelayHeap // delayedEvalsUpdateCh is used to trigger notifications for updates // to the delayHeap @@ -142,7 +142,7 @@ func NewEvalBroker(timeout, initialNackDelay, subsequentNackDelay time.Duration, timeWait: make(map[string]*time.Timer), initialNackDelay: initialNackDelay, subsequentNackDelay: subsequentNackDelay, - delayHeap: lib.NewDelayHeap(), + delayHeap: delayheap.NewDelayHeap(), delayedEvalsUpdateCh: make(chan struct{}, 1), } b.stats.ByScheduler = make(map[string]*SchedulerStats) @@ -719,7 +719,7 @@ func (b *EvalBroker) flush() { b.ready = make(map[string]PendingEvaluations) b.unack = make(map[string]*unackEval) b.timeWait = make(map[string]*time.Timer) - b.delayHeap = lib.NewDelayHeap() + b.delayHeap = delayheap.NewDelayHeap() } // evalWrapper satisfies the HeapNode interface diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 2f14248d2..105d39334 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -34,8 +34,8 @@ import ( "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper/args" - "github.com/hashicorp/nomad/helper/lib" "github.com/hashicorp/nomad/helper/uuid" + "github.com/hashicorp/nomad/lib/kheap" "github.com/mitchellh/copystructure" "github.com/ugorji/go/codec" @@ -6510,7 +6510,7 @@ type AllocMetric struct { // topScores is used to maintain a heap of the top K nodes with // the highest normalized score - topScores *lib.ScoreHeap + topScores *kheap.ScoreHeap // AllocationTime is a measure of how long the allocation // attempt took. This can affect performance and SLAs. @@ -6599,7 +6599,7 @@ func (a *AllocMetric) ScoreNode(node *Node, name string, score float64) { // Create the heap if its not there already if a.topScores == nil { - a.topScores = lib.NewScoreHeap(MaxRetainedNodeScores) + a.topScores = kheap.NewScoreHeap(MaxRetainedNodeScores) } heap.Push(a.topScores, a.nodeScoreMeta)