From d08e19e6d2e735c2a548f20ea46df9d6c8ef2fe6 Mon Sep 17 00:00:00 2001 From: Yash Bhardwaj Date: Thu, 24 Aug 2023 09:47:43 +0530 Subject: [PATCH] feat: add job labels to support job attribution (#115) (#126) --- core/scheduler/service/executor_input_compiler.go | 10 ++++++++++ core/scheduler/service/executor_input_compiler_test.go | 1 + 2 files changed, 11 insertions(+) diff --git a/core/scheduler/service/executor_input_compiler.go b/core/scheduler/service/executor_input_compiler.go index 9ea1706048..556b2ed37a 100644 --- a/core/scheduler/service/executor_input_compiler.go +++ b/core/scheduler/service/executor_input_compiler.go @@ -2,6 +2,7 @@ package service import ( "context" + "fmt" "strings" "time" @@ -36,6 +37,8 @@ const ( configDend = "DEND" configExecutionTime = "EXECUTION_TIME" configDestination = "JOB_DESTINATION" + + JobAttributionLabelsKey = "JOB_LABELS" ) type TenantService interface { @@ -92,6 +95,13 @@ func (i InputCompiler) Compile(ctx context.Context, job *scheduler.Job, config s return nil, err } + jobAttributionLabels := fmt.Sprintf("project=%s,namespace=%s,job=%s", job.Tenant.ProjectName(), job.Tenant.NamespaceName(), job.Name) + if jobLables, ok := confs[JobAttributionLabelsKey]; ok { + confs[JobAttributionLabelsKey] = jobLables + "," + jobAttributionLabels + } else { + confs[JobAttributionLabelsKey] = jobAttributionLabels + } + if config.Executor.Type == scheduler.ExecutorTask { return &scheduler.ExecutorInput{ Configs: utils.MergeMaps(confs, systemDefinedVars), diff --git a/core/scheduler/service/executor_input_compiler_test.go b/core/scheduler/service/executor_input_compiler_test.go index 4f72ae263e..f458510d5c 100644 --- a/core/scheduler/service/executor_input_compiler_test.go +++ b/core/scheduler/service/executor_input_compiler_test.go @@ -228,6 +228,7 @@ func TestExecutorCompiler(t *testing.T) { "EXECUTION_TIME": executedAt.Format(time.RFC3339), "JOB_DESTINATION": job.Destination, "some.config.compiled": "val.compiled", + "JOB_LABELS": "project=proj1,namespace=ns1,job=job1", }, Secrets: map[string]string{"secret.config.compiled": "a.secret.val.compiled"}, Files: compiledFile,