Skip to content

Commit

Permalink
feat: add job labels to support job attribution (#115) (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryashbhardwaj authored Aug 24, 2023
1 parent 2cac6c9 commit d08e19e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/scheduler/service/executor_input_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -36,6 +37,8 @@ const (
configDend = "DEND"
configExecutionTime = "EXECUTION_TIME"
configDestination = "JOB_DESTINATION"

JobAttributionLabelsKey = "JOB_LABELS"
)

type TenantService interface {
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions core/scheduler/service/executor_input_compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d08e19e

Please sign in to comment.