Skip to content

Commit

Permalink
feat: test workflow tags (#5813)
Browse files Browse the repository at this point in the history
* feat: test workflow tags

Signed-off-by: Vladislav Sukhin <[email protected]>

* feat: test workflow tags api spec

Signed-off-by: Vladislav Sukhin <[email protected]>

* feat: add test workflow api method routes

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Sep 4, 2024
1 parent 01fbdca commit 9dc3a40
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 21 deletions.
72 changes: 72 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,42 @@ paths:
type: array
items:
$ref: "#/components/schemas/Problem"
/test-workflow-with-executions/{id}/tags:
get:
tags:
- test-workflows
- api
parameters:
- $ref: "#/components/parameters/ID"
summary: List test workflow execution tags
description: List test workflow execution tags for all executed test workflows
operationId: listTestWorkflowWithExecutionTags
responses:
200:
description: successful operation
content:
application/json:
schema:
type: object
additionalProperties:
type: array
items:
type: string
example:
app:
- backend
env:
- prod
toDelete:
- "yes"
502:
description: problem communicating with kubernetes cluster
content:
application/problem+json:
schema:
type: array
items:
$ref: "#/components/schemas/Problem"
/test-workflows/{id}/executions:
get:
tags:
Expand Down Expand Up @@ -3860,6 +3896,42 @@ paths:
type: array
items:
$ref: "#/components/schemas/Problem"
/test-workflows/{id}/tags:
get:
tags:
- test-workflows
- api
parameters:
- $ref: "#/components/parameters/ID"
summary: List test workflow execution tags
description: List test workflow execution tags for all executed test workflows
operationId: listTestWorkflowTagsByTestWorkflow
responses:
200:
description: successful list operation
content:
application/json:
schema:
type: object
additionalProperties:
type: array
items:
type: string
example:
app:
- backend
env:
- prod
toDelete:
- "yes"
502:
description: problem communicating with kubernetes cluster
content:
application/problem+json:
schema:
type: array
items:
$ref: "#/components/schemas/Problem"
/test-workflows/{id}/metrics:
get:
tags:
Expand Down
3 changes: 2 additions & 1 deletion internal/app/api/v1/labels_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func (s TestkubeAPI) ListLabelsHandler() fiber.Handler {
func (s *TestkubeAPI) ListTagsHandler() fiber.Handler {
return func(c *fiber.Ctx) error {
errPrefix := "failed to list execution tags"
id := c.Params("id")

tags, err := s.TestWorkflowResults.GetExecutionTags(c.Context())
tags, err := s.TestWorkflowResults.GetExecutionTags(c.Context(), id)
if err != nil {
return s.ClientError(c, errPrefix, err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (s *TestkubeAPI) InitRoutes() {
testWorkflows.Delete("/:id", s.DeleteTestWorkflowHandler())
testWorkflows.Get("/:id/executions", s.ListTestWorkflowExecutionsHandler())
testWorkflows.Post("/:id/executions", s.ExecuteTestWorkflowHandler())
testWorkflows.Get("/:id/tags", s.ListTagsHandler())
testWorkflows.Get("/:id/metrics", s.GetTestWorkflowMetricsHandler())
testWorkflows.Get("/:id/executions/:executionID", s.GetTestWorkflowExecutionHandler())
testWorkflows.Post("/:id/abort", s.AbortAllTestWorkflowExecutionsHandler())
Expand All @@ -436,6 +437,7 @@ func (s *TestkubeAPI) InitRoutes() {
testWorkflowWithExecutions := root.Group("/test-workflow-with-executions")
testWorkflowWithExecutions.Get("/", s.ListTestWorkflowWithExecutionsHandler())
testWorkflowWithExecutions.Get("/:id", s.GetTestWorkflowWithExecutionHandler())
testWorkflowWithExecutions.Get("/:id/tags", s.ListTagsHandler())

root.Post("/preview-test-workflow", s.PreviewTestWorkflowHandler())

Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/data/testworkflow/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func (r *CloudRepository) GetNextExecutionNumber(ctx context.Context, testWorkfl
return commandResponse.TestWorkflowNumber, nil
}

func (r *CloudRepository) GetExecutionTags(ctx context.Context) (tags map[string][]string, err error) {
req := ExecutionGetExecutionTagsRequest{}
func (r *CloudRepository) GetExecutionTags(ctx context.Context, testWorkflowName string) (tags map[string][]string, err error) {
req := ExecutionGetExecutionTagsRequest{TestWorkflowName: testWorkflowName}
process := func(v ExecutionGetExecutionTagsResponse) map[string][]string {
return v.Tags
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cloud/data/testworkflow/execution_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type ExecutionGetNextExecutionNumberResponse struct {
}

type ExecutionGetExecutionTagsRequest struct {
TestWorkflowName string `json:"testWorkflowName"`
}

type ExecutionGetExecutionTagsResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/testworkflow/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Repository interface {
// GetTestWorkflowMetrics get metrics based on the TestWorkflow results
GetTestWorkflowMetrics(ctx context.Context, name string, limit, last int) (metrics testkube.ExecutionsMetrics, err error)
// GetExecutionTags gets execution tags
GetExecutionTags(ctx context.Context) (map[string][]string, error)
GetExecutionTags(ctx context.Context, testWorkflowName string) (map[string][]string, error)
}

type Sequences interface {
Expand Down
30 changes: 15 additions & 15 deletions pkg/repository/testworkflow/mock_repository.go

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

9 changes: 7 additions & 2 deletions pkg/repository/testworkflow/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,14 @@ func (r *MongoRepository) GetNextExecutionNumber(ctx context.Context, name strin
return r.sequenceRepository.GetNextExecutionNumber(ctx, name, sequence.ExecutionTypeTestWorkflow)
}

func (r *MongoRepository) GetExecutionTags(ctx context.Context) (tags map[string][]string, err error) {
func (r *MongoRepository) GetExecutionTags(ctx context.Context, testWorkflowName string) (tags map[string][]string, err error) {
query := bson.M{"tags": bson.M{"$exists": true}}
if testWorkflowName != "" {
query["workflow.name"] = testWorkflowName
}

pipeline := []bson.M{
{"$match": bson.M{"tags": bson.M{"$exists": true}}},
{"$match": query},
{"$project": bson.M{
"tags": 1,
}},
Expand Down

0 comments on commit 9dc3a40

Please sign in to comment.