Skip to content
Merged
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
10 changes: 10 additions & 0 deletions client/frontend/client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions client/frontend/metric_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions client/frontend/retryable_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/api/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var (
"ListScheduleMatchingTimes": {Scope: ScopeNamespace, Access: AccessReadOnly, Polling: PollingNone},
"DeleteSchedule": {Scope: ScopeNamespace, Access: AccessWrite, Polling: PollingNone},
"ListSchedules": {Scope: ScopeNamespace, Access: AccessReadOnly, Polling: PollingNone},
"CountSchedules": {Scope: ScopeNamespace, Access: AccessReadOnly, Polling: PollingNone},
"UpdateWorkerBuildIdCompatibility": {Scope: ScopeNamespace, Access: AccessWrite, Polling: PollingNone},
"GetWorkerBuildIdCompatibility": {Scope: ScopeNamespace, Access: AccessReadOnly, Polling: PollingNone},
"UpdateWorkerVersioningRules": {Scope: ScopeNamespace, Access: AccessWrite, Polling: PollingNone},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/rpc/interceptor/redirection.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var (
"PatchSchedule": func() any { return &workflowservice.PatchScheduleResponse{} },
"DeleteSchedule": func() any { return &workflowservice.DeleteScheduleResponse{} },
"ListSchedules": func() any { return &workflowservice.ListSchedulesResponse{} },
"CountSchedules": func() any { return &workflowservice.CountSchedulesResponse{} },
"ListScheduleMatchingTimes": func() any { return &workflowservice.ListScheduleMatchingTimesResponse{} },
"UpdateWorkerBuildIdCompatibility": func() any { return &workflowservice.UpdateWorkerBuildIdCompatibilityResponse{} },
"GetWorkerBuildIdCompatibility": func() any { return &workflowservice.GetWorkerBuildIdCompatibilityResponse{} },
Expand Down
1 change: 1 addition & 0 deletions common/rpc/interceptor/redirection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (s *redirectionInterceptorSuite) TestGlobalAPI() {
"PatchSchedule": {},
"DeleteSchedule": {},
"ListSchedules": {},
"CountSchedules": {},
"ListScheduleMatchingTimes": {},
"UpdateWorkerBuildIdCompatibility": {},
"GetWorkerBuildIdCompatibility": {},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/sdk/metric v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
go.temporal.io/api v1.61.1-0.20260123144430-3418f5100388
go.temporal.io/api v1.61.1-0.20260128230845-c246540cf2ed
go.temporal.io/sdk v1.38.0
go.uber.org/fx v1.24.0
go.uber.org/mock v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
go.temporal.io/api v1.61.1-0.20260123144430-3418f5100388 h1:Rahqpgjqalbv28RLoOtnNNZvwtnes/sQP0+cisO70Hw=
go.temporal.io/api v1.61.1-0.20260123144430-3418f5100388/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
go.temporal.io/api v1.61.1-0.20260128230845-c246540cf2ed h1:g3CgsK5BXL2rQy0ZIJVRpNUDdtPM1y4bGv5ZoKsqR74=
go.temporal.io/api v1.61.1-0.20260128230845-c246540cf2ed/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
go.temporal.io/sdk v1.38.0 h1:4Bok5LEdED7YKpsSjIa3dDqram5VOq+ydBf4pyx0Wo4=
go.temporal.io/sdk v1.38.0/go.mod h1:a+R2Ej28ObvHoILbHaxMyind7M6D+W0L7edt5UJF4SE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down
1 change: 1 addition & 0 deletions service/frontend/configs/quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ var (
// APIs that rely on visibility
"/temporal.api.workflowservice.v1.WorkflowService/GetWorkerTaskReachability": 1,
"/temporal.api.workflowservice.v1.WorkflowService/ListSchedules": 1,
"/temporal.api.workflowservice.v1.WorkflowService/CountSchedules": 1,
"/temporal.api.workflowservice.v1.WorkflowService/ListBatchOperations": 1,
"/temporal.api.workflowservice.v1.WorkflowService/DescribeTaskQueueWithReachability": 1, // note this isn't a real method name
"/temporal.api.workflowservice.v1.WorkflowService/ListDeployments": 1,
Expand Down
1 change: 1 addition & 0 deletions service/frontend/configs/quotas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *quotasSuite) TestVisibilityAPIs() {

"/temporal.api.workflowservice.v1.WorkflowService/GetWorkerTaskReachability": {},
"/temporal.api.workflowservice.v1.WorkflowService/ListSchedules": {},
"/temporal.api.workflowservice.v1.WorkflowService/CountSchedules": {},
"/temporal.api.workflowservice.v1.WorkflowService/ListBatchOperations": {},
"/temporal.api.workflowservice.v1.WorkflowService/DescribeTaskQueueWithReachability": {},
"/temporal.api.workflowservice.v1.WorkflowService/ListDeployments": {},
Expand Down
135 changes: 124 additions & 11 deletions service/frontend/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4437,7 +4437,25 @@ func (wh *WorkflowHandler) ListSchedules(
}

chasmEnabled := wh.chasmSchedulerEnabled(ctx, namespaceName.String())
query, err := wh.prepareSchedulerQuery(chasmEnabled, request.Query, namespaceName)
if err != nil {
return nil, err
}

if chasmEnabled {
// CHASM ListSchedules will include schedules created in the V1/workflow stack.
return wh.listSchedulesChasm(ctx, request, namespaceName, namespaceID, query)
}
return wh.listSchedulesWorkflow(ctx, request, namespaceName, namespaceID, query)
}

// prepareSchedulerQuery validates a scheduler RPC's query argument, and wraps it
// in the appropriate base query.
func (wh *WorkflowHandler) prepareSchedulerQuery(
chasmEnabled bool,
query string,
namespaceName namespace.Name,
) (string, error) {
// Use different base queries based on code path:
// - CHASM path uses TemporalSystemExecutionStatus (translated via archetype ID)
// - V1 path uses ExecutionStatus directly (no archetype ID available)
Expand All @@ -4446,29 +4464,27 @@ func (wh *WorkflowHandler) ListSchedules(
baseQuery = scheduler.VisibilityListQueryChasm
}

query := baseQuery
if strings.TrimSpace(request.Query) != "" {
result := baseQuery
if strings.TrimSpace(query) != "" {
saNameType, err := wh.saProvider.GetSearchAttributes(wh.visibilityMgr.GetIndexName(), false)
if err != nil {
return nil, serviceerror.NewUnavailablef(errUnableToGetSearchAttributesMessage, err)
return "", serviceerror.NewUnavailablef(errUnableToGetSearchAttributesMessage, err)
}

if err := scheduler.ValidateVisibilityQuery(
namespaceName,
saNameType,
wh.saMapperProvider,
wh.config.VisibilityEnableUnifiedQueryConverter,
request.Query,
query,
); err != nil {
return nil, err
return "", err
}
query = fmt.Sprintf("%s AND (%s)", baseQuery, request.Query)
}

if chasmEnabled {
// CHASM ListSchedules will include schedules created in the V1/workflow stack.
return wh.listSchedulesChasm(ctx, request, namespaceName, namespaceID, query)
result = fmt.Sprintf("%s AND (%s)", baseQuery, query)
}
return wh.listSchedulesWorkflow(ctx, request, namespaceName, namespaceID, query)

return result, nil
}

func (wh *WorkflowHandler) listSchedulesChasm(
Expand Down Expand Up @@ -4565,6 +4581,103 @@ func (wh *WorkflowHandler) listSchedulesWorkflow(
}, nil
}

func (wh *WorkflowHandler) CountSchedules(
ctx context.Context,
request *workflowservice.CountSchedulesRequest,
) (_ *workflowservice.CountSchedulesResponse, retError error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of including the underscore here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because you need to name both arguments if you name one of them, and yet I never assign to the first return argument, so instead it is bound to "unused"/_.

defer log.CapturePanic(wh.logger, &retError)

if request == nil {
return nil, errRequestNotSet
}

if !wh.config.EnableSchedules(request.Namespace) {
return nil, errSchedulesNotAllowed
}

namespaceName := namespace.Name(request.GetNamespace())
namespaceID, err := wh.namespaceRegistry.GetNamespaceID(namespaceName)
if err != nil {
return nil, err
}

if wh.config.DisableListVisibilityByFilter(namespaceName.String()) {
return nil, errListNotAllowed
}

chasmEnabled := wh.chasmSchedulerEnabled(ctx, namespaceName.String())
query, err := wh.prepareSchedulerQuery(chasmEnabled, request.Query, namespaceName)
if err != nil {
return nil, err
}

// Route to CHASM or V1 based on config (same pattern as ListSchedules)
if chasmEnabled {
return wh.countSchedulesChasm(ctx, namespaceID, namespaceName, query)
}
return wh.countSchedulesWorkflow(ctx, namespaceID, namespaceName, query)
}

// countSchedulesChasm counts schedules using CHASM APIs
func (wh *WorkflowHandler) countSchedulesChasm(
ctx context.Context,
namespaceID namespace.ID,
namespaceName namespace.Name,
query string,
) (*workflowservice.CountSchedulesResponse, error) {
resp, err := chasm.CountExecutions[*chasmscheduler.Scheduler](ctx, &chasm.CountExecutionsRequest{
NamespaceID: namespaceID.String(),
NamespaceName: namespaceName.String(),
Query: query,
})
if err != nil {
return nil, err
}

groups := make([]*workflowservice.CountSchedulesResponse_AggregationGroup, 0, len(resp.Groups))
for _, g := range resp.Groups {
groups = append(groups, &workflowservice.CountSchedulesResponse_AggregationGroup{
GroupValues: g.Values,
Count: g.Count,
})
}

return &workflowservice.CountSchedulesResponse{
Count: resp.Count,
Groups: groups,
}, nil
}

// countSchedulesWorkflow counts schedules using direct visibility query (V1 path)
func (wh *WorkflowHandler) countSchedulesWorkflow(
ctx context.Context,
namespaceID namespace.ID,
namespaceName namespace.Name,
query string,
) (*workflowservice.CountSchedulesResponse, error) {
persistenceResp, err := wh.visibilityMgr.CountWorkflowExecutions(ctx, &manager.CountWorkflowExecutionsRequest{
NamespaceID: namespaceID,
Namespace: namespaceName,
Query: query,
})
if err != nil {
return nil, err
}

groups := make([]*workflowservice.CountSchedulesResponse_AggregationGroup, 0, len(persistenceResp.Groups))
for _, g := range persistenceResp.Groups {
groups = append(groups, &workflowservice.CountSchedulesResponse_AggregationGroup{
GroupValues: g.GroupValues,
Count: g.Count,
})
}

return &workflowservice.CountSchedulesResponse{
Count: persistenceResp.Count,
Groups: groups,
}, nil
}

func (wh *WorkflowHandler) UpdateWorkflowExecution(
ctx context.Context,
request *workflowservice.UpdateWorkflowExecutionRequest,
Expand Down
Loading
Loading