Skip to content

Commit

Permalink
proper list on high queue depth
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 committed Oct 2, 2024
1 parent 83cb054 commit a56629b
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 179 deletions.
2 changes: 2 additions & 0 deletions api-contracts/openapi/components/schemas/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ QueueMetrics:
$ref: "./tenant.yaml#/QueueMetrics"
TenantQueueMetrics:
$ref: "./tenant.yaml#/TenantQueueMetrics"
TenantStepRunQueueMetrics:
$ref: "./tenant.yaml#/TenantStepRunQueueMetrics"
AcceptInviteRequest:
$ref: "./user.yaml#/AcceptInviteRequest"
RejectInviteRequest:
Expand Down
7 changes: 7 additions & 0 deletions api-contracts/openapi/components/schemas/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,10 @@ TenantQueueMetrics:
type: object
additionalProperties:
type: integer

TenantStepRunQueueMetrics:
properties:
queues:
type: object
additionalProperties:
type: integer
2 changes: 2 additions & 0 deletions api-contracts/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ paths:
$ref: "./paths/api-tokens/api_tokens.yaml#/revoke"
/api/v1/tenants/{tenant}/queue-metrics:
$ref: "./paths/tenant/tenant.yaml#/getQueueMetrics"
/api/v1/tenants/{tenant}/step-run-queue-metrics:
$ref: "./paths/tenant/tenant.yaml#/getStepRunQueueMetrics"
/api/v1/tenants/{tenant}/events:
$ref: "./paths/event/event.yaml#/withTenant"
/api/v1/tenants/{tenant}/events/bulk:
Expand Down
44 changes: 44 additions & 0 deletions api-contracts/openapi/paths/tenant/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,47 @@ getQueueMetrics:
summary: Get workflow metrics
tags:
- Workflow

getStepRunQueueMetrics:
get:
x-resources: ["tenant"]
description: Get the queue metrics for the tenant
operationId: tenant:get:step-run-queue-metrics
parameters:
- description: The tenant id
in: path
name: tenant
required: true
schema:
type: string
format: uuid
minLength: 36
maxLength: 36
responses:
"200":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/TenantStepRunQueueMetrics"
description: Successfully retrieved the step run queue metrics
"400":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: A malformed or bad request
"403":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: Forbidden
"404":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: Not found
summary: Get step run metrics
tags:
- Tenant
24 changes: 24 additions & 0 deletions api/v1/server/handlers/tenants/get_step_run_queue_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tenants

import (
"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)

func (t *TenantService) TenantGetStepRunQueueMetrics(ctx echo.Context, request gen.TenantGetStepRunQueueMetricsRequestObject) (gen.TenantGetStepRunQueueMetricsResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)

stepRunQueueCounts, err := t.config.EngineRepository.StepRun().GetQueueCounts(ctx.Request().Context(), tenant.ID)

if err != nil {
return nil, err
}

resp := gen.TenantStepRunQueueMetrics{
Queues: &stepRunQueueCounts,
}

return gen.TenantGetStepRunQueueMetrics200JSONResponse(resp), nil
}
457 changes: 279 additions & 178 deletions api/v1/server/oas/gen/openapi.gen.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions frontend/app/src/lib/api/generated/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
TenantMemberList,
TenantQueueMetrics,
TenantResourcePolicy,
TenantStepRunQueueMetrics,
TriggerWorkflowRunRequest,
UpdateTenantAlertEmailGroupRequest,
UpdateTenantInviteRequest,
Expand Down Expand Up @@ -823,6 +824,23 @@ export class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType
format: 'json',
...params,
});
/**
* @description Get the queue metrics for the tenant
*
* @tags Tenant
* @name TenantGetStepRunQueueMetrics
* @summary Get step run metrics
* @request GET:/api/v1/tenants/{tenant}/step-run-queue-metrics
* @secure
*/
tenantGetStepRunQueueMetrics = (tenant: string, params: RequestParams = {}) =>
this.request<TenantStepRunQueueMetrics, APIErrors>({
path: `/api/v1/tenants/${tenant}/step-run-queue-metrics`,
method: 'GET',
secure: true,
format: 'json',
...params,
});
/**
* @description Lists all events for a tenant.
*
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/src/lib/api/generated/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ export interface TenantQueueMetrics {
queues?: Record<string, number>;
}

export interface TenantStepRunQueueMetrics {
queues?: Record<string, number>;
}

export interface AcceptInviteRequest {
/**
* @minLength 36
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/src/lib/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ export const queries = createQueryKeyStore({
queryKey: ['queue-metrics:get', tenant],
queryFn: async () => (await api.tenantGetQueueMetrics(tenant)).data,
}),
getStepRunQueueMetrics: (tenant: string) => ({
queryKey: ['queue-metrics:get:step-run', tenant],
queryFn: async () =>
(await api.tenantGetStepRunQueueMetrics(tenant)).data,
}),
},
stepRuns: {
get: (tenant: string, stepRun: string) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export function WorkflowRunsTable({
});

const tenantMetricsQuery = useQuery({
...queries.metrics.get(tenant.metadata.id),
...queries.metrics.getStepRunQueueMetrics(tenant.metadata.id),
refetchInterval,
});

Expand Down
138 changes: 138 additions & 0 deletions pkg/client/rest/gen.go

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

0 comments on commit a56629b

Please sign in to comment.