Skip to content

Commit

Permalink
feat: queued metrics, along with bug fixes for round robin queueing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 authored Apr 4, 2024
1 parent 28e3a18 commit 334ce75
Show file tree
Hide file tree
Showing 32 changed files with 1,323 additions and 215 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 @@ -178,3 +178,5 @@ ListSNSIntegrations:
$ref: "./sns.yaml#/ListSNSIntegrations"
CreateSNSIntegrationRequest:
$ref: "./sns.yaml#/CreateSNSIntegrationRequest"
WorkflowMetrics:
$ref: "./workflow.yaml#/WorkflowMetrics"
4 changes: 4 additions & 0 deletions api-contracts/openapi/components/schemas/event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ EventWorkflowRunSummary:
type: integer
format: int64
description: The number of running runs.
queued:
type: integer
format: int64
description: The number of queued runs.
succeeded:
type: integer
format: int64
Expand Down
10 changes: 10 additions & 0 deletions api-contracts/openapi/components/schemas/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,13 @@ LinkGithubRepositoryRequest:
- gitRepoName
- gitRepoOwner
- gitRepoBranch

WorkflowMetrics:
type: object
properties:
groupKeyRunsCount:
type: integer
description: The number of runs for a specific group key (passed via filter)
groupKeyCount:
type: integer
description: The total number of concurrency group keys.
1 change: 1 addition & 0 deletions api-contracts/openapi/components/schemas/workflow_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ WorkflowRunStatus:
- SUCCEEDED
- FAILED
- CANCELLED
- QUEUED

WorkflowRunStatusList:
type: array
Expand Down
2 changes: 2 additions & 0 deletions api-contracts/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ paths:
$ref: "./paths/workflow/workflow.yaml#/workflowVersionDefinition"
/api/v1/workflows/{workflow}/link-github:
$ref: "./paths/workflow/workflow.yaml#/linkGithub"
/api/v1/workflows/{workflow}/metrics:
$ref: "./paths/workflow/workflow.yaml#/getMetrics"
/api/v1/step-runs/{step-run}/create-pr:
$ref: "./paths/workflow/workflow.yaml#/createPullRequest"
/api/v1/step-runs/{step-run}/logs:
Expand Down
55 changes: 55 additions & 0 deletions api-contracts/openapi/paths/workflow/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,58 @@ getDiff:
summary: Get diff
tags:
- Workflow
getMetrics:
get:
x-resources: ["tenant", "workflow"]
description: Get the metrics for a workflow version
operationId: workflow:get:metrics
parameters:
- description: The workflow id
in: path
name: workflow
required: true
schema:
type: string
format: uuid
minLength: 36
maxLength: 36
- description: A status of workflow runs to filter by
in: query
name: status
required: false
schema:
$ref: "../../components/schemas/_index.yaml#/WorkflowRunStatus"
- description: A group key to filter metrics by
in: query
name: groupKey
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/WorkflowMetrics"
description: Successfully retrieved the workflow version 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 workflow metrics
tags:
- Workflow
44 changes: 44 additions & 0 deletions api/v1/server/handlers/workflows/get_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package workflows

import (
"errors"

"github.com/labstack/echo/v4"

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

func (t *WorkflowService) WorkflowGetMetrics(ctx echo.Context, request gen.WorkflowGetMetricsRequestObject) (gen.WorkflowGetMetricsResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
workflow := ctx.Get("workflow").(*db.WorkflowModel)

opts := &repository.GetWorkflowMetricsOpts{}

if request.Params.Status != nil {
opts.Status = (*string)(request.Params.Status)
}

if request.Params.GroupKey != nil {
opts.GroupKey = request.Params.GroupKey
}

metrics, err := t.config.APIRepository.Workflow().GetWorkflowMetrics(tenant.ID, workflow.ID, opts)

if err != nil {
if errors.Is(err, db.ErrNotFound) {
return gen.WorkflowGetMetrics404JSONResponse(
apierrors.NewAPIErrors("workflow not found"),
), nil
}

return nil, err
}

return gen.WorkflowGetMetrics200JSONResponse(gen.WorkflowMetrics{
GroupKeyCount: &metrics.GroupKeyCount,
GroupKeyRunsCount: &metrics.GroupKeyRunsCount,
}), nil
}
Loading

0 comments on commit 334ce75

Please sign in to comment.