-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Martin <[email protected]>
- Loading branch information
Showing
11 changed files
with
411 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,74 @@ | ||
package metrics | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
v1 "k8s.io/api/core/v1" | ||
|
||
"github.com/armadaproject/armada/internal/common/armadacontext" | ||
"github.com/armadaproject/armada/internal/scheduler/configuration" | ||
"github.com/armadaproject/armada/internal/scheduler/context" | ||
"github.com/armadaproject/armada/internal/scheduler/schedulerobjects" | ||
"github.com/armadaproject/armada/internal/scheduler/testfixtures" | ||
"github.com/armadaproject/armada/pkg/armadaevents" | ||
) | ||
|
||
func TestFoo(t *testing.T) { | ||
r, err := regexp.Compile("foo.*bar") | ||
func TestUpdate(t *testing.T) { | ||
ctx := armadacontext.Background() | ||
|
||
metrics, err := New(configuration.MetricsConfig{ | ||
TrackedErrorRegexes: nil, | ||
TrackedResourceNames: []v1.ResourceName{"cpu"}, | ||
ResetInterval: 24 * time.Hour, | ||
}) | ||
require.NoError(t, err) | ||
assert.True(t, r.MatchString("foobar")) | ||
assert.True(t, r.MatchString("foo bar")) | ||
assert.True(t, r.MatchString("foo and bar")) | ||
assert.True(t, r.MatchString("this is foo and bar so")) | ||
assert.False(t, r.MatchString("barfoo")) | ||
assert.False(t, r.MatchString("foo")) | ||
assert.False(t, r.MatchString("bar")) | ||
|
||
now := time.Now() | ||
|
||
queuedJob := testfixtures.NewJob(uuid.NewString(), | ||
"test-jobset", | ||
"test-queue", | ||
1, | ||
&schedulerobjects.JobSchedulingInfo{}, | ||
true, | ||
0, | ||
false, | ||
false, | ||
false, | ||
time.Now().UnixNano(), | ||
true) | ||
|
||
jobRunErrorsByRunId := map[uuid.UUID]*armadaevents.Error{ | ||
uuid.MustParse(queuedJob.Id()): { | ||
Terminal: true, | ||
Reason: &armadaevents.Error_PodError{ | ||
PodError: &armadaevents.PodError{ | ||
Message: "my error", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
leasedJob := queuedJob.WithNewRun("test-executor", "node1", "test-node", "test-pool", 1) | ||
pendingJob := leasedJob.WithUpdatedRun(leasedJob.LatestRun().WithPendingTime(addSeconds(now, 1))) | ||
runningJob := pendingJob.WithUpdatedRun(pendingJob.LatestRun().WithRunningTime(addSeconds(now, 2))) | ||
finishedJob := runningJob.WithUpdatedRun(runningJob.LatestRun().WithTerminatedTime(addSeconds(now, 3))) | ||
preemptedJob := finishedJob.WithUpdatedRun(runningJob.LatestRun().WithPreemptedTime(addSeconds(now, 4))) | ||
|
||
require.NoError(t, metrics.UpdateQueued(queuedJob)) | ||
require.NoError(t, metrics.UpdateLeased(context.JobSchedulingContextFromJob(leasedJob))) | ||
require.NoError(t, metrics.UpdatePending(pendingJob)) | ||
require.NoError(t, metrics.UpdateRunning(runningJob)) | ||
require.NoError(t, metrics.UpdateSucceeded(finishedJob)) | ||
require.NoError(t, metrics.UpdateCancelled(finishedJob)) | ||
require.NoError(t, metrics.UpdateFailed(ctx, finishedJob, jobRunErrorsByRunId)) | ||
require.NoError(t, metrics.UpdatePreempted(preemptedJob)) | ||
} | ||
|
||
func addSeconds(t time.Time, seconds int) *time.Time { | ||
t = t.Add(time.Duration(seconds) * time.Second) | ||
return &t | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.