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

uber / cadence / 01905aec-bedd-4111-bd52-6ddaf1aa974a

27 Jun 2024 06:17PM UTC coverage: 71.432% (-0.002%) from 71.434%
01905aec-bedd-4111-bd52-6ddaf1aa974a

push

buildkite

web-flow
Add duplicate workflowID/runID/workflowType columns used for Pinot prefix text match (#6149)

4 of 4 new or added lines in 1 file covered. (100.0%)

32 existing lines in 11 files now uncovered.

104678 of 146542 relevant lines covered (71.43%)

2647.25 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 {
853✔
35
                activityInfoCount++
114✔
36
                activityInfoSize += computeActivityInfoSize(ai)
114✔
37
        }
114✔
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 {
744✔
49
                childExecutionInfoCount++
5✔
50
                childExecutionInfoSize += computeChildInfoSize(ci)
5✔
51
        }
5✔
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,447✔
95
        if req.NewWorkflowSnapshot != nil {
4,622✔
96
                return mergeMutableStateUpdateSessionStats(sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation), sc.computeWorkflowSnapshotStats(req.NewWorkflowSnapshot))
175✔
97
        }
175✔
98
        return sc.computeWorkflowMutationStats(&req.UpdateWorkflowMutation)
4,275✔
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,449✔
117
        executionInfoSize := computeExecutionInfoSize(req.ExecutionInfo)
4,449✔
118

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

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

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

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

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

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

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

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

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

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

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

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

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

4,449✔
175
        return &MutableStateUpdateSessionStats{
4,449✔
176
                MutableStateSize:             totalSize,
4,449✔
177
                ExecutionInfoSize:            executionInfoSize,
4,449✔
178
                ActivityInfoSize:             activityInfoSize,
4,449✔
179
                TimerInfoSize:                timerInfoSize,
4,449✔
180
                ChildInfoSize:                childExecutionInfoSize,
4,449✔
181
                SignalInfoSize:               signalInfoSize,
4,449✔
182
                BufferedEventsSize:           bufferedEventsSize,
4,449✔
183
                ActivityInfoCount:            activityInfoCount,
4,449✔
184
                TimerInfoCount:               timerInfoCount,
4,449✔
185
                ChildInfoCount:               childExecutionInfoCount,
4,449✔
186
                SignalInfoCount:              signalInfoCount,
4,449✔
187
                RequestCancelInfoCount:       requestCancelInfoCount,
4,449✔
188
                DeleteActivityInfoCount:      deleteActivityInfoCount,
4,449✔
189
                DeleteTimerInfoCount:         deleteTimerInfoCount,
4,449✔
190
                DeleteChildInfoCount:         deleteChildInfoCount,
4,449✔
191
                DeleteSignalInfoCount:        deleteSignalInfoCount,
4,449✔
192
                DeleteRequestCancelInfoCount: deleteRequestCancelInfoCount,
4,449✔
193
                TransferTasksCount:           transferTasksCount,
4,449✔
194
                TimerTasksCount:              timerTasksCount,
4,449✔
195
                ReplicationTasksCount:        replicationTasksCount,
4,449✔
196
        }
4,449✔
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 {
714✔
212
                timerInfoCount++
12✔
213
                timerInfoSize += computeTimerInfoSize(ti)
12✔
214
        }
12✔
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,886✔
292
        size := len(executionInfo.WorkflowID)
5,886✔
293
        size += len(executionInfo.TaskList)
5,886✔
294
        size += len(executionInfo.WorkflowTypeName)
5,886✔
295
        size += len(executionInfo.ParentWorkflowID)
5,886✔
296

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

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

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