Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Martin <chris@cmartinit.co.uk>
  • Loading branch information
d80tb7 committed Aug 9, 2024
1 parent 064b54d commit 6a35699
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
38 changes: 19 additions & 19 deletions internal/scheduler/context/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func TestSchedulingContextAccounting(t *testing.T) {
}

func TestCalculateFairShares(t *testing.T) {
zeroCpu := nCpu(0)
oneCpu := nCpu(1)
fortyCpu := nCpu(40)
oneHundredCpu := nCpu(100)
oneThousandCpu := nCpu(1000)
zeroCpu := cpu(0)
oneCpu := cpu(1)
fortyCpu := cpu(40)
oneHundredCpu := cpu(100)
oneThousandCpu := cpu(1000)
tests := map[string]struct {
availableResources schedulerobjects.ResourceList
queueCtxs map[string]*QueueSchedulingContext
Expand Down Expand Up @@ -206,44 +206,44 @@ func TestCalculateFairnessError(t *testing.T) {
expected float64
}{
"one queue, no error": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{
"queueA": {Allocated: nCpu(50), AdjustedFairShare: 0.5},
"queueA": {Allocated: cpu(50), AdjustedFairShare: 0.5},
},
expected: 0,
},
"two queues, no error": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{
"queueA": {Allocated: nCpu(50), AdjustedFairShare: 0.5},
"queueB": {Allocated: nCpu(50), AdjustedFairShare: 0.5},
"queueA": {Allocated: cpu(50), AdjustedFairShare: 0.5},
"queueB": {Allocated: cpu(50), AdjustedFairShare: 0.5},
},
expected: 0,
},
"one queue with error": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{
"queueA": {Allocated: nCpu(40), AdjustedFairShare: 0.5},
"queueA": {Allocated: cpu(40), AdjustedFairShare: 0.5},
},
expected: 0.1,
},
"two queues with error": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{
"queueA": {Allocated: nCpu(40), AdjustedFairShare: 0.5},
"queueB": {Allocated: nCpu(10), AdjustedFairShare: 0.5},
"queueA": {Allocated: cpu(40), AdjustedFairShare: 0.5},
"queueB": {Allocated: cpu(10), AdjustedFairShare: 0.5},
},
expected: 0.5,
},
"above fair share is not counted": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{
"queueA": {Allocated: nCpu(100), AdjustedFairShare: 0.5},
"queueA": {Allocated: cpu(100), AdjustedFairShare: 0.5},
},
expected: 0.0,
},
"empty": {
availableResources: nCpu(100),
availableResources: cpu(100),
queueCtxs: map[string]*QueueSchedulingContext{},
expected: 0.0,
},
Expand Down Expand Up @@ -278,7 +278,7 @@ func testSmallCpuJobSchedulingContext(queue, priorityClassName string) *JobSched
}
}

func nCpu(n int) schedulerobjects.ResourceList {
func cpu(n int) schedulerobjects.ResourceList {
return schedulerobjects.ResourceList{
Resources: map[string]resource.Quantity{"cpu": resource.MustParse(fmt.Sprintf("%d", n))},
}
Expand Down
10 changes: 5 additions & 5 deletions internal/scheduler/metrics/cycle_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const epsilon = 1e-6

func TestReportStateTransitions(t *testing.T) {
fairnessCostProvider, err := fairness.NewDominantResourceFairness(
nCpu(100),
cpu(100),
configuration.SchedulingConfig{DominantResourceFairnessResourcesToConsider: []string{"cpu"}})
require.NoError(t, err)
result := schedulerresult.SchedulerResult{
Expand All @@ -31,9 +31,9 @@ func TestReportStateTransitions(t *testing.T) {
FairnessCostProvider: fairnessCostProvider,
QueueSchedulingContexts: map[string]*context.QueueSchedulingContext{
"queue1": {
Allocated: nCpu(10),
Demand: nCpu(20),
CappedDemand: nCpu(15),
Allocated: cpu(10),
Demand: cpu(20),
CappedDemand: cpu(15),
AdjustedFairShare: 0.15,
SuccessfulJobSchedulingContexts: map[string]*context.JobSchedulingContext{
"job1": {
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestReportStateTransitions(t *testing.T) {
assert.InDelta(t, 0.05, fairnessError, epsilon, "fairnessError")
}

func nCpu(n int) schedulerobjects.ResourceList {
func cpu(n int) schedulerobjects.ResourceList {
return schedulerobjects.ResourceList{
Resources: map[string]resource.Quantity{"cpu": resource.MustParse(fmt.Sprintf("%d", n))},
}
Expand Down
10 changes: 5 additions & 5 deletions internal/scheduler/metrics/state_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,35 @@ func newJobStateMetrics(errorRegexes []*regexp.Regexp, trackedResourceNames []v1
jobStateSecondsByQueue := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: prefix + "job_state_seconds_by_queue",
Help: "time spend in different states at the queue level",
Help: "time spent in different states at the queue level",
},
[]string{queueLabel, poolLabel, stateLabel, priorStateLabel},
)
jobStateSecondsByNode := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: prefix + "job_state_seconds_by_node",
Help: "time spend in different states at the node level",
Help: "time spent in different states at the node level",
},
[]string{nodeLabel, poolLabel, clusterLabel, stateLabel, priorStateLabel},
)
jobStateResourceSecondsByQueue := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: prefix + "job_state_resource_seconds_by_queue",
Help: "Resource-seconds spend in different states at the queue level",
Help: "Resource-seconds spent in different states at the queue level",
},
[]string{queueLabel, poolLabel, stateLabel, priorStateLabel, resourceLabel},
)
jobStateResourceSecondsByNode := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: prefix + "job_state_resource_seconds_by_node",
Help: "Resource-seconds spend in different states at the node level",
Help: "Resource-seconds spent in different states at the node level",
},
[]string{nodeLabel, poolLabel, clusterLabel, stateLabel, priorStateLabel, resourceLabel},
)
jobErrorsByQueue := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: prefix + "job_error_classification_by_queue",
Help: "Failed jobs ey error classification at the queue level",
Help: "Failed jobs by error classification at the queue level",
},
[]string{queueLabel, poolLabel, errorCategoryLabel, errorSubcategoryLabel},
)
Expand Down

0 comments on commit 6a35699

Please sign in to comment.