Skip to content

Commit

Permalink
fix: keep things backward compatible for other deployments depending …
Browse files Browse the repository at this point in the history
…on the upgraded optimus server. (#629)
  • Loading branch information
sravankorumilli authored Oct 7, 2022
1 parent 4e125d0 commit 0ff5fe6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
8 changes: 6 additions & 2 deletions api/handler/v1beta1/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ func (sv *JobRunServiceServer) JobRun(ctx context.Context, req *pb.JobRunRequest
}

func (*JobRunServiceServer) GetWindow(_ context.Context, req *pb.GetWindowRequest) (*pb.GetWindowResponse, error) {
// TODO the default version to be deprecated & made mandatory in future releases
version := 1
if err := req.GetScheduledAt().CheckValid(); err != nil {
return nil, status.Errorf(codes.Internal, "%s: failed to parse schedule time %s", err.Error(), req.GetScheduledAt())
}

window, err := models.NewWindow(int(req.Version), req.GetTruncateTo(), req.GetOffset(), req.GetSize())
if req.Version != 0 {
version = int(req.Version)
}
window, err := models.NewWindow(version, req.GetTruncateTo(), req.GetOffset(), req.GetSize())
if err != nil {
return nil, err
}
Expand Down
53 changes: 52 additions & 1 deletion api/handler/v1beta1/job_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func TestJobRunServiceServer(t *testing.T) {
})

t.Run("GetWindow", func(t *testing.T) {
t.Run("should return the correct window date range", func(t *testing.T) {
t.Run("should return the correct window date range for version 1", func(t *testing.T) {
JobRunServiceServer := v1.NewJobRunServiceServer(
log,
nil, nil, nil, nil,
Expand All @@ -585,6 +585,57 @@ func TestJobRunServiceServer(t *testing.T) {
assert.Equal(t, "2020-11-11T00:00:00Z", resp.GetStart().AsTime().Format(time.RFC3339))
assert.Equal(t, "2020-11-12T00:00:00Z", resp.GetEnd().AsTime().Format(time.RFC3339))
})
t.Run("should fetch window date range for version 2", func(t *testing.T) {
JobRunServiceServer := v1.NewJobRunServiceServer(
log,
nil, nil, nil, nil,
nil,
nil,
nil,
monitoringService,
nil,
)

scheduledAt := time.Date(2020, 11, 11, 0, 0, 0, 0, time.UTC)
scheduledAtTimestamp := timestamppb.New(scheduledAt)
req := pb.GetWindowRequest{
ScheduledAt: scheduledAtTimestamp,
Version: 2,
Size: "24h",
Offset: "24h",
TruncateTo: "d",
}
resp, err := JobRunServiceServer.GetWindow(ctx, &req)
assert.Nil(t, err)

assert.Equal(t, "2020-11-11T00:00:00Z", resp.GetStart().AsTime().Format(time.RFC3339))
assert.Equal(t, "2020-11-12T00:00:00Z", resp.GetEnd().AsTime().Format(time.RFC3339))
})
t.Run("should ensure backward compatibility for previous fetch window configurations", func(t *testing.T) {
JobRunServiceServer := v1.NewJobRunServiceServer(
log,
nil, nil, nil, nil,
nil,
nil,
nil,
monitoringService,
nil,
)

scheduledAt := time.Date(2020, 11, 11, 0, 0, 0, 0, time.UTC)
scheduledAtTimestamp := timestamppb.New(scheduledAt)
req := pb.GetWindowRequest{
ScheduledAt: scheduledAtTimestamp,
Size: "24h",
Offset: "",
TruncateTo: "m",
}
resp, err := JobRunServiceServer.GetWindow(ctx, &req)
assert.Nil(t, err)

assert.Equal(t, "2020-11-10T00:00:00Z", resp.GetStart().AsTime().Format(time.RFC3339))
assert.Equal(t, "2020-11-11T00:00:00Z", resp.GetEnd().AsTime().Format(time.RFC3339))
})
})
t.Run("JobRun", func(t *testing.T) {
date, err := time.Parse(AirflowDateFormat, "2022-03-25T02:00:00+00:00")
Expand Down

0 comments on commit 0ff5fe6

Please sign in to comment.