Skip to content

Commit

Permalink
feat: improve metrics (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
masontikhonov authored Dec 23, 2024
1 parent f5c6557 commit 27800bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion venona/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.0.3
7 changes: 6 additions & 1 deletion venona/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,19 @@ func (a *Agent) reportTaskStatus(ctx context.Context, taskDef task.Task, err err
}

func (a *Agent) getTasks(ctx context.Context) (task.Tasks, []*workflow.Workflow) {
metrics.IncGetTasksRequests()
tasks := a.pullTasks(ctx)
return a.splitTasks(tasks)
}

func (a *Agent) pullTasks(ctx context.Context) task.Tasks {
start := time.Now()
tasks, err := a.cf.Tasks(ctx)
metrics.ObserveGetTasks(start)
status := "success"
if err != nil {
status = "error"
}
metrics.ObserveGetTasks(start, status)

if err != nil {
a.log.Error("Failed pulling tasks", "error", err)
Expand Down
18 changes: 14 additions & 4 deletions venona/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ var (
Name: "queue_size",
Help: "Current number of waiting tasks",
})
getTasksDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
getTasksDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: runnerNamespace,
Name: "get_tasks_duration_sec",
Help: "How long each GetTasks request takes (seconds)",
Buckets: []float64{0.25, 0.5, 1, 2, 3, 6},
Buckets: []float64{0.25, 0.5, 1, 2, 3, 6, 12, 30, 60},
}, []string{"status"})
getTasksRequests = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: runnerNamespace,
Name: "get_tasks_requests",
Help: "Number of GetTasks requests",
})
handlingTimeSinceCreation = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: runnerNamespace,
Expand Down Expand Up @@ -136,10 +141,15 @@ func IncWorkflowRetries(podName string) {
wfTaskRetries.With(labels).Inc()
}

func ObserveGetTasks(start time.Time) {
func ObserveGetTasks(start time.Time, status string) {
end := time.Now()
diff := end.Sub(start)
getTasksDuration.Observe(diff.Seconds())
labels := prometheus.Labels{"status": status}
getTasksDuration.With(labels).Observe(diff.Seconds())
}

func IncGetTasksRequests() {
getTasksRequests.Inc()
}

func ObserveAgentTaskMetrics(agentType string, sinceCreation, inRunner, processed time.Duration) {
Expand Down
2 changes: 1 addition & 1 deletion venonactl/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.0.3

0 comments on commit 27800bf

Please sign in to comment.