Skip to content

Commit

Permalink
Add Signal Name to Signal Metrics (cadence-workflow#4161)
Browse files Browse the repository at this point in the history
What changed?
Adding signalName as a tag to the signal metrics. This will help filtering signal metrics by signal name and create alerts.

See https://t3.uberinternal.com/browse/CDNC-1232 for more details.

Why?
With this change customers can create alerts per signal name and monitor abnormalities.
  • Loading branch information
demirkayaender authored Apr 27, 2021
1 parent 7457be7 commit ac856a6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/metrics/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
invariantType = "invariantType"
kafkaPartition = "kafkaPartition"
transport = "transport"
signalName = "signalName"

domainAllValue = "all"
unknownValue = "_unknown_"
Expand Down Expand Up @@ -153,3 +154,8 @@ func ThriftTransportTag() Tag {
func GPRCTransportTag() Tag {
return simpleMetric{key: transport, value: transportGRPC}
}

// SignalNameTag returns a new SignalName tag
func SignalNameTag(value string) Tag {
return metricWithUnknown(signalName, value)
}
5 changes: 5 additions & 0 deletions service/frontend/workflowHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,10 @@ func (wh *WorkflowHandler) GetWorkflowExecutionHistory(
}, nil
}

func withSignalName(ctx context.Context, signalName string) context.Context {
return metrics.TagContext(ctx, metrics.SignalNameTag(signalName))
}

// SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
// WorkflowExecutionSignaled event recorded in the history and a decision task being created for the execution.
func (wh *WorkflowHandler) SignalWorkflowExecution(
Expand All @@ -2116,6 +2120,7 @@ func (wh *WorkflowHandler) SignalWorkflowExecution(
) (retError error) {
defer log.CapturePanic(wh.GetLogger(), &retError)

ctx = withSignalName(ctx, signalRequest.GetSignalName())
scope, sw := wh.startRequestProfileWithDomain(ctx, metrics.FrontendSignalWorkflowExecutionScope, signalRequest)
defer sw.Stop()

Expand Down
27 changes: 27 additions & 0 deletions service/frontend/workflowHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,33 @@ func (s *workflowHandlerSuite) TestContextMetricsTags() {
s.Fail("counter not found")
}

func (s *workflowHandlerSuite) TestSignalMetricHasSignalName() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))

signalRequest := &types.SignalWorkflowExecutionRequest{
SignalName: "test_signal",
}
wh.SignalWorkflowExecution(context.Background(), signalRequest)

expectedMetrics := make(map[string]bool)
expectedMetrics["test.cadence_requests"] = false
expectedMetrics["test.cadence_errors_bad_request"] = false

snapshot := s.mockResource.MetricsScope.Snapshot()
for _, counter := range snapshot.Counters() {
if _, ok := expectedMetrics[counter.Name()]; ok {
expectedMetrics[counter.Name()] = true
}
if val, ok := counter.Tags()["signalName"]; ok {
s.Equal(val, "test_signal")
} else {
s.Fail("Couldn't find signalName tag")
}
}
s.True(expectedMetrics["test.cadence_requests"])
s.True(expectedMetrics["test.cadence_errors_bad_request"])
}

func (s *workflowHandlerSuite) newConfig(dynamicClient dc.Client) *Config {
return NewConfig(
dc.NewCollection(
Expand Down

0 comments on commit ac856a6

Please sign in to comment.