-
Notifications
You must be signed in to change notification settings - Fork 800
/
helpers.go
362 lines (316 loc) · 15 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package logging
import (
"github.com/uber-common/bark"
"github.com/uber/cadence/.gen/go/shared"
)
//
// Common logging methods
//
// LogPersistantStoreErrorEvent is used to log errors from persistence layer.
func LogPersistantStoreErrorEvent(logger bark.Logger, operation string, err error, details string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: PersistentStoreErrorEventID,
TagStoreOperation: operation,
TagWorkflowErr: err,
}).Errorf("Persistent store operation failure. Operation Details: %v", details)
}
// LogTransferTaskProcessingFailedEvent is used to log failures from transfer task processing.
func LogTransferTaskProcessingFailedEvent(logger bark.Logger, taskID int64, taskType int, err error) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferTaskProcessingFailed,
TagTaskID: taskID,
TagTaskType: taskType,
TagWorkflowErr: err,
}).Errorf("Processor failed to process transfer task: %v, type: %v. Error: %v", taskID, taskType, err)
}
// LogOperationFailedEvent is used to log generic operation failures.
func LogOperationFailedEvent(logger bark.Logger, msg string, err error) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: OperationFailed,
TagWorkflowErr: err,
}).Warnf("%v. Error: %v", msg, err)
}
// LogOperationPanicEvent is used to log fatal errors by application to cause panic
func LogOperationPanicEvent(logger bark.Logger, msg string, err error) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: OperationPanic,
TagWorkflowErr: err,
}).Fatalf("%v. Error: %v", msg, err)
}
//
// History service logging methods
//
// LogInvalidHistoryActionEvent is used to log invalid history builder state
func LogInvalidHistoryActionEvent(logger bark.Logger, action string, eventID int64, state string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: InvalidHistoryActionEventID,
TagHistoryBuilderAction: action,
}).Warnf("Invalid history builder state for action: EventID: %v, State: %v", eventID, state)
}
// LogHistorySerializationErrorEvent is used to log errors serializing execution history
func LogHistorySerializationErrorEvent(logger bark.Logger, err error, msg string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistorySerializationErrorEventID,
TagWorkflowErr: err,
}).Errorf("Error serializing workflow execution history. Msg: %v", msg)
}
// LogHistoryDeserializationErrorEvent is used to log errors deserializing execution history
func LogHistoryDeserializationErrorEvent(logger bark.Logger, err error, msg string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistoryDeserializationErrorEventID,
TagWorkflowErr: err,
}).Errorf("Error deserializing workflow execution history. Msg: %v", msg)
}
// LogHistoryEngineStartingEvent is used to log history engine starting
func LogHistoryEngineStartingEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistoryEngineStarting,
}).Info("HistoryEngine starting.")
}
// LogHistoryEngineStartedEvent is used to log history engine started
func LogHistoryEngineStartedEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistoryEngineStarted,
}).Info("HistoryEngine started.")
}
// LogHistoryEngineShuttingDownEvent is used to log history shutting down
func LogHistoryEngineShuttingDownEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistoryEngineShuttingDown,
}).Info("HistoryEngine shutting down.")
}
// LogHistoryEngineShutdownEvent is used to log history shut down complete
func LogHistoryEngineShutdownEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: HistoryEngineShutdown,
}).Info("HistoryEngine shutdown.")
}
// LogDuplicateTaskEvent is used to log the event when a duplicate task is detected
func LogDuplicateTaskEvent(lg bark.Logger, taskType int, taskID int64, requestID string, scheduleID, startedID int64,
isRunning bool) {
lg.WithFields(bark.Fields{
TagWorkflowEventID: DuplicateTaskEventID,
}).Debugf("Potentially duplicate task. TaskID: %v, TaskType: %v, RequestID: %v, scheduleID: %v, startedID: %v, isRunning: %v",
taskID, taskType, requestID, scheduleID, startedID, isRunning)
}
// LogDuplicateTransferTaskEvent is used to log the event when duplicate processing of the same transfer task is detected
func LogDuplicateTransferTaskEvent(lg bark.Logger, taskType int, taskID int64, scheduleID int64) {
lg.WithFields(bark.Fields{
TagWorkflowEventID: DuplicateTransferTaskEventID,
}).Debugf("Potentially duplicate task. TaskID: %v, TaskType: %v, scheduleID: %v",
taskID, taskType, scheduleID)
}
// LogTransferQueueProcesorStartingEvent is used to log transfer queue processor starting
func LogTransferQueueProcesorStartingEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferQueueProcessorStarting,
}).Info("Transfer queue processor starting.")
}
// LogTransferQueueProcesorStartedEvent is used to log transfer queue processor started
func LogTransferQueueProcesorStartedEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferQueueProcessorStarted,
}).Info("Transfer queue processor started.")
}
// LogTransferQueueProcesorShuttingDownEvent is used to log transfer queue processing shutting down
func LogTransferQueueProcesorShuttingDownEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferQueueProcessorShuttingDown,
}).Info("Transfer queue processor shutting down.")
}
// LogTransferQueueProcesorShutdownEvent is used to log transfer queue processor shutdown complete
func LogTransferQueueProcesorShutdownEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferQueueProcessorShutdown,
}).Info("Transfer queue processor shutdown.")
}
// LogTransferQueueProcesorShutdownTimedoutEvent is used to log timeout during transfer queue processor shutdown
func LogTransferQueueProcesorShutdownTimedoutEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TransferQueueProcessorShutdownTimedout,
}).Warn("Transfer queue processor timedout on shutdown.")
}
// LogShardRangeUpdatedEvent is used to log rangeID update for a shard
func LogShardRangeUpdatedEvent(logger bark.Logger, shardID int, rangeID, startSequence, endSequence int64) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardRangeUpdatedEventID,
}).Infof("Range updated for shardID '%v'. RangeID: %v, StartSequence: %v, EndSequence: %v", shardID,
rangeID, startSequence, endSequence)
}
// LogShardControllerStartedEvent is used to log shard controller started
func LogShardControllerStartedEvent(logger bark.Logger, host string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardControllerStarted,
}).Infof("ShardController started on host: %v", host)
}
// LogShardControllerShutdownEvent is used to log shard controller shutdown complete
func LogShardControllerShutdownEvent(logger bark.Logger, host string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardControllerShutdown,
}).Infof("ShardController stopped on host: %v", host)
}
// LogShardControllerShuttingDownEvent is used to log shard controller shutting down
func LogShardControllerShuttingDownEvent(logger bark.Logger, host string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardControllerShuttingDown,
}).Infof("ShardController stopping on host: %v", host)
}
// LogShardControllerShutdownTimedoutEvent is used to log timeout during shard controller shutdown
func LogShardControllerShutdownTimedoutEvent(logger bark.Logger, host string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardControllerShutdownTimedout,
}).Warnf("ShardController timed out during shutdown on host: %v", host)
}
// LogRingMembershipChangedEvent is used to log membership changes events received by shard controller
func LogRingMembershipChangedEvent(logger bark.Logger, host string, added, removed, updated int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: RingMembershipChangedEvent,
}).Infof("ShardController on host '%v' received ring membership changed event: {Added: %v, Removed: %v, Updated: %v}",
host, added, removed, updated)
}
// LogShardClosedEvent is used to log shard closed event
func LogShardClosedEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardClosedEvent,
TagHistoryShardID: shardID,
}).Infof("ShardController on host '%v' received shard closed event for shardID: %v", host, shardID)
}
// LogShardItemCreatedEvent is used to log creation of a shard item
func LogShardItemCreatedEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardItemCreated,
}).Infof("ShardController on host '%v' created a shard item for shardID '%v'.", host, shardID)
}
// LogShardItemRemovedEvent is used to log removal of a shard item
func LogShardItemRemovedEvent(logger bark.Logger, host string, shardID int, remainingShards int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardItemRemoved,
}).Infof("ShardController on host '%v' removed shard item for shardID '%v'. Remaining number of shards: %v",
host, shardID, remainingShards)
}
// LogShardEngineCreatingEvent is used to log start of history engine creation
func LogShardEngineCreatingEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardEngineCreating,
}).Infof("ShardController on host '%v' creating engine for shardID '%v'.", host, shardID)
}
// LogShardEngineCreatedEvent is used to log completion of history engine creation
func LogShardEngineCreatedEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardEngineCreated,
}).Infof("ShardController on host '%v' created engine for shardID '%v'.", host, shardID)
}
// LogShardEngineStoppingEvent is used to log when stopping engine for a shard has started
func LogShardEngineStoppingEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardEngineStopping,
}).Infof("ShardController on host '%v' stopping engine for shardID '%v'.", host, shardID)
}
// LogShardEngineStoppedEvent is used to log when stopping engine for a shard has completed
func LogShardEngineStoppedEvent(logger bark.Logger, host string, shardID int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: ShardEngineStopped,
}).Infof("ShardController on host '%v' stopped engine for shardID '%v'.", host, shardID)
}
// LogMutableStateInvalidAction is used to log invalid mutable state builder state
func LogMutableStateInvalidAction(logger bark.Logger, errorMsg string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: InvalidMutableStateActionEventID,
}).Errorf("%v. ", errorMsg)
}
// LogMultipleCompletionDecisionsEvent is used to log multiple completion decisions for an execution
func LogMultipleCompletionDecisionsEvent(lg bark.Logger, decisionType shared.DecisionType) {
lg.WithFields(bark.Fields{
TagWorkflowEventID: MultipleCompletionDecisionsEventID,
TagDecisionType: decisionType,
}).Warnf("Multiple completion decisions. DecisionType: %v", decisionType)
}
// LogDecisionFailedEvent is used to log decision failures by RespondDecisionTaskCompleted handler
func LogDecisionFailedEvent(lg bark.Logger, domainID, workflowID, runID string,
failCause shared.DecisionTaskFailedCause) {
lg.WithFields(bark.Fields{
TagWorkflowEventID: DecisionFailedEventID,
TagDomainID: domainID,
TagWorkflowExecutionID: workflowID,
TagWorkflowRunID: runID,
TagDecisionFailCause: failCause,
}).Info("Failing the decision.")
}
//
// Matching service logging methods
//
// LogTaskListLoadingEvent is used to log starting of a new task list loading
func LogTaskListLoadingEvent(logger bark.Logger, taskListName string, taskListType int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TaskListLoading,
TagTaskListName: taskListName,
TagTaskListType: taskListType,
}).Info("Loading TaskList.")
}
// LogTaskListLoadedEvent is used to log completion of a new task list loading
func LogTaskListLoadedEvent(logger bark.Logger, taskListName string, taskListType int) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TaskListLoaded,
TagTaskListName: taskListName,
TagTaskListType: taskListType,
}).Info("Loaded TaskList.")
}
// LogTaskListLoadingFailedEvent is used to log failure of a new task list loading
func LogTaskListLoadingFailedEvent(logger bark.Logger, taskListName string, taskListType int, err error) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TaskListLoadingFailed,
TagTaskListName: taskListName,
TagTaskListType: taskListType,
TagWorkflowErr: err,
}).Info("Loading TaskList failed.")
}
// LogTaskListUnloadingEvent is used to log starting of a task list unloading
func LogTaskListUnloadingEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TaskListUnloading,
}).Info("Unloading TaskList.")
}
// LogTaskListUnloadedEvent is used to log completion of a task list unloading
func LogTaskListUnloadedEvent(logger bark.Logger) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: TaskListUnloaded,
}).Info("Unloaded TaskList.")
}
// LogQueryTaskMissingWorkflowTypeErrorEvent is used to log invalid query task that is missing workflow type
func LogQueryTaskMissingWorkflowTypeErrorEvent(logger bark.Logger, workflowID, runID, queryType string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: InvalidQueryTaskEventID,
"WorkflowID": workflowID,
"RunID": runID,
"QueryType": queryType,
}).Error("Cannot get WorkflowType for QueryTask.")
}
// LogQueryTaskFailedEvent is used to log query task failure
func LogQueryTaskFailedEvent(logger bark.Logger, domain, workflowID, runID, queryType string) {
logger.WithFields(bark.Fields{
TagWorkflowEventID: QueryTaskFailedEventID,
"Domain": domain,
"WorkflowID": workflowID,
"RunID": runID,
"QueryType": queryType,
}).Info("QueryWorkflowFailed.")
}