Skip to content

Commit

Permalink
feat: check for test workflow execution for execute action
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Jul 3, 2024
1 parent 40a5503 commit 5349e35
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/app/api/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (m Metrics) IncTestTriggerEventCount(name, resource, eventType string, caus
}).Inc()
}

func (m Metrics) InWebhookEventCount(name, eventType, result string) {
func (m Metrics) IncWebhookEventCount(name, eventType, result string) {
m.WebhookEventCount.With(map[string]string{
"name": name,
"eventType": eventType,
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_execution_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,18 @@ func (e *TestWorkflowExecution) GetNamespace(defaultNamespace string) string {
}
return e.Namespace
}

func (e *TestWorkflowExecution) ContainsExecuteAction() bool {
if e.ResolvedWorkflow == nil || e.ResolvedWorkflow.Spec == nil {
return false
}

steps := append(e.ResolvedWorkflow.Spec.Setup, append(e.ResolvedWorkflow.Spec.Steps, e.ResolvedWorkflow.Spec.After...)...)
for _, step := range steps {
if step.ContainsExecuteAction() {
return true
}
}

return false
}
19 changes: 19 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_step_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,22 @@ func (w *TestWorkflowStep) EscapeDots() *TestWorkflowStep {
func (w *TestWorkflowStep) UnscapeDots() *TestWorkflowStep {
return w.ConvertDots(utils.UnescapeDots)
}

func (w *TestWorkflowStep) ContainsExecuteAction() bool {
if w.Execute != nil && (len(w.Execute.Tests) != 0 || len(w.Execute.Workflows) != 0) {
return true
}

steps := append(w.Setup, w.Steps...)
for _, step := range steps {
if step.ContainsExecuteAction() {
return true
}
}

if w.Parallel.ContainsExecuteAction() {
return true
}

return false
}
2 changes: 1 addition & 1 deletion pkg/event/kind/webhook/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (l *WebhookListener) Notify(event testkube.Event) (result testkube.EventRes
res = "error"
}

l.metrics.InWebhookEventCount(l.name, eventType, res)
l.metrics.IncWebhookEventCount(l.name, eventType, res)
}()

switch {
Expand Down

0 comments on commit 5349e35

Please sign in to comment.