Skip to content

Feat: better telemetry for cron execs#861

Merged
pr0n00gler merged 7 commits intomainfrom
feat/cron_telemetry
Jun 2, 2025
Merged

Feat: better telemetry for cron execs#861
pr0n00gler merged 7 commits intomainfrom
feat/cron_telemetry

Conversation

@jcompagni10
Copy link
Contributor

fix how timing is reported for cron execution

Comment on lines 72 to 79
startTime := time.Now()
schedules := k.getSchedulesReadyForExecution(ctx, executionStage)

for _, schedule := range schedules {
err := k.executeSchedule(ctx, schedule)
recordExecutedSchedule(err, schedule)
}
telemetry.ModuleMeasureSince(types.ModuleName, startTime, LabelExecuteReadySchedules)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just adding defer resolves the problem and it's more cleaner from my perspective (Cosmos SDK uses defer as well):
https://go.dev/play/p/Eof5hpEyxQX

pr0n00gler
pr0n00gler previously approved these changes Mar 18, 2025
@@ -205,8 +210,9 @@ func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error
)
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of error, you are missing both telemetry.ModuleMeasureSince calls, it's better to use defer

// and executes messages in each one
func (k *Keeper) ExecuteReadySchedules(ctx sdk.Context, executionStage types.ExecutionStage) {
telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules)
startTime := time.Now()
Copy link
Collaborator

@pr0n00gler pr0n00gler Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why do you need a separate variable startTime here.

Just calling an original method telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules) via defer resolves the initial problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Changed

@jcompagni10
Copy link
Contributor Author

)
return err
}
defer telemetry.ModuleMeasureSince(types.ModuleName, startTimeContract, LabelExecuteCronContract, schedule.Name, msg.Contract)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, suppose we have two schedules:A and B. A gets called first, B is second.
Doesn't this defer call mean, that a measurement for A call contains a time consumption of the B call?
Because the ModuleMeasureSince is called only in the end of the whole execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resloved

@pr0n00gler pr0n00gler merged commit 167ad81 into main Jun 2, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants