-
Notifications
You must be signed in to change notification settings - Fork 141
Feat: better telemetry for cron execs #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b90084d
a5fd4e3
b61677e
59076ce
7c1f418
93b8b3d
7c1e687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ import ( | |
|
|
||
| var ( | ||
| LabelExecuteReadySchedules = "execute_ready_schedules" | ||
| LabelExecuteCronSchedule = "execute_cron_schedule" | ||
| LabelExecuteCronContract = "execute_cron_contract" | ||
| LabelScheduleCount = "schedule_count" | ||
| LabelScheduleExecutionsCount = "schedule_executions_count" | ||
|
|
||
|
|
@@ -67,13 +69,14 @@ func (k *Keeper) Logger(ctx sdk.Context) log.Logger { | |
| // ExecuteReadySchedules gets all schedules that are due for execution (with limit that is equal to Params.Limit) | ||
| // 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() | ||
| schedules := k.getSchedulesReadyForExecution(ctx, executionStage) | ||
|
|
||
| for _, schedule := range schedules { | ||
| err := k.executeSchedule(ctx, schedule) | ||
| recordExecutedSchedule(err, schedule) | ||
| } | ||
| telemetry.ModuleMeasureSince(types.ModuleName, startTime, LabelExecuteReadySchedules) | ||
|
||
| } | ||
|
|
||
| // AddSchedule adds a new schedule to be executed every certain number of blocks, specified in the `period`. | ||
|
|
@@ -182,12 +185,14 @@ func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context, executionStage t | |
| func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error { | ||
| // Even if contract execution returned an error, we still increase the height | ||
| // and execute it after this interval | ||
| startTimeSchedule := time.Now() | ||
| schedule.LastExecuteHeight = uint64(ctx.BlockHeight()) //nolint:gosec | ||
| k.storeSchedule(ctx, schedule) | ||
|
|
||
| cacheCtx, writeFn := ctx.CacheContext() | ||
|
|
||
| for idx, msg := range schedule.Msgs { | ||
| startTimeContract := time.Now() | ||
| executeMsg := wasmtypes.MsgExecuteContract{ | ||
| Sender: k.accountKeeper.GetModuleAddress(types.ModuleName).String(), | ||
| Contract: msg.Contract, | ||
|
|
@@ -205,8 +210,9 @@ func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error | |
| ) | ||
| return err | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case of error, you are missing both |
||
| } | ||
| telemetry.ModuleMeasureSince(types.ModuleName, startTimeContract, LabelExecuteCronContract, schedule.Name, msg.Contract) | ||
| } | ||
|
|
||
| telemetry.ModuleMeasureSince(types.ModuleName, startTimeSchedule, LabelExecuteCronSchedule, schedule.Name) | ||
| // only save state if all the messages in a schedule were executed successfully | ||
| writeFn() | ||
| return nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
startTimehere.Just calling an original method
telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules)viadeferresolves the initial problemThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Changed