Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Remove gogo proto from simulator definitions #4151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/common/proto/protoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ func ToStdDuration(pd *types.Duration) time.Duration {
}
return time.Duration(pd.Seconds)*time.Second + time.Duration(pd.Nanos)*time.Nanosecond
}

func ToDuration(d time.Duration) *types.Duration {
return &types.Duration{
Seconds: d.Nanoseconds() / 1000000000,
Nanos: int32(d.Nanoseconds() % 1000000000),
}
}
5 changes: 3 additions & 2 deletions internal/scheduler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/armadaproject/armada/internal/common/compress"
"github.com/armadaproject/armada/internal/common/logging"
"github.com/armadaproject/armada/internal/common/maps"
protoutil "github.com/armadaproject/armada/internal/common/proto"
"github.com/armadaproject/armada/internal/common/pulsarutils"
priorityTypes "github.com/armadaproject/armada/internal/common/types"
"github.com/armadaproject/armada/internal/scheduler/database"
Expand Down Expand Up @@ -370,7 +371,7 @@ func (srv *ExecutorApi) executorFromLeaseRequest(ctx *armadacontext.Context, req
nodes := make([]*schedulerobjects.Node, 0, len(req.Nodes))
now := srv.clock.Now().UTC()
for _, nodeInfo := range req.Nodes {
if node, err := executorapi.NewNodeFromNodeInfo(nodeInfo, req.ExecutorId, srv.allowedPriorities, now); err != nil {
if node, err := executorapi.NewNodeFromNodeInfo(nodeInfo, req.ExecutorId, srv.allowedPriorities, protoutil.ToTimestamp(now)); err != nil {
logging.WithStacktrace(ctx, err).Warnf(
"skipping node %s from executor %s", nodeInfo.GetName(), req.GetExecutorId(),
)
Expand All @@ -382,7 +383,7 @@ func (srv *ExecutorApi) executorFromLeaseRequest(ctx *armadacontext.Context, req
Id: req.ExecutorId,
Pool: req.Pool,
Nodes: nodes,
LastUpdateTime: now,
LastUpdateTime: protoutil.ToTimestamp(now),
UnassignedJobRuns: req.UnassignedJobRunIds,
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/scheduler/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func TestExecutorApi_LeaseJobRuns(t *testing.T) {
Resources: nil,
},
},
LastSeen: testClock.Now().UTC(),
LastSeen: protoutil.ToTimestamp(testClock.Now()),
ReportingNodeType: "node-type-1",
},
},
LastUpdateTime: testClock.Now().UTC(),
LastUpdateTime: protoutil.ToTimestamp(testClock.Now()),
UnassignedJobRuns: []string{runId3},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/scheduler/database/executor_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *PostgresExecutorRepository) StoreExecutor(ctx *armadacontext.Context, e
err = queries.UpsertExecutor(ctx, UpsertExecutorParams{
ExecutorID: executor.Id,
LastRequest: compressed,
UpdateTime: executor.LastUpdateTime,
UpdateTime: protoutil.ToStdTime(executor.LastUpdateTime),
})
if err != nil {
return errors.WithStack(err)
Expand Down
14 changes: 8 additions & 6 deletions internal/scheduler/database/executor_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"golang.org/x/exp/slices"

"github.com/armadaproject/armada/internal/common/armadacontext"
protoutil "github.com/armadaproject/armada/internal/common/proto"
"github.com/armadaproject/armada/internal/scheduler/schedulerobjects"
)

func TestExecutorRepository_LoadAndSave(t *testing.T) {
t1 := time.Now().UTC().Round(1 * time.Microsecond) // postgres only stores times with micro precision

tests := map[string]struct {
executors []*schedulerobjects.Executor
}{
Expand All @@ -26,10 +28,10 @@ func TestExecutorRepository_LoadAndSave(t *testing.T) {
Nodes: []*schedulerobjects.Node{
{
Id: "test-node-1",
LastSeen: t1,
LastSeen: protoutil.ToTimestamp(t1),
},
},
LastUpdateTime: t1,
LastUpdateTime: protoutil.ToTimestamp(t1),
UnassignedJobRuns: []string{"run1", "run2"},
},
{
Expand All @@ -38,10 +40,10 @@ func TestExecutorRepository_LoadAndSave(t *testing.T) {
Nodes: []*schedulerobjects.Node{
{
Id: "test-node-2",
LastSeen: t1,
LastSeen: protoutil.ToTimestamp(t1),
},
},
LastUpdateTime: t1,
LastUpdateTime: protoutil.ToTimestamp(t1),
UnassignedJobRuns: []string{"run3", "run4"},
},
},
Expand Down Expand Up @@ -95,11 +97,11 @@ func TestExecutorRepository_GetLastUpdateTimes(t *testing.T) {
executors: []*schedulerobjects.Executor{
{
Id: "test-executor-1",
LastUpdateTime: t1,
LastUpdateTime: protoutil.ToTimestamp(t1),
},
{
Id: "test-executor-2",
LastUpdateTime: t2,
LastUpdateTime: protoutil.ToTimestamp(t2),
},
},
expectedUpdateTimes: map[string]time.Time{"test-executor-1": t1, "test-executor-2": t2},
Expand Down
10 changes: 3 additions & 7 deletions internal/scheduler/jobdb/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jobdb

import (
"fmt"
"time"

"github.com/gogo/protobuf/proto"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -398,12 +397,9 @@ func (job *Job) SchedulingKey() schedulerobjects.SchedulingKey {
return job.schedulingKey
}

// SubmitTime exists for compatibility with the LegacyJob interface.
func (job *Job) SubmitTime() time.Time {
if job.jobSchedulingInfo == nil {
return time.Time{}
}
return job.jobSchedulingInfo.SubmitTime
// SubmitTime returns the time the job was submitted in nanos since the epoch
func (job *Job) SubmitTime() int64 {
return job.submittedTime
}

// RequestedPriority returns the requested priority of the job.
Expand Down
Loading
Loading