Skip to content

Commit 16e61c9

Browse files
MryashbhardwajYash bhardwaj
andauthored
fix: add replay job config to replay dry run (#580)
* fix: add replay job config to replay dry run * fix: return task config as part of job replay config --------- Co-authored-by: Yash bhardwaj <yash.bhardwaj@gojek.com>
1 parent b95965a commit 16e61c9

10 files changed

Lines changed: 296 additions & 243 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ NAME = "github.com/goto/optimus"
55
LAST_COMMIT := $(shell git rev-parse --short HEAD)
66
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
77
OPMS_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
8-
PROTON_COMMIT := "0d8cde8f458ccf46ea3176b0265168091cc77e8b"
8+
PROTON_COMMIT := "bba736bdc93dabd74e2ce2ec155cee99692c0268"
99

1010

1111
.PHONY: build test test-ci generate-proto unit-test-ci integration-test vet coverage clean install lint

core/scheduler/handler/v1beta1/replay.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ReplayService interface {
2525
GetReplayByID(ctx context.Context, replayID uuid.UUID) (replay *scheduler.ReplayWithRun, err error)
2626
GetReplayByApprovalID(ctx context.Context, approvalID string) (*scheduler.ReplayWithRun, error)
2727
GetRunsStatus(ctx context.Context, tenant tenant.Tenant, jobName scheduler.JobName, config *scheduler.ReplayConfig) (runs []*scheduler.JobRunStatus, err error)
28+
GetJobConfig(ctx context.Context, tenant tenant.Tenant, jobName scheduler.JobName, config *scheduler.ReplayConfig) (map[string]string, error)
2829
CancelReplay(ctx context.Context, replayWithRun *scheduler.ReplayWithRun) error
2930
}
3031

@@ -61,8 +62,15 @@ func (h ReplayHandler) ReplayDryRun(ctx context.Context, req *pb.ReplayDryRunReq
6162
return nil, errors.GRPCErr(err, "unable to fetch runs status for "+req.JobName)
6263
}
6364

65+
jobConfig, err := h.service.GetJobConfig(ctx, replayReq.Tenant(), replayReq.JobName(), replayReq.Config())
66+
if err != nil {
67+
h.l.Error("error fetching runs status for replay dry run: %s", err)
68+
return nil, errors.GRPCErr(err, "unable to fetch runs status for "+req.JobName)
69+
}
70+
6471
return &pb.ReplayDryRunResponse{
6572
ReplayRuns: replayRunsToProto(runs),
73+
JobConfig: jobConfig,
6674
}, nil
6775
}
6876

core/scheduler/handler/v1beta1/replay_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func TestReplayHandler(t *testing.T) {
178178
}
179179

180180
service.On("GetRunsStatus", ctx, jobTenant, jobName, replayConfig).Return(runs, nil)
181+
service.On("GetJobConfig", ctx, jobTenant, jobName, replayConfig).Return(jobConfig, nil)
181182

182183
result, err := replayHandler.ReplayDryRun(ctx, req)
183184
assert.NoError(t, err)
@@ -778,8 +779,8 @@ func (_m *mockReplayService) CancelReplay(ctx context.Context, replayWithRun *sc
778779
return r0
779780
}
780781

781-
func (_m *mockReplayService) GetReplayConfig(ctx context.Context, projectName tenant.ProjectName, name scheduler.JobName, scheduledAt time.Time) (map[string]string, error) {
782-
args := _m.Called(ctx, projectName, name, scheduledAt)
782+
func (_m *mockReplayService) GetJobConfig(ctx context.Context, jobTenant tenant.Tenant, jobName scheduler.JobName, config *scheduler.ReplayConfig) (map[string]string, error) {
783+
args := _m.Called(ctx, jobTenant, jobName, config)
783784
if args.Get(0) == nil {
784785
return nil, args.Error(1)
785786
}

core/scheduler/service/executor_input_compiler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const (
5353

5454
var invalidLabelCharacterRegex *regexp.Regexp
5555

56+
var jobRunMode ctxContext = "run-mode"
57+
58+
type ctxContext string
59+
5660
type TenantService interface {
5761
GetDetails(ctx context.Context, tnnt tenant.Tenant) (*tenant.WithDetails, error)
5862
GetSecrets(ctx context.Context, tnnt tenant.Tenant) ([]*tenant.PlainTextSecret, error)
@@ -138,6 +142,7 @@ func (i InputCompiler) Compile(ctx context.Context, job *scheduler.JobWithDetail
138142
)
139143

140144
mergedContext := utils.MergeAnyMaps(taskContext, allTaskConfigs)
145+
ctx = context.WithValue(ctx, jobRunMode, scheduler.DryRun)
141146
fileMap, err := i.assetCompiler.CompileJobRunAssets(ctx, job.Job, systemDefinedVars, interval, mergedContext)
142147
if err != nil {
143148
i.logger.Error("error compiling job run assets: %s", err)

core/scheduler/service/executor_input_compiler_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestExecutorCompiler(t *testing.T) {
156156
templateCompiler.On("Compile", mock.Anything, taskContext).Return(map[string]string{}, nil)
157157
defer templateCompiler.AssertExpectations(t)
158158
assetCompiler := new(mockAssetCompiler)
159-
assetCompiler.On("CompileJobRunAssets", ctx, &job, systemDefinedVars, interval, taskContext).Return(nil, fmt.Errorf("CompileJobRunAssets error"))
159+
assetCompiler.On("CompileJobRunAssets", mock.Anything, &job, systemDefinedVars, interval, taskContext).Return(nil, fmt.Errorf("CompileJobRunAssets error"))
160160
defer assetCompiler.AssertExpectations(t)
161161

162162
inputCompiler := service.NewJobInputCompiler(tenantService, templateCompiler, assetCompiler, logger)
@@ -263,7 +263,7 @@ func TestExecutorCompiler(t *testing.T) {
263263
Return(map[string]string{"secret.config.compiled": "a.secret.val.compiled"}, nil)
264264
defer templateCompiler.AssertExpectations(t)
265265
assetCompiler := new(mockAssetCompiler)
266-
assetCompiler.On("CompileJobRunAssets", ctx, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
266+
assetCompiler.On("CompileJobRunAssets", mock.Anything, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
267267
defer assetCompiler.AssertExpectations(t)
268268
inputCompiler := service.NewJobInputCompiler(tenantService, templateCompiler, assetCompiler, logger)
269269
inputExecutorResp, err := inputCompiler.Compile(ctx, &details, config, executedAt, nil)
@@ -313,7 +313,7 @@ func TestExecutorCompiler(t *testing.T) {
313313
}
314314

315315
assetCompilerNew := new(mockAssetCompiler)
316-
assetCompilerNew.On("CompileJobRunAssets", ctx, &jobNew, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
316+
assetCompilerNew.On("CompileJobRunAssets", mock.Anything, &jobNew, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
317317
defer assetCompilerNew.AssertExpectations(t)
318318

319319
inputCompiler := service.NewJobInputCompiler(tenantService, templateCompiler, assetCompilerNew, logger)
@@ -408,7 +408,7 @@ func TestExecutorCompiler(t *testing.T) {
408408
"someFileName": "fileContents",
409409
}
410410
assetCompiler := new(mockAssetCompiler)
411-
assetCompiler.On("CompileJobRunAssets", ctx, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
411+
assetCompiler.On("CompileJobRunAssets", mock.Anything, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
412412
defer assetCompiler.AssertExpectations(t)
413413

414414
templateCompiler := new(mockTemplateCompiler)
@@ -507,7 +507,7 @@ func TestExecutorCompiler(t *testing.T) {
507507
"someFileName": "fileContents",
508508
}
509509
assetCompiler := new(mockAssetCompiler)
510-
assetCompiler.On("CompileJobRunAssets", ctx, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
510+
assetCompiler.On("CompileJobRunAssets", mock.Anything, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
511511
defer assetCompiler.AssertExpectations(t)
512512

513513
templateCompiler := new(mockTemplateCompiler)
@@ -579,7 +579,7 @@ func TestExecutorCompiler(t *testing.T) {
579579
"someFileName": "fileContents",
580580
}
581581
assetCompiler := new(mockAssetCompiler)
582-
assetCompiler.On("CompileJobRunAssets", ctx, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
582+
assetCompiler.On("CompileJobRunAssets", mock.Anything, &job, systemDefinedVars, interval, taskContext).Return(compiledFile, nil)
583583
defer assetCompiler.AssertExpectations(t)
584584

585585
templateCompiler := new(mockTemplateCompiler)

core/scheduler/service/replay_service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ReplayRepository interface {
4242
ScanAbandonedReplayRequests(ctx context.Context, unhandledClassifierDuration time.Duration) ([]*scheduler.Replay, error)
4343
AcquireReplayRequest(ctx context.Context, replayID uuid.UUID, unhandledClassifierDuration time.Duration) error
4444

45+
GetReplayJobConfig(ctx context.Context, jobTenant tenant.Tenant, jobName scheduler.JobName, scheduledAt time.Time) (map[string]string, error)
4546
GetReplayRequestByID(ctx context.Context, replayID uuid.UUID) (*scheduler.Replay, error)
4647

4748
GetReplayByFilters(ctx context.Context, projectName tenant.ProjectName, filters ...filter.FilterOpt) ([]*scheduler.ReplayWithRun, error)
@@ -192,6 +193,18 @@ func (r *ReplayService) GetReplayByApprovalID(ctx context.Context, approvalID st
192193
return replayWithRun, nil
193194
}
194195

196+
func (r *ReplayService) GetJobConfig(ctx context.Context, tenant tenant.Tenant, jobName scheduler.JobName, config *scheduler.ReplayConfig) (map[string]string, error) {
197+
details, err := r.jobRepo.GetJobDetails(ctx, tenant.ProjectName(), jobName)
198+
if err != nil {
199+
r.logger.Error("error getting job [%s]: %s", jobName, err)
200+
return nil, err
201+
}
202+
for k, v := range config.JobConfig {
203+
details.Job.Task.Config[k] = v
204+
}
205+
return details.Job.Task.Config, nil
206+
}
207+
195208
func (r *ReplayService) GetRunsStatus(ctx context.Context, tenant tenant.Tenant, jobName scheduler.JobName, config *scheduler.ReplayConfig) ([]*scheduler.JobRunStatus, error) {
196209
jobRunCriteria := &scheduler.JobRunsCriteria{
197210
Name: jobName.String(),

protos/gotocompany/optimus/core/v1beta1/job_run.pb.go

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/gotocompany/optimus/core/v1beta1/job_run.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@
750750
"NULL_VALUE"
751751
],
752752
"default": "NULL_VALUE",
753-
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\nThe JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
753+
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
754754
},
755755
"rpcStatus": {
756756
"type": "object",

0 commit comments

Comments
 (0)