Skip to content

Commit

Permalink
fix(sdk): hatchery step log delay numeric (#6456)
Browse files Browse the repository at this point in the history
Signed-off-by: richardlt <[email protected]>
  • Loading branch information
richardlt authored Feb 14, 2023
1 parent 55071aa commit 38c942a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sdk/hatchery/hatchery.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ func SendSpawnInfo(ctx context.Context, h Interface, jobID int64, spawnMsg sdk.S

func logStepInfo(ctx context.Context, step string, queued time.Time) {
if id := ctx.Value(LogFieldJobID); id != nil {
ctx = context.WithValue(ctx, LogFieldJobStep, step)
ctx = context.WithValue(ctx, LogFieldJobStepDelay, time.Since(queued).Milliseconds())
ctx = context.WithValue(ctx, LogFieldStep, step)
ctx = context.WithValue(ctx, LogFieldStepDelay, time.Since(queued).Nanoseconds())
log.Info(ctx, "step: %s job: %s", step, id)
}
}
8 changes: 8 additions & 0 deletions sdk/hatchery/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ func spawnWorkerForJob(ctx context.Context, h Interface, j workerStarterRequest)
ctx = context.WithValue(ctx, LogFieldWorkflow, arg.WorkflowName)
ctx = context.WithValue(ctx, LogFieldNodeRun, arg.NodeRunName)

var serviceCount int
for i := range arg.Requirements {
if arg.Requirements[i].Type == sdk.ServiceRequirement {
serviceCount++
}
}
ctx = context.WithValue(ctx, LogFieldServiceCount, serviceCount)

// Get a JWT to authentified the worker
jwt, err := NewWorkerToken(h.Service().Name, h.GetPrivateKey(), time.Now().Add(1*time.Hour), arg)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions sdk/hatchery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ const (

var (
LogFieldJobID = log.Field("action_metadata_job_id")
LogFieldJobStep = log.Field("hatchery_job_step")
LogFieldJobStepDelay = log.Field("hatchery_job_step_delay")
LogFieldStep = log.Field("hatchery_step")
LogFieldStepDelay = log.Field("hatchery_step_delay_num")
LogFieldProjectID = log.Field("worker_project_id")
LogFieldProject = log.Field("worker_project")
LogFieldWorkflow = log.Field("worker_workflow")
LogFieldNodeRunID = log.Field("worker_node_run_id")
LogFieldNodeRun = log.Field("worker_node_run")
LogFieldModel = log.Field("worker_model")
LogFieldServiceCount = log.Field("worker_service_count")
LogFieldServiceCount = log.Field("worker_service_count_num")
)

func init() {
log.RegisterField(LogFieldJobID)
log.RegisterField(LogFieldJobStep)
log.RegisterField(LogFieldJobStepDelay)
log.RegisterField(LogFieldStep)
log.RegisterField(LogFieldStepDelay)
log.RegisterField(LogFieldProjectID)
log.RegisterField(LogFieldProject)
log.RegisterField(LogFieldWorkflow)
Expand Down

0 comments on commit 38c942a

Please sign in to comment.