From 726499681ca3b614663af0350be022c96603a1e5 Mon Sep 17 00:00:00 2001 From: Kannan Rajah Date: Wed, 11 Mar 2026 10:55:02 -0700 Subject: [PATCH] Add CountWorkers API Add CountWorkers RPC for counting workers matching a query filter. Follows the same pattern as CountWorkflowExecutions, CountSchedules, and CountActivityExecutions. Made-with: Cursor --- openapi/openapiv2.json | 86 +++++++++++++++++++ openapi/openapiv3.yaml | 70 +++++++++++++++ .../workflowservice/v1/request_response.proto | 12 +++ temporal/api/workflowservice/v1/service.proto | 10 +++ 4 files changed, 178 insertions(+) diff --git a/openapi/openapiv2.json b/openapi/openapiv2.json index ea5c6c69a..163908147 100644 --- a/openapi/openapiv2.json +++ b/openapi/openapiv2.json @@ -2190,6 +2190,44 @@ ] } }, + "/api/v1/namespaces/{namespace}/worker-count": { + "get": { + "summary": "CountWorkers is a visibility API to count workers in a specific namespace.", + "operationId": "CountWorkers2", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1CountWorkersResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "namespace", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "query", + "description": "Query to filter workers before counting.\nSupported filter fields are the same as in ListWorkersRequest.", + "in": "query", + "required": false, + "type": "string" + } + ], + "tags": [ + "WorkflowService" + ] + } + }, "/api/v1/namespaces/{namespace}/worker-deployment-versions/{deploymentVersion.deploymentName}/{deploymentVersion.buildId}": { "get": { "summary": "Describes a worker deployment version.\nExperimental. This API might significantly change or be removed in a future release.", @@ -6690,6 +6728,44 @@ ] } }, + "/namespaces/{namespace}/worker-count": { + "get": { + "summary": "CountWorkers is a visibility API to count workers in a specific namespace.", + "operationId": "CountWorkers", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/v1CountWorkersResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "namespace", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "query", + "description": "Query to filter workers before counting.\nSupported filter fields are the same as in ListWorkersRequest.", + "in": "query", + "required": false, + "type": "string" + } + ], + "tags": [ + "WorkflowService" + ] + } + }, "/namespaces/{namespace}/worker-deployment-versions/{deploymentVersion.deploymentName}/{deploymentVersion.buildId}": { "get": { "summary": "Describes a worker deployment version.\nExperimental. This API might significantly change or be removed in a future release.", @@ -11954,6 +12030,16 @@ } } }, + "v1CountWorkersResponse": { + "type": "object", + "properties": { + "count": { + "type": "string", + "format": "int64", + "description": "Approximate number of workers matching the query." + } + } + }, "v1CountWorkflowExecutionsResponse": { "type": "object", "properties": { diff --git a/openapi/openapiv3.yaml b/openapi/openapiv3.yaml index 4ccc94584..d65d1c83f 100644 --- a/openapi/openapiv3.yaml +++ b/openapi/openapiv3.yaml @@ -1958,6 +1958,38 @@ paths: application/json: schema: $ref: '#/components/schemas/Status' + /api/v1/namespaces/{namespace}/worker-count: + get: + tags: + - WorkflowService + description: CountWorkers is a visibility API to count workers in a specific namespace. + operationId: CountWorkers + parameters: + - name: namespace + in: path + required: true + schema: + type: string + - name: query + in: query + description: |- + Query to filter workers before counting. + Supported filter fields are the same as in ListWorkersRequest. + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CountWorkersResponse' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' /api/v1/namespaces/{namespace}/worker-deployment-versions/{deployment_version.deployment_name}/{deployment_version.build_id}: get: tags: @@ -5991,6 +6023,38 @@ paths: application/json: schema: $ref: '#/components/schemas/Status' + /namespaces/{namespace}/worker-count: + get: + tags: + - WorkflowService + description: CountWorkers is a visibility API to count workers in a specific namespace. + operationId: CountWorkers + parameters: + - name: namespace + in: path + required: true + schema: + type: string + - name: query + in: query + description: |- + Query to filter workers before counting. + Supported filter fields are the same as in ListWorkersRequest. + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CountWorkersResponse' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' /namespaces/{namespace}/worker-deployment-versions/{deployment_version.deployment_name}/{deployment_version.build_id}: get: tags: @@ -9100,6 +9164,12 @@ components: $ref: '#/components/schemas/Payload' count: type: string + CountWorkersResponse: + type: object + properties: + count: + type: string + description: Approximate number of workers matching the query. CountWorkflowExecutionsResponse: type: object properties: diff --git a/temporal/api/workflowservice/v1/request_response.proto b/temporal/api/workflowservice/v1/request_response.proto index 651816e37..30e664e9d 100644 --- a/temporal/api/workflowservice/v1/request_response.proto +++ b/temporal/api/workflowservice/v1/request_response.proto @@ -2684,6 +2684,18 @@ message DescribeWorkerResponse { temporal.api.worker.v1.WorkerInfo worker_info = 1; } +message CountWorkersRequest { + string namespace = 1; + // Query to filter workers before counting. + // Supported filter fields are the same as in ListWorkersRequest. + string query = 2; +} + +message CountWorkersResponse { + // Approximate number of workers matching the query. + int64 count = 1; +} + // Request to pause a workflow execution. message PauseWorkflowExecutionRequest { // Namespace of the workflow to pause. diff --git a/temporal/api/workflowservice/v1/service.proto b/temporal/api/workflowservice/v1/service.proto index c67a2717b..2bb26a51e 100644 --- a/temporal/api/workflowservice/v1/service.proto +++ b/temporal/api/workflowservice/v1/service.proto @@ -1272,6 +1272,16 @@ service WorkflowService { }; } + // CountWorkers is a visibility API to count workers in a specific namespace. + rpc CountWorkers (CountWorkersRequest) returns (CountWorkersResponse) { + option (google.api.http) = { + get: "/namespaces/{namespace}/worker-count" + additional_bindings { + get: "/api/v1/namespaces/{namespace}/worker-count" + } + }; + } + // Updates task queue configuration. // For the overall queue rate limit: the rate limit set by this api overrides the worker-set rate limit, // which uncouples the rate limit from the worker lifecycle.