Skip to content

Commit

Permalink
docs: test trigger metric
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Jun 20, 2024
1 parent 9898b38 commit 1ce800d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/docs/articles/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The Testkube API Server exposes a `/metrics` endpoint that can be consumed by Pr
* `testkube_test_executions_duration_ms`- The duration of test executions.
* `testkube_testsuite_executions_duration_ms`- The duration of test suite executions.
* `testkube_testworkflow_executions_duration_ms`- The duration of test workflow executions.
* `testkube_testtrigger_event_count` - The total number of test trigger events.

Note: as the metrics also include labels with the associated test name (see below), no metrics are produced unless some tests were run since last api-server restart

Expand Down
12 changes: 2 additions & 10 deletions internal/app/api/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var testWorkflowTemplateDeletesCount = promauto.NewCounterVec(prometheus.Counter
var testTriggerEventCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "testkube_testtrigger_event_count",
Help: "The total number of test trigger events",
}, []string{"resource", "name", "labels", "eventType", "causes"})
}, []string{"resource", "eventType", "causes"})

func NewMetrics() Metrics {
return Metrics{
Expand Down Expand Up @@ -489,18 +489,10 @@ func (m Metrics) IncDeleteTestWorkflowTemplate(err error) {
}).Inc()
}

func (m Metrics) IncTestTriggerEventCount(resource, name, eventType string, causes []string, labels map[string]string) {
var ls []string
for key, value := range labels {
ls = append(ls, fmt.Sprintf("%s=%s", key, value))
}

slices.Sort(ls)
func (m Metrics) IncTestTriggerEventCount(resource, eventType string, causes []string) {
slices.Sort(causes)
m.TestTriggerEventCount.With(map[string]string{
"resource": resource,
"name": name,
"labels": strings.Join(ls, ","),
"eventType": eventType,
"causes": strings.Join(causes, ","),
}).Inc()
Expand Down
2 changes: 1 addition & 1 deletion pkg/triggers/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Service) match(ctx context.Context, e *watcherEvent) error {
causes = append(causes, string(cause))
}

s.metrics.IncTestTriggerEventCount(string(e.resource), e.name, string(e.eventType), causes, e.labels)
s.metrics.IncTestTriggerEventCount(string(e.resource), string(e.eventType), causes)
if err := s.triggerExecutor(ctx, e, t); err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/triggers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ func (s *Service) podEventHandler(ctx context.Context) cache.ResourceEventHandle
newPod.Namespace == s.testkubeNamespace && newPod.Labels["job-name"] != "" && newPod.Labels[testkube.TestLabelTestName] != "" &&
!(strings.HasSuffix(oldPod.Name, cexecutor.ScraperPodSuffix) || strings.HasSuffix(newPod.Name, cexecutor.ScraperPodSuffix)) &&
oldPod.Labels["job-name"] == newPod.Labels["job-name"] {
s.metrics.IncTestTriggerEventCount(string(testtrigger.ResourcePod), newPod.Name, string(testtrigger.CauseEventUpdated),
nil, newPod.Labels)
s.metrics.IncTestTriggerEventCount(string(testtrigger.ResourcePod), string(testtrigger.CauseEventUpdated), nil)
s.checkExecutionPodStatus(ctx, oldPod.Labels["job-name"], []*corev1.Pod{oldPod, newPod})
}
},
Expand Down

0 comments on commit 1ce800d

Please sign in to comment.