@@ -942,7 +942,7 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessEvent(
942942 return err
943943 }
944944
945- historySum := weh . estimateHistorySize (event )
945+ historySum := estimateHistorySize (weh . logger , event )
946946 atomic .AddInt64 (& weh .workflowInfo .TotalHistoryBytes , int64 (historySum ))
947947
948948 // When replaying histories to get stack trace or current state the last event might be not
@@ -1384,139 +1384,3 @@ func (weh *workflowExecutionEventHandlerImpl) handleSignalExternalWorkflowExecut
13841384
13851385 return nil
13861386}
1387-
1388- func (weh * workflowExecutionEventHandlerImpl ) estimateHistorySize (event * m.HistoryEvent ) int {
1389- sum := historySizeEstimationBuffer
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 += sizeOf (event .WorkflowExecutionStartedEventAttributes .Memo .GetFields ())
1397- sum += sizeOf (event .WorkflowExecutionStartedEventAttributes .Header .GetFields ())
1398- sum += sizeOf (event .WorkflowExecutionStartedEventAttributes .SearchAttributes .GetIndexedFields ())
1399- }
1400- case m .EventTypeWorkflowExecutionCompleted :
1401- if event .WorkflowExecutionCompletedEventAttributes != nil {
1402- sum += len (event .WorkflowExecutionCompletedEventAttributes .Result )
1403- }
1404- case m .EventTypeWorkflowExecutionSignaled :
1405- if event .WorkflowExecutionSignaledEventAttributes != nil {
1406- sum += len (event .WorkflowExecutionSignaledEventAttributes .Input )
1407- }
1408- case m .EventTypeWorkflowExecutionFailed :
1409- if event .WorkflowExecutionFailedEventAttributes != nil {
1410- sum += len (event .WorkflowExecutionFailedEventAttributes .Details )
1411- }
1412- case m .EventTypeDecisionTaskStarted :
1413- if event .DecisionTaskStartedEventAttributes != nil {
1414- sum += getLengthOfStringPointer (event .DecisionTaskStartedEventAttributes .Identity )
1415- }
1416- case m .EventTypeDecisionTaskCompleted :
1417- if event .DecisionTaskCompletedEventAttributes != nil {
1418- sum += len (event .DecisionTaskCompletedEventAttributes .ExecutionContext )
1419- sum += getLengthOfStringPointer (event .DecisionTaskCompletedEventAttributes .Identity )
1420- sum += getLengthOfStringPointer (event .DecisionTaskCompletedEventAttributes .BinaryChecksum )
1421- }
1422- case m .EventTypeDecisionTaskFailed :
1423- if event .DecisionTaskFailedEventAttributes != nil {
1424- sum += len (event .DecisionTaskFailedEventAttributes .Details )
1425- }
1426- case m .EventTypeActivityTaskScheduled :
1427- if event .ActivityTaskScheduledEventAttributes != nil {
1428- sum += len (event .ActivityTaskScheduledEventAttributes .Input )
1429- sum += sizeOf (event .ActivityTaskScheduledEventAttributes .Header .GetFields ())
1430- }
1431- case m .EventTypeActivityTaskStarted :
1432- if event .ActivityTaskStartedEventAttributes != nil {
1433- sum += len (event .ActivityTaskStartedEventAttributes .LastFailureDetails )
1434- }
1435- case m .EventTypeActivityTaskCompleted :
1436- if event .ActivityTaskCompletedEventAttributes != nil {
1437- sum += len (event .ActivityTaskCompletedEventAttributes .Result )
1438- sum += getLengthOfStringPointer (event .ActivityTaskCompletedEventAttributes .Identity )
1439- }
1440- case m .EventTypeActivityTaskFailed :
1441- if event .ActivityTaskFailedEventAttributes != nil {
1442- sum += len (event .ActivityTaskFailedEventAttributes .Details )
1443- }
1444- case m .EventTypeActivityTaskTimedOut :
1445- if event .ActivityTaskTimedOutEventAttributes != nil {
1446- sum += len (event .ActivityTaskTimedOutEventAttributes .Details )
1447- sum += len (event .ActivityTaskTimedOutEventAttributes .LastFailureDetails )
1448- }
1449- case m .EventTypeActivityTaskCanceled :
1450- if event .ActivityTaskCanceledEventAttributes != nil {
1451- sum += len (event .ActivityTaskCanceledEventAttributes .Details )
1452- }
1453- case m .EventTypeMarkerRecorded :
1454- if event .MarkerRecordedEventAttributes != nil {
1455- sum += len (event .MarkerRecordedEventAttributes .Details )
1456- }
1457- case m .EventTypeWorkflowExecutionTerminated :
1458- if event .WorkflowExecutionTerminatedEventAttributes != nil {
1459- sum += len (event .WorkflowExecutionTerminatedEventAttributes .Details )
1460- }
1461- case m .EventTypeWorkflowExecutionCanceled :
1462- if event .WorkflowExecutionCanceledEventAttributes != nil {
1463- sum += len (event .WorkflowExecutionCanceledEventAttributes .Details )
1464- }
1465- case m .EventTypeWorkflowExecutionContinuedAsNew :
1466- if event .WorkflowExecutionContinuedAsNewEventAttributes != nil {
1467- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Input )
1468- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .FailureDetails )
1469- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .LastCompletionResult )
1470- sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .Memo .GetFields ())
1471- sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .Header .GetFields ())
1472- sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .SearchAttributes .GetIndexedFields ())
1473- }
1474- case m .EventTypeStartChildWorkflowExecutionInitiated :
1475- if event .StartChildWorkflowExecutionInitiatedEventAttributes != nil {
1476- sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Input )
1477- sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Control )
1478- sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .Memo .GetFields ())
1479- sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .Header .GetFields ())
1480- sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .SearchAttributes .GetIndexedFields ())
1481- }
1482- case m .EventTypeChildWorkflowExecutionCompleted :
1483- if event .ChildWorkflowExecutionCompletedEventAttributes != nil {
1484- sum += len (event .ChildWorkflowExecutionCompletedEventAttributes .Result )
1485- }
1486- case m .EventTypeChildWorkflowExecutionFailed :
1487- if event .ChildWorkflowExecutionFailedEventAttributes != nil {
1488- sum += len (event .ChildWorkflowExecutionFailedEventAttributes .Details )
1489- sum += getLengthOfStringPointer (event .ChildWorkflowExecutionFailedEventAttributes .Reason )
1490- }
1491- case m .EventTypeChildWorkflowExecutionCanceled :
1492- if event .ChildWorkflowExecutionCanceledEventAttributes != nil {
1493- sum += len (event .ChildWorkflowExecutionCanceledEventAttributes .Details )
1494- }
1495- case m .EventTypeSignalExternalWorkflowExecutionInitiated :
1496- if event .SignalExternalWorkflowExecutionInitiatedEventAttributes != nil {
1497- sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Control )
1498- sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Input )
1499- }
1500-
1501- default :
1502- weh .logger .Warn ("unknown event type" , zap .String ("Event Type" , event .GetEventType ().String ()))
1503- }
1504-
1505- return sum
1506- }
1507-
1508- // simple function to estimate the size of a map[string][]byte
1509- func sizeOf (o map [string ][]byte ) int {
1510- sum := 0
1511- for k , v := range o {
1512- sum += len (k ) + len (v )
1513- }
1514- return sum
1515- }
1516-
1517- func getLengthOfStringPointer (s * string ) int {
1518- if s == nil {
1519- return 0
1520- }
1521- return len (* s )
1522- }
0 commit comments