Skip to content

Commit 6bbff40

Browse files
committed
Add node_pool to blockedEval metric
Adds the node_pool to the blockedEval metrics that get emitted for resource/cpu, along with the dc and node class.
1 parent 493e7b2 commit 6bbff40

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

api/allocations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ type AllocationMetric struct {
307307
NodesEvaluated int
308308
NodesFiltered int
309309
NodesInPool int
310+
NodePool string
310311
NodesAvailable map[string]int
311312
ClassFiltered map[string]int
312313
ConstraintFiltered map[string]int

nomad/blocked_evals.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ func (b *BlockedEvals) EmitStats(period time.Duration, stopCh <-chan struct{}) {
749749
labels := []metrics.Label{
750750
{Name: "datacenter", Value: k.dc},
751751
{Name: "node_class", Value: k.class},
752+
{Name: "node_pool", Value: k.nodepool},
752753
}
753754
metrics.SetGaugeWithLabels([]string{"nomad", "blocked_evals", "cpu"}, float32(v.CPU), labels)
754755
metrics.SetGaugeWithLabels([]string{"nomad", "blocked_evals", "memory"}, float32(v.MemoryMB), labels)

nomad/blocked_evals_stats.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ type BlockedStats struct {
2929

3030
// classInDC is a coordinate of a specific class in a specific datacenter
3131
type classInDC struct {
32-
dc string
33-
class string
32+
dc string
33+
class string
34+
nodepool string
3435
}
3536

3637
// NewBlockedStats returns a new BlockedStats.
@@ -80,6 +81,7 @@ func (b *BlockedStats) prune(cutoff time.Time) {
8081
func generateResourceStats(eval *structs.Evaluation) *BlockedResourcesStats {
8182
dcs := make(map[string]struct{})
8283
classes := make(map[string]struct{})
84+
nodepools := make(map[string]struct{})
8385

8486
resources := BlockedResourcesSummary{
8587
Timestamp: time.Now().UTC(),
@@ -92,6 +94,9 @@ func generateResourceStats(eval *structs.Evaluation) *BlockedResourcesStats {
9294
for class := range allocMetrics.ClassExhausted {
9395
classes[class] = struct{}{}
9496
}
97+
98+
nodepools[allocMetrics.NodePool] = struct{}{}
99+
95100
if len(allocMetrics.ClassExhausted) == 0 {
96101
// some evaluations have no class
97102
classes[""] = struct{}{}
@@ -107,10 +112,12 @@ func generateResourceStats(eval *structs.Evaluation) *BlockedResourcesStats {
107112
byJob[nsID] = resources
108113

109114
byClassInDC := make(map[classInDC]BlockedResourcesSummary)
110-
for dc := range dcs {
111-
for class := range classes {
112-
k := classInDC{dc: dc, class: class}
113-
byClassInDC[k] = resources
115+
for nodepool := range nodepools {
116+
for dc := range dcs {
117+
for class := range classes {
118+
k := classInDC{dc: dc, class: class, nodepool: nodepool}
119+
byClassInDC[k] = resources
120+
}
114121
}
115122
}
116123

nomad/blocked_evals_stats_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ var (
147147
}
148148

149149
node1 = classInDC{
150-
dc: "dc1",
151-
class: "alpha",
150+
dc: "dc1",
151+
class: "alpha",
152+
nodepool: "default",
152153
}
153154

154155
node2 = classInDC{
155-
dc: "dc1",
156-
class: "beta",
156+
dc: "dc1",
157+
class: "beta",
158+
nodepool: "dev",
157159
}
158160

159161
node3 = classInDC{
@@ -321,6 +323,7 @@ func (t testBlockedEvalsRandomBlockedEval) Generate(rand *rand.Rand, _ int) refl
321323
tgCount := rand.Intn(10) + 1
322324
dcCount := rand.Intn(3) + 1
323325
nodeClassCount := rand.Intn(3) + 1
326+
nodePoolName := fmt.Sprintf("node-pool-%d", rand.Intn(3)+1)
324327

325328
failedTGAllocs := map[string]*structs.AllocMetric{}
326329

@@ -340,6 +343,7 @@ func (t testBlockedEvalsRandomBlockedEval) Generate(rand *rand.Rand, _ int) refl
340343
},
341344
NodesAvailable: map[string]int{},
342345
ClassExhausted: map[string]int{},
346+
NodePool: nodePoolName,
343347
}
344348

345349
for dc := 1; dc <= dcCount; dc++ {

nomad/structs/structs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11876,6 +11876,9 @@ type AllocMetric struct {
1187611876
// NodesInPool is the number of nodes in the node pool used by the job.
1187711877
NodesInPool int
1187811878

11879+
// NodePool is the node pool the node belongs to.
11880+
NodePool string
11881+
1187911882
// NodesAvailable is the number of nodes available for evaluation per DC.
1188011883
NodesAvailable map[string]int
1188111884

scheduler/generic_sched.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ func (s *GenericScheduler) computePlacements(
577577
// Store the available nodes by datacenter
578578
s.ctx.Metrics().NodesAvailable = byDC
579579
s.ctx.Metrics().NodesInPool = len(nodes)
580+
s.ctx.Metrics().NodePool = s.job.NodePool
580581

581582
// Compute top K scoring node metadata
582583
s.ctx.Metrics().PopulateScoreMetaData()

0 commit comments

Comments
 (0)