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

uber / cadence / 01907299-3fb0-4ecc-b0ad-df71b17f5ddc

02 Jul 2024 08:39AM UTC coverage: 71.517% (-0.005%) from 71.522%
01907299-3fb0-4ecc-b0ad-df71b17f5ddc

Pull #5926

buildkite

mantas-sidlauskas
Add peer provider plugin registration
Pull Request #5926: Add peer provider plugin registration

20 of 22 new or added lines in 1 file covered. (90.91%)

36 existing lines in 12 files now uncovered.

105326 of 147274 relevant lines covered (71.52%)

2598.44 hits per line

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

98.18
/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 {
740✔
30
        executionInfoSize := computeExecutionInfoSize(req.State.ExecutionInfo)
740✔
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

199
func (sc *statsComputer) computeWorkflowSnapshotStats(req *InternalWorkflowSnapshot) *MutableStateUpdateSessionStats {
702✔
200
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
702✔
201

702✔
202
        activityInfoCount := 0
702✔
203
        activityInfoSize := 0
702✔
204
        for _, ai := range req.ActivityInfos {
729✔
205
                activityInfoCount++
27✔
206
                activityInfoSize += computeActivityInfoSize(ai)
27✔
207
        }
27✔
208

209
        timerInfoCount := 0
702✔
210
        timerInfoSize := 0
702✔
211
        for _, ti := range req.TimerInfos {
713✔
212
                timerInfoCount++
11✔
213
                timerInfoSize += computeTimerInfoSize(ti)
11✔
214
        }
11✔
215

216
        childExecutionInfoCount := 0
702✔
217
        childExecutionInfoSize := 0
702✔
218
        for _, ci := range req.ChildExecutionInfos {
712✔
219
                childExecutionInfoCount++
10✔
220
                childExecutionInfoSize += computeChildInfoSize(ci)
10✔
221
        }
10✔
222

223
        signalInfoCount := 0
702✔
224
        signalInfoSize := 0
702✔
225
        for _, si := range req.SignalInfos {
703✔
226
                signalInfoCount++
1✔
227
                signalInfoSize += computeSignalInfoSize(si)
1✔
228
        }
1✔
229

230
        requestCancelInfoCount := len(req.RequestCancelInfos)
702✔
231

702✔
232
        transferTasksCount := len(req.TransferTasks)
702✔
233
        timerTasksCount := len(req.TimerTasks)
702✔
234
        replicationTasksCount := len(req.ReplicationTasks)
702✔
235

702✔
236
        totalSize := executionInfoSize
702✔
237
        totalSize += activityInfoSize
702✔
238
        totalSize += timerInfoSize
702✔
239
        totalSize += childExecutionInfoSize
702✔
240
        totalSize += signalInfoSize
702✔
241

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

260
func mergeMutableStateUpdateSessionStats(stats ...*MutableStateUpdateSessionStats) *MutableStateUpdateSessionStats {
176✔
261
        result := &MutableStateUpdateSessionStats{}
176✔
262
        for _, s := range stats {
525✔
263
                result.MutableStateSize += s.MutableStateSize
349✔
264

349✔
265
                result.ExecutionInfoSize += s.ExecutionInfoSize
349✔
266
                result.ActivityInfoSize += s.ActivityInfoSize
349✔
267
                result.TimerInfoSize += s.TimerInfoSize
349✔
268
                result.ChildInfoSize += s.ChildInfoSize
349✔
269
                result.SignalInfoSize += s.SignalInfoSize
349✔
270
                result.BufferedEventsSize += s.BufferedEventsSize
349✔
271

349✔
272
                result.ActivityInfoCount += s.ActivityInfoCount
349✔
273
                result.TimerInfoCount += s.TimerInfoCount
349✔
274
                result.ChildInfoCount += s.ChildInfoCount
349✔
275
                result.SignalInfoCount += s.SignalInfoCount
349✔
276
                result.RequestCancelInfoCount += s.RequestCancelInfoCount
349✔
277

349✔
278
                result.DeleteActivityInfoCount += s.DeleteActivityInfoCount
349✔
279
                result.DeleteTimerInfoCount += s.DeleteTimerInfoCount
349✔
280
                result.DeleteChildInfoCount += s.DeleteChildInfoCount
349✔
281
                result.DeleteSignalInfoCount += s.DeleteSignalInfoCount
349✔
282
                result.DeleteRequestCancelInfoCount += s.DeleteRequestCancelInfoCount
349✔
283

349✔
284
                result.TransferTasksCount += s.TransferTasksCount
349✔
285
                result.TimerInfoCount += s.TimerInfoCount
349✔
286
                result.ReplicationTasksCount += s.ReplicationTasksCount
349✔
287
        }
349✔
288
        return result
176✔
289
}
290

291
func computeExecutionInfoSize(executionInfo *InternalWorkflowExecutionInfo) int {
5,885✔
292
        size := len(executionInfo.WorkflowID)
5,885✔
293
        size += len(executionInfo.TaskList)
5,885✔
294
        size += len(executionInfo.WorkflowTypeName)
5,885✔
295
        size += len(executionInfo.ParentWorkflowID)
5,885✔
296

5,885✔
297
        return size
5,885✔
298
}
5,885✔
299

300
func computeActivityInfoSize(ai *InternalActivityInfo) int {
1,407✔
301
        size := len(ai.ActivityID)
1,407✔
302
        if ai.ScheduledEvent != nil {
1,415✔
303
                size += len(ai.ScheduledEvent.Data)
8✔
304
        }
8✔
305
        if ai.StartedEvent != nil {
1,415✔
306
                size += len(ai.StartedEvent.Data)
8✔
307
        }
8✔
308
        size += len(ai.Details)
1,407✔
309

1,407✔
310
        return size
1,407✔
311
}
312

313
func computeTimerInfoSize(ti *TimerInfo) int {
52✔
314
        size := len(ti.TimerID)
52✔
315

52✔
316
        return size
52✔
317
}
52✔
318

319
func computeChildInfoSize(ci *InternalChildExecutionInfo) int {
58✔
320
        size := 0
58✔
321
        if ci.InitiatedEvent != nil {
64✔
322
                size += len(ci.InitiatedEvent.Data)
6✔
323
        }
6✔
324
        if ci.StartedEvent != nil {
64✔
325
                size += len(ci.StartedEvent.Data)
6✔
326
        }
6✔
327
        return size
58✔
328
}
329

330
func computeSignalInfoSize(si *SignalInfo) int {
19✔
331
        size := len(si.SignalName)
19✔
332
        size += len(si.Input)
19✔
333
        size += len(si.Control)
19✔
334

19✔
335
        return size
19✔
336
}
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