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

uber / cadence / 01907298-99db-4403-a675-2e4158bcca0f

02 Jul 2024 08:38AM UTC coverage: 71.522%. Remained the same
01907298-99db-4403-a675-2e4158bcca0f

Pull #6025

buildkite

mantas-sidlauskas
check if modifying copy will not change original value
Pull Request #6025: add Copy() method to configstore structs

41 of 41 new or added lines in 2 files covered. (100.0%)

41 existing lines in 14 files now uncovered.

105309 of 147241 relevant lines covered (71.52%)

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

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

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

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

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

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

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

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

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

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

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

101
func (sc *statsComputer) computeMutableStateCreateStats(req *InternalCreateWorkflowExecutionRequest) *MutableStateUpdateSessionStats {
528✔
102
        return sc.computeWorkflowSnapshotStats(&req.NewWorkflowSnapshot)
528✔
103
}
528✔
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,445✔
117
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
4,445✔
118

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

703✔
242
        return &MutableStateUpdateSessionStats{
703✔
243
                MutableStateSize:       totalSize,
703✔
244
                ExecutionInfoSize:      executionInfoSize,
703✔
245
                ActivityInfoSize:       activityInfoSize,
703✔
246
                TimerInfoSize:          timerInfoSize,
703✔
247
                ChildInfoSize:          childExecutionInfoSize,
703✔
248
                SignalInfoSize:         signalInfoSize,
703✔
249
                ActivityInfoCount:      activityInfoCount,
703✔
250
                TimerInfoCount:         timerInfoCount,
703✔
251
                ChildInfoCount:         childExecutionInfoCount,
703✔
252
                SignalInfoCount:        signalInfoCount,
703✔
253
                RequestCancelInfoCount: requestCancelInfoCount,
703✔
254
                TransferTasksCount:     transferTasksCount,
703✔
255
                TimerTasksCount:        timerTasksCount,
703✔
256
                ReplicationTasksCount:  replicationTasksCount,
703✔
257
        }
703✔
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,883✔
292
        size := len(executionInfo.WorkflowID)
5,883✔
293
        size += len(executionInfo.TaskList)
5,883✔
294
        size += len(executionInfo.WorkflowTypeName)
5,883✔
295
        size += len(executionInfo.ParentWorkflowID)
5,883✔
296

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

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

1,395✔
310
        return size
1,395✔
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