Skip to content

Commit 4ddfe1b

Browse files
committed
(move to front) change metrics defs to have unique integers
1 parent db5eaf8 commit 4ddfe1b

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

common/metrics/defs.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type (
5353
ServiceIdx int
5454
)
5555

56+
func (s scopeDefinition) GetOperationString() string {
57+
return s.operation
58+
}
59+
5660
// MetricTypes which are supported
5761
const (
5862
Counter MetricType = iota
@@ -1068,7 +1072,7 @@ const (
10681072
// -- Operation scopes for History service --
10691073
const (
10701074
// HistoryStartWorkflowExecutionScope tracks StartWorkflowExecution API calls received by service
1071-
HistoryStartWorkflowExecutionScope = iota + NumCommonScopes
1075+
HistoryStartWorkflowExecutionScope = iota + NumFrontendScopes
10721076
// HistoryRecordActivityTaskHeartbeatScope tracks RecordActivityTaskHeartbeat API calls received by service
10731077
HistoryRecordActivityTaskHeartbeatScope
10741078
// HistoryRespondDecisionTaskCompletedScope tracks RespondDecisionTaskCompleted API calls received by service
@@ -1356,7 +1360,7 @@ const (
13561360
// -- Operation scopes for Matching service --
13571361
const (
13581362
// PollForDecisionTaskScope tracks PollForDecisionTask API calls received by service
1359-
MatchingPollForDecisionTaskScope = iota + NumCommonScopes
1363+
MatchingPollForDecisionTaskScope = iota + NumHistoryScopes
13601364
// PollForActivityTaskScope tracks PollForActivityTask API calls received by service
13611365
MatchingPollForActivityTaskScope
13621366
// MatchingAddActivityTaskScope tracks AddActivityTask API calls received by service
@@ -1392,7 +1396,7 @@ const (
13921396
// -- Operation scopes for Worker service --
13931397
const (
13941398
// ReplicationScope is the scope used by all metric emitted by replicator
1395-
ReplicatorScope = iota + NumCommonScopes
1399+
ReplicatorScope = iota + NumMatchingScopes
13961400
// DomainReplicationTaskScope is the scope used by domain task replication processing
13971401
DomainReplicationTaskScope
13981402
// ESProcessorScope is scope used by all metric emitted by esProcessor
@@ -1440,7 +1444,7 @@ const (
14401444
// -- Operation scopes for ShardDistributor service --
14411445
const (
14421446
// ShardDistributorGetShardOwnerScope tracks GetShardOwner API calls received by service
1443-
ShardDistributorGetShardOwnerScope = iota + NumCommonScopes
1447+
ShardDistributorGetShardOwnerScope = iota + NumWorkerScopes
14441448
ShardDistributorHeartbeatScope
14451449
ShardDistributorAssignLoopScope
14461450

@@ -2700,12 +2704,13 @@ const (
27002704
VirtualQueueCountGauge
27012705
VirtualQueuePausedGauge
27022706
VirtualQueueRunningGauge
2707+
27032708
NumHistoryMetrics
27042709
)
27052710

27062711
// Matching metrics enum
27072712
const (
2708-
PollSuccessPerTaskListCounter = iota + NumCommonMetrics
2713+
PollSuccessPerTaskListCounter = iota + NumHistoryMetrics
27092714
PollTimeoutPerTaskListCounter
27102715
PollSuccessWithSyncPerTaskListCounter
27112716
LeaseRequestPerTaskListCounter
@@ -2783,12 +2788,13 @@ const (
27832788
IsolationGroupUpscale
27842789
IsolationGroupDownscale
27852790
PartitionDrained
2791+
27862792
NumMatchingMetrics
27872793
)
27882794

27892795
// Worker metrics enum
27902796
const (
2791-
ReplicatorMessages = iota + NumCommonMetrics
2797+
ReplicatorMessages = iota + NumMatchingMetrics
27922798
ReplicatorFailures
27932799
ReplicatorMessagesDropped
27942800
ReplicatorLatency
@@ -2872,12 +2878,13 @@ const (
28722878
DiagnosticsWorkflowStartedCount
28732879
DiagnosticsWorkflowSuccess
28742880
DiagnosticsWorkflowExecutionLatency
2881+
28752882
NumWorkerMetrics
28762883
)
28772884

28782885
// ShardDistributor metrics enum
28792886
const (
2880-
ShardDistributorRequests = iota + NumCommonMetrics
2887+
ShardDistributorRequests = iota + NumWorkerMetrics
28812888
ShardDistributorFailures
28822889
ShardDistributorLatency
28832890
ShardDistributorErrContextTimeoutCounter

common/metrics/defs_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ func TestMetricDefs(t *testing.T) {
129129
}
130130
}
131131

132+
// "index -> operation" must be unique for structured.DynamicOperationTags' int lookup to work consistently.
133+
// Duplicate indexes with the same operation name are technically fine, but there doesn't seem to be any benefit in allowing it,
134+
// and it trivially ensures that all indexes have only one operation name.
135+
func TestOperationIndexesAreUnique(t *testing.T) {
136+
seen := make(map[int]bool)
137+
for serviceIdx, serviceOps := range ScopeDefs {
138+
for idx := range serviceOps {
139+
if seen[idx] {
140+
t.Error("duplicate operation index:", idx, "with name:", serviceOps[idx].operation, "in service:", serviceIdx)
141+
}
142+
seen[idx] = true
143+
}
144+
}
145+
}
146+
147+
func TestMetricsAreUnique(t *testing.T) {
148+
// Duplicate metric names are checked by the linter.
149+
//
150+
// Duplicate indexes are arguably fine, but there doesn't seem to be any benefit in allowing it.
151+
t.Run("indexes", func(t *testing.T) {
152+
seen := make(map[int]bool)
153+
for _, serviceMetrics := range MetricDefs {
154+
for idx := range serviceMetrics {
155+
if seen[idx] {
156+
t.Error("duplicate metric index:", idx, "with name:", serviceMetrics[idx].metricName)
157+
}
158+
seen[idx] = true
159+
}
160+
}
161+
})
162+
}
163+
132164
func TestExponentialDurationBuckets(t *testing.T) {
133165
factor := math.Pow(2, 0.25)
134166
assert.Equal(t, 80, len(ExponentialDurationBuckets))

0 commit comments

Comments
 (0)