@@ -940,6 +940,11 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessEvent(
940
940
return err
941
941
}
942
942
943
+ //historySizeErr := weh.estimateHistorySize(event)
944
+ //if historySizeErr != nil {
945
+ // weh.logger.Error("Failed to estimate history size", zap.Error(historySizeErr))
946
+ //}
947
+
943
948
// When replaying histories to get stack trace or current state the last event might be not
944
949
// decision started. So always call OnDecisionTaskStarted on the last event.
945
950
// Don't call for EventType_DecisionTaskStarted as it was already called when handling it.
@@ -1379,3 +1384,108 @@ func (weh *workflowExecutionEventHandlerImpl) handleSignalExternalWorkflowExecut
1379
1384
1380
1385
return nil
1381
1386
}
1387
+
1388
+ func (weh * workflowExecutionEventHandlerImpl ) estimateHistorySize (event * m.HistoryEvent ) error {
1389
+ sum := 0
1390
+ switch event .GetEventType () {
1391
+ case m .EventTypeWorkflowExecutionStarted :
1392
+ if event .WorkflowExecutionStartedEventAttributes != nil {
1393
+ sum += len (event .WorkflowExecutionStartedEventAttributes .Input )
1394
+ sum += len (event .WorkflowExecutionStartedEventAttributes .ContinuedFailureDetails )
1395
+ sum += len (event .WorkflowExecutionStartedEventAttributes .LastCompletionResult )
1396
+ sum += len (event .WorkflowExecutionStartedEventAttributes .Memo .GetFields ())
1397
+ }
1398
+ case m .EventTypeWorkflowExecutionSignaled :
1399
+ if event .WorkflowExecutionSignaledEventAttributes != nil {
1400
+ sum += len (event .WorkflowExecutionSignaledEventAttributes .Input )
1401
+ }
1402
+ case m .EventTypeWorkflowExecutionFailed :
1403
+ if event .WorkflowExecutionFailedEventAttributes != nil {
1404
+ sum += len (event .WorkflowExecutionFailedEventAttributes .Details )
1405
+ }
1406
+ case m .EventTypeDecisionTaskCompleted :
1407
+ if event .DecisionTaskCompletedEventAttributes != nil {
1408
+ sum += len (event .DecisionTaskCompletedEventAttributes .ExecutionContext )
1409
+ }
1410
+ case m .EventTypeDecisionTaskFailed :
1411
+ if event .DecisionTaskFailedEventAttributes != nil {
1412
+ sum += len (event .DecisionTaskFailedEventAttributes .Details )
1413
+ }
1414
+ case m .EventTypeActivityTaskScheduled :
1415
+ if event .ActivityTaskScheduledEventAttributes != nil {
1416
+ sum += len (event .ActivityTaskScheduledEventAttributes .Input )
1417
+ sum += len (event .ActivityTaskScheduledEventAttributes .Header .GetFields ())
1418
+ }
1419
+ case m .EventTypeActivityTaskStarted :
1420
+ if event .ActivityTaskStartedEventAttributes != nil {
1421
+ sum += len (event .ActivityTaskStartedEventAttributes .LastFailureDetails )
1422
+ }
1423
+ case m .EventTypeActivityTaskCompleted :
1424
+ if event .ActivityTaskCompletedEventAttributes != nil {
1425
+ sum += len (event .ActivityTaskCompletedEventAttributes .Result )
1426
+ }
1427
+ case m .EventTypeActivityTaskFailed :
1428
+ if event .ActivityTaskFailedEventAttributes != nil {
1429
+ sum += len (event .ActivityTaskFailedEventAttributes .Details )
1430
+ }
1431
+ case m .EventTypeActivityTaskTimedOut :
1432
+ if event .ActivityTaskTimedOutEventAttributes != nil {
1433
+ sum += len (event .ActivityTaskTimedOutEventAttributes .Details )
1434
+ sum += len (event .ActivityTaskTimedOutEventAttributes .LastFailureDetails )
1435
+ }
1436
+ case m .EventTypeActivityTaskCanceled :
1437
+ if event .ActivityTaskCanceledEventAttributes != nil {
1438
+ sum += len (event .ActivityTaskCanceledEventAttributes .Details )
1439
+ }
1440
+ case m .EventTypeMarkerRecorded :
1441
+ if event .MarkerRecordedEventAttributes != nil {
1442
+ sum += len (event .MarkerRecordedEventAttributes .Details )
1443
+ }
1444
+ case m .EventTypeWorkflowExecutionTerminated :
1445
+ if event .WorkflowExecutionTerminatedEventAttributes != nil {
1446
+ sum += len (event .WorkflowExecutionTerminatedEventAttributes .Details )
1447
+ }
1448
+ case m .EventTypeWorkflowExecutionCanceled :
1449
+ if event .WorkflowExecutionCanceledEventAttributes != nil {
1450
+ sum += len (event .WorkflowExecutionCanceledEventAttributes .Details )
1451
+ }
1452
+ case m .EventTypeWorkflowExecutionContinuedAsNew :
1453
+ if event .WorkflowExecutionContinuedAsNewEventAttributes != nil {
1454
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Input )
1455
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .FailureDetails )
1456
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .LastCompletionResult )
1457
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Memo .GetFields ())
1458
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Header .GetFields ())
1459
+ sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .SearchAttributes .GetIndexedFields ())
1460
+ }
1461
+ case m .EventTypeStartChildWorkflowExecutionInitiated :
1462
+ if event .StartChildWorkflowExecutionInitiatedEventAttributes != nil {
1463
+ sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Input )
1464
+ sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Control )
1465
+ sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Memo .GetFields ())
1466
+ sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Header .GetFields ())
1467
+ sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .SearchAttributes .GetIndexedFields ())
1468
+ }
1469
+ case m .EventTypeChildWorkflowExecutionCompleted :
1470
+ if event .ChildWorkflowExecutionCompletedEventAttributes != nil {
1471
+ sum += len (event .ChildWorkflowExecutionCompletedEventAttributes .Result )
1472
+ }
1473
+ case m .EventTypeChildWorkflowExecutionFailed :
1474
+ if event .ChildWorkflowExecutionFailedEventAttributes != nil {
1475
+ sum += len (event .ChildWorkflowExecutionFailedEventAttributes .Details )
1476
+ }
1477
+ case m .EventTypeChildWorkflowExecutionCanceled :
1478
+ if event .ChildWorkflowExecutionCanceledEventAttributes != nil {
1479
+ sum += len (event .ChildWorkflowExecutionCanceledEventAttributes .Details )
1480
+ }
1481
+ case m .EventTypeSignalExternalWorkflowExecutionInitiated :
1482
+ if event .SignalExternalWorkflowExecutionInitiatedEventAttributes != nil {
1483
+ sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Control )
1484
+ sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Input )
1485
+ }
1486
+ default :
1487
+ return fmt .Errorf ("unknown event type" )
1488
+ }
1489
+ weh .workflowInfo .TotalHistoryBytes += int64 (sum )
1490
+ return nil
1491
+ }
0 commit comments