Skip to content

Commit b4f1ddd

Browse files
authored
Merge pull request #213 from yaananth/yaananth-metrics
Special handle timer fired events for workflow event delay metrics + add event name as tag for workflow task metrics
2 parents bcd44f2 + e3bd685 commit b4f1ddd

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

internal/metrickeys/metrickeys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const (
77
WorkflowInstanceCreated = Prefix + "workflow.created"
88
WorkflowInstanceFinished = Prefix + "workflow.finished"
99

10-
WorkflowTaskScheduled = Prefix + "workflow.task.scheduled"
1110
WorkflowTaskProcessed = Prefix + "workflow.task.processed"
1211
WorkflowTaskDelay = Prefix + "workflow.task.time_in_queue"
1312

@@ -32,4 +31,5 @@ const (
3231
ContinuedAsNew = "continued_as_new"
3332

3433
ActivityName = "activity"
34+
EventName = "event"
3535
)

internal/worker/workflow.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/benbjohnson/clock"
1111
"github.com/cschleiden/go-workflows/backend"
1212
"github.com/cschleiden/go-workflows/internal/core"
13+
"github.com/cschleiden/go-workflows/internal/history"
1314
"github.com/cschleiden/go-workflows/internal/metrickeys"
1415
"github.com/cschleiden/go-workflows/internal/task"
1516
"github.com/cschleiden/go-workflows/internal/workflow"
@@ -133,11 +134,25 @@ func (ww *WorkflowWorker) runDispatcher() {
133134

134135
func (ww *WorkflowWorker) handle(ctx context.Context, t *task.Workflow) {
135136
// Record how long this task was in the queue
136-
scheduledAt := t.NewEvents[0].Timestamp // Use the timestamp of the first event as the schedule time
137+
firstEvent := t.NewEvents[0]
138+
var scheduledAt time.Time
139+
if firstEvent.Type == history.EventType_TimerFired {
140+
timerFiredAttributes := firstEvent.Attributes.(*history.TimerFiredAttributes)
141+
scheduledAt = timerFiredAttributes.At // Use the timestamp of the timer fired event as the schedule time
142+
} else {
143+
scheduledAt = firstEvent.Timestamp // Use the timestamp of the first event as the schedule time
144+
}
145+
146+
eventName := fmt.Sprint(firstEvent.Type)
147+
137148
timeInQueue := time.Since(scheduledAt)
138-
ww.backend.Metrics().Distribution(metrickeys.WorkflowTaskDelay, metrics.Tags{}, float64(timeInQueue/time.Millisecond))
149+
ww.backend.Metrics().Distribution(metrickeys.WorkflowTaskDelay, metrics.Tags{
150+
metrickeys.EventName: eventName,
151+
}, float64(timeInQueue/time.Millisecond))
139152

140-
timer := metrics.Timer(ww.backend.Metrics(), metrickeys.WorkflowTaskProcessed, metrics.Tags{})
153+
timer := metrics.Timer(ww.backend.Metrics(), metrickeys.WorkflowTaskProcessed, metrics.Tags{
154+
metrickeys.EventName: eventName,
155+
})
141156

142157
result, err := ww.handleTask(ctx, t)
143158
if err != nil {

0 commit comments

Comments
 (0)