• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 018730a3-9e41-46e0-a95a-718fc884a759

30 Mar 2023 04:10AM UTC coverage: 57.06% (-0.03%) from 57.087%
018730a3-9e41-46e0-a95a-718fc884a759

push

buildkite

GitHub
large workflow hot shard detection (#5166)

37 of 37 new or added lines in 4 files covered. (100.0%)

85219 of 149351 relevant lines covered (57.06%)

2279.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.57
/common/persistence/statsComputer.go
1
// Copyright (c) 2017-2020 Uber Technologies, Inc.
2
// Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
// of this software and associated documentation files (the "Software"), to deal
6
// in the Software without restriction, including without limitation the rights
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
// copies of the Software, and to permit persons to whom the Software is
9
// furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
// THE SOFTWARE.
21

22
package persistence
23

24
type (
25
        // statsComputer is to computing struct sizes after serialization
26
        statsComputer struct{}
27
)
28

29
func (sc *statsComputer) computeMutableStateStats(req *InternalGetWorkflowExecutionResponse) *MutableStateStats {
737✔
30
        executionInfoSize := computeExecutionInfoSize(req.State.ExecutionInfo)
737✔
31

737✔
32
        activityInfoCount := 0
737✔
33
        activityInfoSize := 0
737✔
34
        for _, ai := range req.State.ActivityInfos {
846✔
35
                activityInfoCount++
109✔
36
                activityInfoSize += computeActivityInfoSize(ai)
109✔
37
        }
109✔
38

39
        timerInfoCount := 0
737✔
40
        timerInfoSize := 0
737✔
41
        for _, ti := range req.State.TimerInfos {
737✔
42
                timerInfoCount++
×
43
                timerInfoSize += computeTimerInfoSize(ti)
×
44
        }
×
45

46
        childExecutionInfoCount := 0
737✔
47
        childExecutionInfoSize := 0
737✔
48
        for _, ci := range req.State.ChildExecutionInfos {
741✔
49
                childExecutionInfoCount++
4✔
50
                childExecutionInfoSize += computeChildInfoSize(ci)
4✔
51
        }
4✔
52

53
        signalInfoCount := 0
737✔
54
        signalInfoSize := 0
737✔
55
        for _, si := range req.State.SignalInfos {
737✔
56
                signalInfoCount++
×
57
                signalInfoSize += computeSignalInfoSize(si)
×
58
        }
×
59

60
        bufferedEventsCount := 0
737✔
61
        bufferedEventsSize := 0
737✔
62

737✔
63
        for _, be := range req.State.BufferedEvents {
740✔
64
                bufferedEventsCount++
3✔
65
                bufferedEventsSize += len(be.Data)
3✔
66
        }
3✔
67

68
        requestCancelInfoCount := len(req.State.RequestCancelInfos)
737✔
69

737✔
70
        totalSize := executionInfoSize
737✔
71
        totalSize += activityInfoSize
737✔
72
        totalSize += timerInfoSize
737✔
73
        totalSize += childExecutionInfoSize
737✔
74
        totalSize += signalInfoSize
737✔
75
        totalSize += bufferedEventsSize
737✔
76

737✔
77
        return &MutableStateStats{
737✔
78
                MutableStateSize:       totalSize,
737✔
79
                ExecutionInfoSize:      executionInfoSize,
737✔
80
                ActivityInfoSize:       activityInfoSize,
737✔
81
                TimerInfoSize:          timerInfoSize,
737✔
82
                ChildInfoSize:          childExecutionInfoSize,
737✔
83
                SignalInfoSize:         signalInfoSize,
737✔
84
                BufferedEventsSize:     bufferedEventsSize,
737✔
85
                ActivityInfoCount:      activityInfoCount,
737✔
86
                TimerInfoCount:         timerInfoCount,
737✔
87
                ChildInfoCount:         childExecutionInfoCount,
737✔
88
                SignalInfoCount:        signalInfoCount,
737✔
89
                BufferedEventsCount:    bufferedEventsCount,
737✔
90
                RequestCancelInfoCount: requestCancelInfoCount,
737✔
91
        }
737✔
92
}
93

94
func (sc *statsComputer) computeMutableStateUpdateStats(req *InternalUpdateWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
4,378✔
95
        if req.NewWorkflowSnapshot != nil {
4,554✔
96
                return mergeMutableStateUpdateSessionStats(sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation), sc.computeWorkflowSnapshotStats(req.NewWorkflowSnapshot))
176✔
97
        }
176✔
98
        return sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation)
4,205✔
99
}
100

101
func (sc *statsComputer) computeMutableStateCreateStats(req *InternalCreateWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
504✔
102
        return sc.computeWorkflowSnapshotStats(&req.NewWorkflowSnapshot)
504✔
103
}
504✔
104

105
func (sc *statsComputer) computeMutableStateConflictResolveStats(req *InternalConflictResolveWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
3✔
106
        mss := sc.computeWorkflowSnapshotStats(&req.ResetWorkflowSnapshot)
3✔
107
        if req.NewWorkflowSnapshot != nil {
3✔
108
                mss = mergeMutableStateUpdateSessionStats(mss, sc.computeWorkflowSnapshotStats(req.NewWorkflowSnapshot))
×
109
        }
×
110
        if req.CurrentWorkflowMutation != nil {
3✔
111
                mss = mergeMutableStateUpdateSessionStats(mss, sc.computeWorkflowMutationStats(req.CurrentWorkflowMutation))
×
112
        }
×
113
        return mss
3✔
114
}
115

116
func (sc *statsComputer) computeWorkflowMutationStats(req *InternalWorkflowMutation) *MutableStateUpdateSessionStats {
4,379✔
117
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
4,379✔
118

4,379✔
119
        activityInfoCount := 0
4,379✔
120
        activityInfoSize := 0
4,379✔
121
        for _, ai := range req.UpsertActivityInfos {
5,604✔
122
                activityInfoCount++
1,225✔
123
                activityInfoSize += computeActivityInfoSize(ai)
1,225✔
124
        }
1,225✔
125

126
        timerInfoCount := 0
4,379✔
127
        timerInfoSize := 0
4,379✔
128
        for _, ti := range req.UpsertTimerInfos {
4,415✔
129
                timerInfoCount++
36✔
130
                timerInfoSize += computeTimerInfoSize(ti)
36✔
131
        }
36✔
132

133
        childExecutionInfoCount := 0
4,379✔
134
        childExecutionInfoSize := 0
4,379✔
135
        for _, ci := range req.UpsertChildExecutionInfos {
4,422✔
136
                childExecutionInfoCount++
43✔
137
                childExecutionInfoSize += computeChildInfoSize(ci)
43✔
138
        }
43✔
139

140
        signalInfoCount := 0
4,379✔
141
        signalInfoSize := 0
4,379✔
142
        for _, si := range req.UpsertSignalInfos {
4,395✔
143
                signalInfoCount++
16✔
144
                signalInfoSize += computeSignalInfoSize(si)
16✔
145
        }
16✔
146

147
        bufferedEventsSize := 0
4,379✔
148
        if req.NewBufferedEvents != nil {
5,022✔
149
                bufferedEventsSize = len(req.NewBufferedEvents.Data)
643✔
150
        }
643✔
151

152
        requestCancelInfoCount := len(req.UpsertRequestCancelInfos)
4,379✔
153

4,379✔
154
        deleteActivityInfoCount := len(req.DeleteActivityInfos)
4,379✔
155

4,379✔
156
        deleteTimerInfoCount := len(req.DeleteTimerInfos)
4,379✔
157

4,379✔
158
        deleteChildInfoCount := len(req.DeleteChildExecutionInfos)
4,379✔
159

4,379✔
160
        deleteSignalInfoCount := len(req.DeleteSignalInfos)
4,379✔
161

4,379✔
162
        deleteRequestCancelInfoCount := len(req.DeleteRequestCancelInfos)
4,379✔
163

4,379✔
164
        transferTasksCount := len(req.TransferTasks)
4,379✔
165
        crossClusterTasksCount := len(req.CrossClusterTasks)
4,379✔
166
        timerTasksCount := len(req.TimerTasks)
4,379✔
167
        replicationTasksCount := len(req.ReplicationTasks)
4,379✔
168

4,379✔
169
        totalSize := executionInfoSize
4,379✔
170
        totalSize += activityInfoSize
4,379✔
171
        totalSize += timerInfoSize
4,379✔
172
        totalSize += childExecutionInfoSize
4,379✔
173
        totalSize += signalInfoSize
4,379✔
174
        totalSize += bufferedEventsSize
4,379✔
175

4,379✔
176
        return &MutableStateUpdateSessionStats{
4,379✔
177
                MutableStateSize:             totalSize,
4,379✔
178
                ExecutionInfoSize:            executionInfoSize,
4,379✔
179
                ActivityInfoSize:             activityInfoSize,
4,379✔
180
                TimerInfoSize:                timerInfoSize,
4,379✔
181
                ChildInfoSize:                childExecutionInfoSize,
4,379✔
182
                SignalInfoSize:               signalInfoSize,
4,379✔
183
                BufferedEventsSize:           bufferedEventsSize,
4,379✔
184
                ActivityInfoCount:            activityInfoCount,
4,379✔
185
                TimerInfoCount:               timerInfoCount,
4,379✔
186
                ChildInfoCount:               childExecutionInfoCount,
4,379✔
187
                SignalInfoCount:              signalInfoCount,
4,379✔
188
                RequestCancelInfoCount:       requestCancelInfoCount,
4,379✔
189
                DeleteActivityInfoCount:      deleteActivityInfoCount,
4,379✔
190
                DeleteTimerInfoCount:         deleteTimerInfoCount,
4,379✔
191
                DeleteChildInfoCount:         deleteChildInfoCount,
4,379✔
192
                DeleteSignalInfoCount:        deleteSignalInfoCount,
4,379✔
193
                DeleteRequestCancelInfoCount: deleteRequestCancelInfoCount,
4,379✔
194
                TransferTasksCount:           transferTasksCount,
4,379✔
195
                CrossClusterTaskCount:        crossClusterTasksCount,
4,379✔
196
                TimerTasksCount:              timerTasksCount,
4,379✔
197
                ReplicationTasksCount:        replicationTasksCount,
4,379✔
198
        }
4,379✔
199
}
200

201
func (sc *statsComputer) computeWorkflowSnapshotStats(req *InternalWorkflowSnapshot) *MutableStateUpdateSessionStats {
678✔
202
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
678✔
203

678✔
204
        activityInfoCount := 0
678✔
205
        activityInfoSize := 0
678✔
206
        for _, ai := range req.ActivityInfos {
701✔
207
                activityInfoCount++
23✔
208
                activityInfoSize += computeActivityInfoSize(ai)
23✔
209
        }
23✔
210

211
        timerInfoCount := 0
678✔
212
        timerInfoSize := 0
678✔
213
        for _, ti := range req.TimerInfos {
681✔
214
                timerInfoCount++
3✔
215
                timerInfoSize += computeTimerInfoSize(ti)
3✔
216
        }
3✔
217

218
        childExecutionInfoCount := 0
678✔
219
        childExecutionInfoSize := 0
678✔
220
        for _, ci := range req.ChildExecutionInfos {
683✔
221
                childExecutionInfoCount++
5✔
222
                childExecutionInfoSize += computeChildInfoSize(ci)
5✔
223
        }
5✔
224

225
        signalInfoCount := 0
678✔
226
        signalInfoSize := 0
678✔
227
        for _, si := range req.SignalInfos {
679✔
228
                signalInfoCount++
1✔
229
                signalInfoSize += computeSignalInfoSize(si)
1✔
230
        }
1✔
231

232
        requestCancelInfoCount := len(req.RequestCancelInfos)
678✔
233

678✔
234
        transferTasksCount := len(req.TransferTasks)
678✔
235
        crossClusterTasksCount := len(req.CrossClusterTasks)
678✔
236
        timerTasksCount := len(req.TimerTasks)
678✔
237
        replicationTasksCount := len(req.ReplicationTasks)
678✔
238

678✔
239
        totalSize := executionInfoSize
678✔
240
        totalSize += activityInfoSize
678✔
241
        totalSize += timerInfoSize
678✔
242
        totalSize += childExecutionInfoSize
678✔
243
        totalSize += signalInfoSize
678✔
244

678✔
245
        return &MutableStateUpdateSessionStats{
678✔
246
                MutableStateSize:       totalSize,
678✔
247
                ExecutionInfoSize:      executionInfoSize,
678✔
248
                ActivityInfoSize:       activityInfoSize,
678✔
249
                TimerInfoSize:          timerInfoSize,
678✔
250
                ChildInfoSize:          childExecutionInfoSize,
678✔
251
                SignalInfoSize:         signalInfoSize,
678✔
252
                ActivityInfoCount:      activityInfoCount,
678✔
253
                TimerInfoCount:         timerInfoCount,
678✔
254
                ChildInfoCount:         childExecutionInfoCount,
678✔
255
                SignalInfoCount:        signalInfoCount,
678✔
256
                RequestCancelInfoCount: requestCancelInfoCount,
678✔
257
                TransferTasksCount:     transferTasksCount,
678✔
258
                CrossClusterTaskCount:  crossClusterTasksCount,
678✔
259
                TimerTasksCount:        timerTasksCount,
678✔
260
                ReplicationTasksCount:  replicationTasksCount,
678✔
261
        }
678✔
262
}
263

264
func mergeMutableStateUpdateSessionStats(stats ...*MutableStateUpdateSessionStats) *MutableStateUpdateSessionStats {
176✔
265
        result := &MutableStateUpdateSessionStats{}
176✔
266
        for _, s := range stats {
525✔
267
                result.MutableStateSize += s.MutableStateSize
349✔
268

349✔
269
                result.ExecutionInfoSize += s.ExecutionInfoSize
349✔
270
                result.ActivityInfoSize += s.ActivityInfoSize
349✔
271
                result.TimerInfoSize += s.TimerInfoSize
349✔
272
                result.ChildInfoSize += s.ChildInfoSize
349✔
273
                result.SignalInfoSize += s.SignalInfoSize
349✔
274
                result.BufferedEventsSize += s.BufferedEventsSize
349✔
275

349✔
276
                result.ActivityInfoCount += s.ActivityInfoCount
349✔
277
                result.TimerInfoCount += s.TimerInfoCount
349✔
278
                result.ChildInfoCount += s.ChildInfoCount
349✔
279
                result.SignalInfoCount += s.SignalInfoCount
349✔
280
                result.RequestCancelInfoCount += s.RequestCancelInfoCount
349✔
281

349✔
282
                result.DeleteActivityInfoCount += s.DeleteActivityInfoCount
349✔
283
                result.DeleteTimerInfoCount += s.DeleteTimerInfoCount
349✔
284
                result.DeleteChildInfoCount += s.DeleteChildInfoCount
349✔
285
                result.DeleteSignalInfoCount += s.DeleteSignalInfoCount
349✔
286
                result.DeleteRequestCancelInfoCount += s.DeleteRequestCancelInfoCount
349✔
287

349✔
288
                result.TransferTasksCount += s.TransferTasksCount
349✔
289
                result.CrossClusterTaskCount += s.CrossClusterTaskCount
349✔
290
                result.TimerInfoCount += s.TimerInfoCount
349✔
291
                result.ReplicationTasksCount += s.ReplicationTasksCount
349✔
292
        }
349✔
293
        return result
176✔
294
}
295

296
func computeExecutionInfoSize(executionInfo *InternalWorkflowExecutionInfo) int {
5,790✔
297
        size := len(executionInfo.WorkflowID)
5,790✔
298
        size += len(executionInfo.TaskList)
5,790✔
299
        size += len(executionInfo.WorkflowTypeName)
5,790✔
300
        size += len(executionInfo.ParentWorkflowID)
5,790✔
301

5,790✔
302
        return size
5,790✔
303
}
5,790✔
304

305
func computeActivityInfoSize(ai *InternalActivityInfo) int {
1,353✔
306
        size := len(ai.ActivityID)
1,353✔
307
        if ai.ScheduledEvent != nil {
1,353✔
308
                size += len(ai.ScheduledEvent.Data)
×
309
        }
×
310
        if ai.StartedEvent != nil {
1,353✔
311
                size += len(ai.StartedEvent.Data)
×
312
        }
×
313
        size += len(ai.Details)
1,353✔
314

1,353✔
315
        return size
1,353✔
316
}
317

318
func computeTimerInfoSize(ti *TimerInfo) int {
41✔
319
        size := len(ti.TimerID)
41✔
320

41✔
321
        return size
41✔
322
}
41✔
323

324
func computeChildInfoSize(ci *InternalChildExecutionInfo) int {
52✔
325
        size := 0
52✔
326
        if ci.InitiatedEvent != nil {
52✔
327
                size += len(ci.InitiatedEvent.Data)
×
328
        }
×
329
        if ci.StartedEvent != nil {
52✔
330
                size += len(ci.StartedEvent.Data)
×
331
        }
×
332
        return size
52✔
333
}
334

335
func computeSignalInfoSize(si *SignalInfo) int {
19✔
336
        size := len(si.SignalName)
19✔
337
        size += len(si.Input)
19✔
338
        size += len(si.Control)
19✔
339

19✔
340
        return size
19✔
341
}
19✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc