Skip to content

Commit

Permalink
TEP-0121: Rewrite metric recorder for TaskRun Retries
Browse files Browse the repository at this point in the history
Prior to this commit, metrics recording durationAndCountMetrics()
is in reconcile() (instead of ReconcileKind()), which only counts
the taskrun numbers where the taskruns that have no preparation
error / not cancelled right after scheduled / not timed out before
calling reconcile() (for example, be pending for a long time.).

This commit moves durationAndCountMetrics() into ReconcileKind()
to address the issue above.

It's worth mentioning that the recording metrics logic was
originally in the ReconcileKind() function, but the commit 1375219,
aming at addressing the recount issue, **moves that logic to `reconcile()`**
[1] (probably for better code style? 🤔).

[1] 1375219#diff-6e67e9c647bbe2a08807ff5ccbdd7dc9036df373e56b9774d3996f92ab7ceabaL138-L145
  • Loading branch information
XinruZhang committed Dec 13, 2022
1 parent 22d197e commit caad78b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ func (tr *TaskRun) HasStarted() bool {
return tr.Status.StartTime != nil && !tr.Status.StartTime.IsZero()
}

func (tr *TaskRun) ToBeRetried() bool {
cond := tr.GetStatusCondition().GetCondition(apis.ConditionSucceeded)
return cond != nil && cond.Reason == tr.ToBeRetried()
}

// IsSuccessful returns true if the TaskRun's status indicates that it is done.
func (tr *TaskRun) IsSuccessful() bool {
return tr != nil && tr.Status.GetCondition(apis.ConditionSucceeded).IsTrue()
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
// error but it does not sync updates back to etcd. It does not emit events.
// `reconcile` consumes spec and resources returned by `prepare`
func (c *Reconciler) reconcile(ctx context.Context, tr *v1beta1.TaskRun, rtr *resources.ResolvedTaskResources) error {
// TODO: separate start time out.
defer c.durationAndCountMetrics(ctx, tr)
logger := logging.FromContext(ctx)
recorder := controller.GetEventRecorder(ctx)
Expand Down

0 comments on commit caad78b

Please sign in to comment.