Skip to content

Commit

Permalink
Add missing metrics to replication task (cadence-workflow#1682)
Browse files Browse the repository at this point in the history
* Add missing metrics to replication task
  • Loading branch information
wxing1292 authored Apr 9, 2019
1 parent 2dc8575 commit b6f9684
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions service/worker/replicator/replicationTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ import (

type (
workflowReplicationTask struct {
partitionID definition.WorkflowIdentifier
taskID int64
attempt int
kafkaMsg messaging.Message
logger bark.Logger
metricsScope int
startTime time.Time
partitionID definition.WorkflowIdentifier
taskID int64
attempt int
kafkaMsg messaging.Message
logger bark.Logger

config *Config
historyClient history.Client
Expand Down Expand Up @@ -76,6 +78,8 @@ func newActivityReplicationTask(task *replicator.ReplicationTask, msg messaging.
attr := task.SyncActicvityTaskAttributes
return &activityReplicationTask{
workflowReplicationTask: workflowReplicationTask{
metricsScope: metrics.SyncActivityTaskScope,
startTime: time.Now(),
partitionID: definition.NewWorkflowIdentifier(
attr.GetDomainId(), attr.GetWorkflowId(), attr.GetRunId(),
),
Expand Down Expand Up @@ -117,6 +121,8 @@ func newHistoryReplicationTask(task *replicator.ReplicationTask, msg messaging.M
attr := task.HistoryTaskAttributes
return &historyReplicationTask{
workflowReplicationTask: workflowReplicationTask{
metricsScope: metrics.HistoryReplicationTaskScope,
startTime: time.Now(),
partitionID: definition.NewWorkflowIdentifier(
attr.GetDomainId(), attr.GetWorkflowId(), attr.GetRunId(),
),
Expand Down Expand Up @@ -262,6 +268,9 @@ func (t *workflowReplicationTask) HashCode() uint32 {
}

func (t *workflowReplicationTask) Ack() {
t.metricsClient.IncCounter(t.metricsScope, metrics.ReplicatorMessages)
t.metricsClient.RecordTimer(t.metricsScope, metrics.ReplicatorLatency, time.Now().Sub(t.startTime))

// the underlying implementation will not return anything other than nil
// do logging just in case
err := t.kafkaMsg.Ack()
Expand All @@ -271,6 +280,9 @@ func (t *workflowReplicationTask) Ack() {
}

func (t *workflowReplicationTask) Nack() {
t.metricsClient.IncCounter(t.metricsScope, metrics.ReplicatorMessages)
t.metricsClient.RecordTimer(t.metricsScope, metrics.ReplicatorLatency, time.Now().Sub(t.startTime))

// the underlying implementation will not return anything other than nil
// do logging just in case
err := t.kafkaMsg.Nack()
Expand Down
4 changes: 4 additions & 0 deletions service/worker/replicator/replicationTask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (s *activityReplicationTaskSuite) TestNewActivityReplicationTask() {
s.Equal(
&activityReplicationTask{
workflowReplicationTask: workflowReplicationTask{
metricsScope: metrics.SyncActivityTaskScope,
startTime: task.startTime,
partitionID: definition.NewWorkflowIdentifier(
replicationAttr.GetDomainId(),
replicationAttr.GetWorkflowId(),
Expand Down Expand Up @@ -304,6 +306,8 @@ func (s *historyReplicationTaskSuite) TestNewHistoryReplicationTask() {
s.Equal(
&historyReplicationTask{
workflowReplicationTask: workflowReplicationTask{
metricsScope: metrics.HistoryReplicationTaskScope,
startTime: task.startTime,
partitionID: definition.NewWorkflowIdentifier(
replicationAttr.GetDomainId(),
replicationAttr.GetWorkflowId(),
Expand Down

0 comments on commit b6f9684

Please sign in to comment.