Skip to content

Commit

Permalink
improve watcher logs
Browse files Browse the repository at this point in the history
Signed-off-by: Satyam Bhardwaj <[email protected]>
  • Loading branch information
ramessesii2 authored and tekton-robot committed Oct 10, 2023
1 parent 0aa7ce4 commit e203c93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions pkg/watcher/reconciler/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, o results.Object) error {
timeTakenField := zap.Int64("results.tekton.dev/time-taken-ms", time.Since(startTime).Milliseconds())

if err != nil {
logger.Debugw("Error upserting record", zap.Error(err), timeTakenField)
logger.Debugw("Error upserting record to API server", zap.Error(err), timeTakenField)
return fmt.Errorf("error upserting record: %w", err)
}

Expand Down Expand Up @@ -150,10 +150,10 @@ func (r *Reconciler) addResultsAnnotations(ctx context.Context, o results.Object
// Update object with Result Annotations.
patch, err := annotation.Patch(o, annotations...)
if err != nil {
return fmt.Errorf("error adding Result annotations: %v", err)
return fmt.Errorf("error adding Result annotations: %w", err)
}
if err := r.objectClient.Patch(ctx, o.GetName(), types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
return fmt.Errorf("error patching object: %v", err)
return fmt.Errorf("error patching object: %w", err)
}
}
return nil
Expand Down Expand Up @@ -347,7 +347,7 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
defer cancel()
logsClient, err := r.resultsClient.UpdateLog(ctx)
if err != nil {
return fmt.Errorf("failed to create UpdateLog client: %v", err)
return fmt.Errorf("failed to create UpdateLog client: %w", err)
}

writer := logs.NewBufferedWriter(logsClient, logName, logs.DefaultBufferSize)
Expand All @@ -369,11 +369,11 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
},
})
if err != nil {
return fmt.Errorf("failed to create tkn reader: %v", err)
return fmt.Errorf("failed to create tkn reader: %w", err)
}
logChan, errChan, err := reader.Read()
if err != nil {
return fmt.Errorf("error reading from tkn reader: %v", err)
return fmt.Errorf("error reading from tkn reader: %w", err)
}

errChanRepeater := make(chan error)
Expand Down
15 changes: 8 additions & 7 deletions pkg/watcher/reconciler/pipelinerun/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ var _ knativereconciler.LeaderAware = (*Reconciler)(nil)
// Reconcile makes new watcher reconcile cycle to handle PipelineRun.
func (r *Reconciler) Reconcile(ctx context.Context, key string) error {
logger := logging.FromContext(ctx).With(zap.String("results.tekton.dev/kind", "PipelineRun"))
logger.Info("Reconciling PipelineRun")

namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
logger.Errorf("invalid resource key: %s", key)
logger.Errorf("Invalid resource key provided: %s. Skipping reconciliation.", key)
return nil
}

if !r.IsLeaderFor(types.NamespacedName{Namespace: namespace, Name: name}) {
logger.Debug("Skipping PipelineRun key because this instance isn't its leader")
logger.Debugf("Instance is not the leader for PipelineRun '%s/%s', skipping reconciliation.", namespace, name)
return controller.NewSkipKey(key)
}

logger.Infof("Initiating reconciliation for PipelineRun '%s/%s'", namespace, name)

pr, err := r.pipelineRunLister.PipelineRuns(namespace).Get(name)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -117,13 +118,13 @@ func (r *Reconciler) areAllUnderlyingTaskRunsReadyForDeletion(ctx context.Contex
// Let's assume that the TaskRun in
// question is gone and therefore, we
// can safely ignore it.
logger.Debugf("TaskRun %s/%s is no longer available - ignoring", pipelineRun.Namespace, reference.Name)
logger.Debugf("TaskRun %s/%s associated with PipelineRun %s is no longer available. Skipping.", pipelineRun.Namespace, reference.Name, pipelineRun.Name)
continue
}
return false, fmt.Errorf("error reading TaskRun from the indexer: %w", err)
}
if !isMarkedAsReadyForDeletion(taskRun) {
logger.Debugf("TaskRun %s/%s isn't yet ready to be deleted - the annotation %s is missing", taskRun.Namespace, taskRun.Name, resultsannotation.ChildReadyForDeletion)
logger.Debugf("TaskRun %s/%s associated with PipelineRun %s isn't yet ready to be deleted - the annotation %s is missing", taskRun.Namespace, taskRun.Name, pipelineRun.Name, resultsannotation.ChildReadyForDeletion)
return false, nil
}
}
Expand All @@ -138,13 +139,13 @@ func (r *Reconciler) areAllUnderlyingTaskRunsReadyForDeletion(ctx context.Contex
// Let's assume that the TaskRun in
// question is gone and therefore, we
// can safely ignore it.
logger.Debugf("TaskRun %s/%s is no longer available - ignoring", pipelineRun.Namespace, taskRunName)
logger.Debugf("TaskRun %s/%s associated with PipelineRun %s is no longer available. Skipping.", pipelineRun.Namespace, taskRunName, pipelineRun.Name)
continue
}
return false, fmt.Errorf("error reading TaskRun from the indexer: %w", err)
}
if !isMarkedAsReadyForDeletion(taskRun) {
logger.Debugf("TaskRun %s/%s isn't yet ready to be deleted - the annotation %s is missing", taskRun.Namespace, taskRun.Name, resultsannotation.ChildReadyForDeletion)
logger.Debugf("TaskRun %s/%s associated with PipelineRun %s isn't yet ready to be deleted - the annotation %s is missing", taskRun.Namespace, taskRunName, pipelineRun.Name, resultsannotation.ChildReadyForDeletion)
return false, nil
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/watcher/reconciler/taskrun/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ func (r *Reconciler) Reconcile(ctx context.Context, key string) error {

namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
logger.Errorf("invalid resource key: %s", key)
logger.Errorf("Received invalid resource key '%s', skipping reconciliation.", key)
return nil
}

if !r.IsLeaderFor(types.NamespacedName{Namespace: namespace, Name: name}) {
logger.Debug("Skipping TaskRun key because this instance isn't its leader")
logger.Debugf("Instance is not the leader for TaskRun '%s/%s', skipping reconciliation.", namespace, name)
return controller.NewSkipKey(key)
}

logger.Info("Reconciling TaskRun")
logger.Infof("Initiating reconciliation for TaskRun '%s/%s'", namespace, name)

tr, err := r.lister.TaskRuns(namespace).Get(name)
if err != nil {
if apierrors.IsNotFound(err) {
logger.Debug("Skipping key: object is no longer available")
logger.Debugf("TaskRun '%s/%s' is no longer available, skipping reconciliation.", namespace, name)
return controller.NewSkipKey(key)
}
return fmt.Errorf("error reading TaskRun from the indexer: %w", err)
return fmt.Errorf("error retrieving TaskRun '%s/%s' from indexer: %w", namespace, name, err)
}

taskRunClient := &dynamic.TaskRunClient{
Expand Down

0 comments on commit e203c93

Please sign in to comment.