forked from cadence-workflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor metrics into common and service metrics
Summary: This revision defines common metrics that are used in more than one service, as well as service specific metrics. It also adds wrappers on the service clients to emit metrics. Test Plan: Build, UT Reviewers: sivakk, maxim, samar Reviewed By: samar Subscribers: jenkins Differential Revision: https://code.uberinternal.com/D722803
- Loading branch information
Tamer Eldeeb
committed
Feb 3, 2017
1 parent
4b6c2a7
commit 3e477ad
Showing
9 changed files
with
412 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package history | ||
|
||
import ( | ||
h "code.uber.internal/devexp/minions/.gen/go/history" | ||
workflow "code.uber.internal/devexp/minions/.gen/go/shared" | ||
"code.uber.internal/devexp/minions/common/metrics" | ||
) | ||
|
||
var _ Client = (*metricClient)(nil) | ||
|
||
type metricClient struct { | ||
client Client | ||
metricsClient metrics.Client | ||
} | ||
|
||
// NewMetricClient creates a new instance of Client that emits metrics | ||
func NewMetricClient(client Client, metricsClient metrics.Client) Client { | ||
return &metricClient{ | ||
client: client, | ||
metricsClient: metricsClient, | ||
} | ||
} | ||
|
||
func (c *metricClient) StartWorkflowExecution(request *workflow.StartWorkflowExecutionRequest) (*workflow.StartWorkflowExecutionResponse, error) { | ||
c.metricsClient.IncCounter(metrics.HistoryClientStartWorkflowExecutionScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientStartWorkflowExecutionScope, metrics.WorkflowLatency) | ||
resp, err := c.client.StartWorkflowExecution(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientStartWorkflowExecutionScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *metricClient) GetWorkflowExecutionHistory( | ||
request *workflow.GetWorkflowExecutionHistoryRequest) (*workflow.GetWorkflowExecutionHistoryResponse, error) { | ||
c.metricsClient.IncCounter(metrics.HistoryClientGetWorkflowExecutionHistoryScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientGetWorkflowExecutionHistoryScope, metrics.WorkflowLatency) | ||
resp, err := c.client.GetWorkflowExecutionHistory(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientGetWorkflowExecutionHistoryScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *metricClient) RecordDecisionTaskStarted(request *h.RecordDecisionTaskStartedRequest) (*h.RecordDecisionTaskStartedResponse, error) { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordDecisionTaskStartedScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRecordDecisionTaskStartedScope, metrics.WorkflowLatency) | ||
resp, err := c.client.RecordDecisionTaskStarted(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordDecisionTaskStartedScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *metricClient) RecordActivityTaskStarted(request *h.RecordActivityTaskStartedRequest) (*h.RecordActivityTaskStartedResponse, error) { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordActivityTaskStartedScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRecordActivityTaskStartedScope, metrics.WorkflowLatency) | ||
resp, err := c.client.RecordActivityTaskStarted(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordActivityTaskStartedScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *metricClient) RespondDecisionTaskCompleted(request *workflow.RespondDecisionTaskCompletedRequest) error { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondDecisionTaskCompletedScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRespondDecisionTaskCompletedScope, metrics.WorkflowLatency) | ||
err := c.client.RespondDecisionTaskCompleted(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondDecisionTaskCompletedScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *metricClient) RespondActivityTaskCompleted(request *workflow.RespondActivityTaskCompletedRequest) error { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondActivityTaskCompletedScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRespondActivityTaskCompletedScope, metrics.WorkflowLatency) | ||
err := c.client.RespondActivityTaskCompleted(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondActivityTaskCompletedScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *metricClient) RespondActivityTaskFailed(request *workflow.RespondActivityTaskFailedRequest) error { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondActivityTaskFailedScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRespondActivityTaskFailedScope, metrics.WorkflowLatency) | ||
err := c.client.RespondActivityTaskFailed(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRespondActivityTaskFailedScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *metricClient) RecordActivityTaskHeartbeat( | ||
request *workflow.RecordActivityTaskHeartbeatRequest) (*workflow.RecordActivityTaskHeartbeatResponse, error) { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordActivityTaskHeartbeatScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.HistoryClientRecordActivityTaskHeartbeatScope, metrics.WorkflowLatency) | ||
resp, err := c.client.RecordActivityTaskHeartbeat(request) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.HistoryClientRecordActivityTaskHeartbeatScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package matching | ||
|
||
import ( | ||
m "code.uber.internal/devexp/minions/.gen/go/matching" | ||
workflow "code.uber.internal/devexp/minions/.gen/go/shared" | ||
"code.uber.internal/devexp/minions/common/metrics" | ||
) | ||
|
||
var _ Client = (*metricClient)(nil) | ||
|
||
type metricClient struct { | ||
client Client | ||
metricsClient metrics.Client | ||
} | ||
|
||
// NewMetricClient creates a new instance of Client that emits metrics | ||
func NewMetricClient(client Client, metricsClient metrics.Client) Client { | ||
return &metricClient{ | ||
client: client, | ||
metricsClient: metricsClient, | ||
} | ||
} | ||
|
||
func (c *metricClient) AddActivityTask(addRequest *m.AddActivityTaskRequest) error { | ||
c.metricsClient.IncCounter(metrics.MatchingClientAddActivityTaskScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.MatchingClientAddActivityTaskScope, metrics.WorkflowLatency) | ||
err := c.client.AddActivityTask(addRequest) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.MatchingClientAddActivityTaskScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *metricClient) AddDecisionTask(addRequest *m.AddDecisionTaskRequest) error { | ||
c.metricsClient.IncCounter(metrics.MatchingClientAddDecisionTaskScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.MatchingClientAddDecisionTaskScope, metrics.WorkflowLatency) | ||
err := c.client.AddDecisionTask(addRequest) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.MatchingClientAddDecisionTaskScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c *metricClient) PollForActivityTask(pollRequest *workflow.PollForActivityTaskRequest) (*workflow.PollForActivityTaskResponse, error) { | ||
c.metricsClient.IncCounter(metrics.MatchingClientPollForActivityTaskScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.MatchingClientPollForActivityTaskScope, metrics.WorkflowLatency) | ||
resp, err := c.client.PollForActivityTask(pollRequest) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.MatchingClientPollForActivityTaskScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *metricClient) PollForDecisionTask(pollRequest *workflow.PollForDecisionTaskRequest) (*workflow.PollForDecisionTaskResponse, error) { | ||
c.metricsClient.IncCounter(metrics.MatchingClientPollForDecisionTaskScope, metrics.WorkflowRequests) | ||
|
||
sw := c.metricsClient.StartTimer(metrics.MatchingClientPollForDecisionTaskScope, metrics.WorkflowLatency) | ||
resp, err := c.client.PollForDecisionTask(pollRequest) | ||
sw.Stop() | ||
|
||
if err != nil { | ||
c.metricsClient.IncCounter(metrics.MatchingClientPollForDecisionTaskScope, metrics.WorkflowFailures) | ||
} | ||
|
||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.