Skip to content

Commit

Permalink
Add tests for metrics and scopes def (cadence-workflow#1038)
Browse files Browse the repository at this point in the history
* Add tests for metric def

* Add test for metric defs, fix missing metric def

* Remove logging
  • Loading branch information
vancexu authored Aug 9, 2018
1 parent 96e49a8 commit cabff59
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ const (
HistoryTaskStandbyRetryCounter
HistoryTaskNotActiveCounter
HistoryTaskBatchCompleteCounter

NumHistoryMetrics
)

// Matching metrics enum
Expand All @@ -779,13 +781,17 @@ const (
RespondQueryTaskFailedCounter
SyncThrottleCounter
BufferThrottleCounter

NumMatchingMetrics
)

// Worker metrics enum
const (
ReplicatorMessages = iota + NumCommonMetrics
ReplicatorFailures
ReplicatorLatency

NumWorkerMetrics
)

// MetricDefs record the metrics for all services
Expand Down Expand Up @@ -837,6 +843,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
DecisionTypeRecordMarkerCounter: {metricName: "record-marker-decision", metricType: Counter},
DecisionTypeCancelExternalWorkflowCounter: {metricName: "cancel-external-workflow-decision", metricType: Counter},
DecisionTypeContinueAsNewCounter: {metricName: "continue-as-new-decision", metricType: Counter},
DecisionTypeSignalExternalWorkflowCounter: {metricName: "signal-external-workflow-decision", metricType: Counter},
DecisionTypeChildWorkflowCounter: {metricName: "child-workflow-decision", metricType: Counter},
MultipleCompletionDecisionsCounter: {metricName: "multiple-completion-decisions", metricType: Counter},
FailedDecisionsCounter: {metricName: "failed-decisions", metricType: Counter},
Expand Down
77 changes: 77 additions & 0 deletions common/metrics/defs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package metrics

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestScopeDefsMapped(t *testing.T) {
for i := PersistenceCreateShardScope; i < NumCommonScopes; i++ {
key, ok := ScopeDefs[Common][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := FrontendStartWorkflowExecutionScope; i < NumFrontendScopes; i++ {
key, ok := ScopeDefs[Frontend][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := HistoryStartWorkflowExecutionScope; i < NumHistoryScopes; i++ {
key, ok := ScopeDefs[History][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := MatchingPollForDecisionTaskScope; i < NumMatchingScopes; i++ {
key, ok := ScopeDefs[Matching][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := ReplicatorScope; i < NumWorkerScopes; i++ {
key, ok := ScopeDefs[Worker][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
}

func TestMetricDefsMapped(t *testing.T) {
for i := CadenceRequests; i < NumCommonMetrics; i++ {
key, ok := MetricDefs[Common][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := TaskRequests; i < NumHistoryMetrics; i++ {
key, ok := MetricDefs[History][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := PollSuccessCounter; i < NumMatchingMetrics; i++ {
key, ok := MetricDefs[Matching][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
for i := ReplicatorMessages; i < NumWorkerMetrics; i++ {
key, ok := MetricDefs[Worker][i]
require.True(t, ok)
require.NotEmpty(t, key)
}
}

0 comments on commit cabff59

Please sign in to comment.