Files
Kannan RajahandGitHub a9d6101eeb Implement pagination for ListWorkers. (#8849)
## What changed?
Implements cursor-based pagination for the ListWorkers API in the worker
registry. This allows clients to efficiently retrieve large sets of
workers in manageable chunks.

Changes
API Changes:
- Added ListWorkersParams struct to encapsulate query parameters (Query,
PageSize, NextPageToken)
- Added ListWorkersResponse struct with Workers slice and NextPageToken
- Updated Registry.ListWorkers interface signature to use the new
structs

Implementation (registry_impl.go):
- Added paginateWorkers function that handles cursor-based pagination
- Workers are sorted by WorkerInstanceKey for deterministic ordering
when pagination is requested Sorting overhead is acceptable as we expect
the number of workers to be in O(1000s). Even for 100K workers, the sort
time < 100 milliseconds.

Handler (handler.go):
- Updated ListWorkers handler to extract pagination params from request
and pass to registry

## Why?
This allows clients to efficiently retrieve large sets of workers in
manageable chunks.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Minimal. Existing calls that don't specify pagination params will not
exercise the new path. We do an early return without applying pagination
logic.
2025-12-22 10:28:43 -08:00

28 lines
891 B
Go

package workers
import (
workerpb "go.temporal.io/api/worker/v1"
"go.temporal.io/server/common/namespace"
)
type (
// ListWorkersParams contains parameters for listing workers.
ListWorkersParams struct {
Query string
PageSize int
NextPageToken []byte // Opaque token from a previous response to resume pagination.
}
// ListWorkersResponse contains the result of listing workers.
ListWorkersResponse struct {
Workers []*workerpb.WorkerHeartbeat
NextPageToken []byte // Opaque token for the next page; nil if no more results.
}
Registry interface {
RecordWorkerHeartbeats(nsID namespace.ID, nsName namespace.Name, workerHeartbeat []*workerpb.WorkerHeartbeat)
ListWorkers(nsID namespace.ID, params ListWorkersParams) (ListWorkersResponse, error)
DescribeWorker(nsID namespace.ID, workerInstanceKey string) (*workerpb.WorkerHeartbeat, error)
}
)