-
Notifications
You must be signed in to change notification settings - Fork 145
/
metrics_runs.go
80 lines (62 loc) · 2.34 KB
/
metrics_runs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package workflows
import (
"fmt"
"strings"
"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/pkg/repository"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)
func (t *WorkflowService) WorkflowRunGetMetrics(ctx echo.Context, request gen.WorkflowRunGetMetricsRequestObject) (gen.WorkflowRunGetMetricsResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
listOpts := &repository.WorkflowRunsMetricsOpts{}
if request.Params.WorkflowId != nil {
workflowIdStr := request.Params.WorkflowId.String()
listOpts.WorkflowId = &workflowIdStr
}
if request.Params.EventId != nil {
eventIdStr := request.Params.EventId.String()
listOpts.EventId = &eventIdStr
}
if request.Params.ParentWorkflowRunId != nil {
parentWorkflowRunIdStr := request.Params.ParentWorkflowRunId.String()
listOpts.ParentId = &parentWorkflowRunIdStr
}
if request.Params.ParentStepRunId != nil {
parentStepRunIdStr := request.Params.ParentStepRunId.String()
listOpts.ParentStepRunId = &parentStepRunIdStr
}
if request.Params.AdditionalMetadata != nil {
additionalMetadata := make(map[string]interface{}, len(*request.Params.AdditionalMetadata))
for _, v := range *request.Params.AdditionalMetadata {
splitValue := strings.Split(fmt.Sprintf("%v", v), ":")
if len(splitValue) == 2 {
additionalMetadata[splitValue[0]] = splitValue[1]
} else {
return gen.WorkflowRunGetMetrics400JSONResponse(apierrors.NewAPIErrors("Additional metadata filters must be in the format key:value.")), nil
}
}
listOpts.AdditionalMetadata = additionalMetadata
}
workflowRunsMetricsCount, err := t.config.APIRepository.WorkflowRun().WorkflowRunMetricsCount(tenant.ID, listOpts)
if err != nil {
return nil, err
}
failed := int(workflowRunsMetricsCount.FAILED)
pending := int(workflowRunsMetricsCount.PENDING)
queued := int(workflowRunsMetricsCount.QUEUED)
running := int(workflowRunsMetricsCount.RUNNING)
succeeded := int(workflowRunsMetricsCount.SUCCEEDED)
return gen.WorkflowRunGetMetrics200JSONResponse(
gen.WorkflowRunsMetrics{
Counts: &gen.WorkflowRunsMetricsCounts{
FAILED: &failed,
PENDING: &pending,
QUEUED: &queued,
RUNNING: &running,
SUCCEEDED: &succeeded,
},
},
), nil
}