Skip to content

Commit

Permalink
feat: Make logging more contextual
Browse files Browse the repository at this point in the history
  • Loading branch information
keskad committed Nov 3, 2023
1 parent 47a0973 commit 118955a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkgs/core/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (prp *PipelineRunProvider) fetchTaskRuns(ctx context.Context, pipelineRun *
}

// ReceivePipelineInfo is tracking tekton.dev/v1, kind: PipelineRun type objects
func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name string, namespace string) (contract.PipelineInfo, error) {
func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name string, namespace string, log *logging.InternalLogger) (contract.PipelineInfo, error) {
globalCfg := prp.confProvider.FetchGlobal("global")

pipelineRun, err := prp.client.PipelineRuns(namespace).Get(ctx, name, metav1.GetOptions{})
Expand Down Expand Up @@ -86,7 +86,7 @@ func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name st
}

// stages
stages, fetchErr := prp.collectStatus(ctx, pipelineRun)
stages, fetchErr := prp.collectStatus(ctx, pipelineRun, log)
if fetchErr != nil {
return contract.PipelineInfo{}, errors.Wrap(fetchErr, "cannot fetch stages list")
}
Expand All @@ -95,7 +95,7 @@ func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name st
globalCfg.Get("dashboard-url"), pipelineRun, pipelineRun.TypeMeta,
)
if dashboardTplErr != nil {
prp.logger.Warningf("Cannot render dashboard template URL '%s': '%s'", dashboardUrl, dashboardTplErr.Error())
log.Warningf("Cannot render dashboard template URL '%s': '%s'", dashboardUrl, dashboardTplErr.Error())
}

pi := contract.NewPipelineInfo(
Expand All @@ -112,7 +112,7 @@ func (prp *PipelineRunProvider) ReceivePipelineInfo(ctx context.Context, name st
)
return *pi, nil
}
func (prp *PipelineRunProvider) collectStatus(ctx context.Context, pipelineRun *v1.PipelineRun) ([]contract.PipelineStage, error) {
func (prp *PipelineRunProvider) collectStatus(ctx context.Context, pipelineRun *v1.PipelineRun, log *logging.InternalLogger) ([]contract.PipelineStage, error) {
// Collect all tasks in valid order
orderedTasks := make([]contract.PipelineStage, 0)

Expand Down Expand Up @@ -144,20 +144,20 @@ func (prp *PipelineRunProvider) collectStatus(ctx context.Context, pipelineRun *
for num, task := range orderedTasks {
taskRunName, exists := mapped[task.Name]
if !exists {
prp.logger.Debugf("TaskRun for task '%s' does not exist at all. Status = pending", task.Name)
log.Debugf("TaskRun for task '%s' does not exist at all. Status = pending", task.Name)
task.Status = contract.PipelinePending
continue
}

taskRun, taskRunExists := pipelineTasks[taskRunName]
if !taskRunExists {
prp.logger.Debugf("TaskRun %s does not exist. Status = pending", taskRunName)
log.Debugf("TaskRun %s does not exist. Status = pending", taskRunName)
task.Status = contract.PipelinePending
continue
}

orderedTasks[num].Status = translateTaskStatus(taskRun)
prp.logger.Debugf("TaskRun '%s' status '%s'", taskRunName, orderedTasks[num].Status)
log.Debugf("TaskRun '%s' status '%s'", taskRunName, orderedTasks[num].Status)
}
return orderedTasks, nil
}
Expand Down

0 comments on commit 118955a

Please sign in to comment.