Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chasm/lib/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@
// waiting portion (those not yet surfaced via RecentActions) counts as buffered.
info.BufferSize = int64(len(invoker.GetBufferedStarts()) - len(info.RecentActions))

executionInfo := ctx.ExecutionInfo()
info.StateSizeBytes = int64(executionInfo.ApproximateStateSize)

Check failure on line 636 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / govulncheck

info.StateSizeBytes undefined (type *"go.temporal.io/api/schedule/v1".ScheduleInfo has no field or method StateSizeBytes)

Check failure on line 636 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / golangci

info.StateSizeBytes undefined (type *"go.temporal.io/api/schedule/v1".ScheduleInfo has no field or method StateSizeBytes)

Check failure on line 636 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / fmt

info.StateSizeBytes undefined (type *"go.temporal.io/api/schedule/v1".ScheduleInfo has no field or method StateSizeBytes)

Check failure on line 636 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / fmt

info.StateSizeBytes undefined (type *"go.temporal.io/api/schedule/v1".ScheduleInfo has no field or method StateSizeBytes)

Check failure on line 636 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / Pre-build for cache

info.StateSizeBytes undefined (type *"go.temporal.io/api/schedule/v1".ScheduleInfo has no field or method StateSizeBytes)

return &schedulerpb.DescribeScheduleResponse{
FrontendResponse: &workflowservice.DescribeScheduleResponse{
Schedule: schedule,
Expand Down Expand Up @@ -911,6 +914,7 @@
ctx chasm.Context,
) *schedulepb.ScheduleListInfo {
spec := common.CloneProto(s.Schedule.Spec)
executionInfo := ctx.ExecutionInfo()

// Clear fields that are too large/not useful for the list view.
spec.TimezoneData = nil
Expand All @@ -930,6 +934,7 @@
Paused: s.Schedule.State.Paused,
RecentActions: invoker.recentActions(),
FutureActionTimes: generator.FutureActionTimes,
StateSizeBytes: int64(executionInfo.ApproximateStateSize),

Check failure on line 937 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / govulncheck

unknown field StateSizeBytes in struct literal of type "go.temporal.io/api/schedule/v1".ScheduleListInfo

Check failure on line 937 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / golangci

unknown field StateSizeBytes in struct literal of type "go.temporal.io/api/schedule/v1".ScheduleListInfo (typecheck)

Check failure on line 937 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / fmt

unknown field StateSizeBytes in struct literal of type "go.temporal.io/api/schedule/v1".ScheduleListInfo

Check failure on line 937 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / fmt

unknown field StateSizeBytes in struct literal of type "go.temporal.io/api/schedule/v1".ScheduleListInfo

Check failure on line 937 in chasm/lib/scheduler/scheduler.go

View workflow job for this annotation

GitHub Actions / Pre-build for cache

unknown field StateSizeBytes in struct literal of type "go.temporal.io/api/schedule/v1".ScheduleListInfo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

describe response makes sense but why do we want to include it in the vis memo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because that's how Metering plans to consume the data, versus doing O(n) queries for each execution. They presently use ListWorkflowExecutions and go off of the metadata within for this purpose.

}
}

Expand Down
49 changes: 49 additions & 0 deletions tests/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestScheduleCHASM(t *testing.T) {
t.Run("TestSkipsWorkflowSentinelWhenDisabled", func(t *testing.T) { testSkipsWorkflowSentinelWhenDisabled(t, newContext) })
t.Run("TestUpdateScheduleMemo", func(t *testing.T) { testUpdateScheduleMemo(t, newContext) })
t.Run("TestUpdateScheduleMemoOnly", func(t *testing.T) { testUpdateScheduleMemoOnly(t, newContext) })
t.Run("TestStateSizeBytesReported", func(t *testing.T) { testStateSizeBytesReported(t, newContext) })
}

func TestScheduleV1(t *testing.T) {
Expand Down Expand Up @@ -1821,6 +1822,54 @@ func testCreatesWorkflowSentinel(t *testing.T, newContext contextFactory) {
s.Equal(int64(1), countResp.Count)
}

func testStateSizeBytesReported(t *testing.T, newContext contextFactory) {
s := testcore.NewEnv(t, scheduleCommonOpts()...)

sid := testcore.RandomizeStr("sched-state-size")
wid := testcore.RandomizeStr("sched-state-size-wf")
wt := testcore.RandomizeStr("sched-state-size-wt")

schedule := &schedulepb.Schedule{
Spec: &schedulepb.ScheduleSpec{
Interval: []*schedulepb.IntervalSpec{
{Interval: durationpb.New(1 * time.Hour)},
},
},
Action: &schedulepb.ScheduleAction{
Action: &schedulepb.ScheduleAction_StartWorkflow{
StartWorkflow: &workflowpb.NewWorkflowExecutionInfo{
WorkflowId: wid,
WorkflowType: &commonpb.WorkflowType{Name: wt},
TaskQueue: &taskqueuepb.TaskQueue{Name: s.WorkerTaskQueue(), Kind: enumspb.TASK_QUEUE_KIND_NORMAL},
},
},
},
State: &schedulepb.ScheduleState{Paused: true},
}

ctx := newContext(s.Context())
_, err := s.FrontendClient().CreateSchedule(ctx, &workflowservice.CreateScheduleRequest{
Namespace: s.Namespace().String(),
ScheduleId: sid,
Schedule: schedule,
Identity: "test",
RequestId: uuid.NewString(),
})
s.NoError(err)

desc, err := s.FrontendClient().DescribeSchedule(ctx, &workflowservice.DescribeScheduleRequest{
Namespace: s.Namespace().String(),
ScheduleId: sid,
})
s.NoError(err)
s.Positive(desc.GetInfo().GetStateSizeBytes(), "Describe should report a non-zero StateSizeBytes")

entry := getScheduleEntryFromVisibility(s, sid, newContext, func(e *schedulepb.ScheduleListEntry) bool {
return e.GetInfo().GetStateSizeBytes() > 0
})
s.Positive(entry.GetInfo().GetStateSizeBytes(), "ListSchedules entry should report a non-zero StateSizeBytes")
}

// testCreatesCHASMSentinel tests that creating a V1 schedule also creates a
// CHASM sentinel to reserve the schedule ID in the CHASM execution space.
func testCreatesCHASMSentinel(t *testing.T, newContext contextFactory) {
Expand Down
Loading