From 3b3ed877df9b0a9d7e1996a14333a213f3375140 Mon Sep 17 00:00:00 2001 From: Justin <58960161+just-at-uber@users.noreply.github.com> Date: Tue, 19 Jul 2022 09:56:14 -0700 Subject: [PATCH] fix/failure details (#492) * fix how failures are handled in grpc * fix lint --- .../format-response/format-failure-details.js | 38 +++++++++++++++++++ ...t-activity-task-failed-event-attributes.js | 4 +- ...-activity-task-started-event-attributes.js | 4 +- ...ctivity-task-timed-out-event-attributes.js | 3 +- ...kflow-execution-failed-event-attributes.js | 4 +- ...t-decision-task-failed-event-attributes.js | 4 +- ...ution-continued-as-new-event-attributes.js | 3 +- ...kflow-execution-failed-event-attributes.js | 4 +- ...flow-execution-started-event-attributes.js | 3 +- .../format-response-describe-workflow.js | 3 +- 10 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 server/middleware/grpc-client/format-response/format-failure-details.js diff --git a/server/middleware/grpc-client/format-response/format-failure-details.js b/server/middleware/grpc-client/format-response/format-failure-details.js new file mode 100644 index 000000000..b8a251806 --- /dev/null +++ b/server/middleware/grpc-client/format-response/format-failure-details.js @@ -0,0 +1,38 @@ +// Copyright (c) 2022 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. + +const atob = require('atob'); + +const formatFailureDetails = failure => { + if (!failure?.details) { + return null; + } + + const decodedFailureDetails = atob(failure.details); + + try { + return JSON.parse(decodedFailureDetails); + } catch (e) { + return decodedFailureDetails; + } +}; + +module.exports = formatFailureDetails; diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-failed-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-failed-event-attributes.js index 0151e3540..63e5778f8 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-failed-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-failed-event-attributes.js @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); + const formatActivityTaskFailedEventAttributes = ({ failure, scheduledEventId, @@ -26,7 +28,7 @@ const formatActivityTaskFailedEventAttributes = ({ ...eventAttributes }) => ({ ...eventAttributes, - details: failure?.details || null, + details: formatFailureDetails(failure), reason: failure?.reason || '', scheduledEventId: parseInt(scheduledEventId), startedEventId: parseInt(startedEventId), diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-started-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-started-event-attributes.js index 1c59ca123..a3cc91fb3 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-started-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-started-event-attributes.js @@ -19,13 +19,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); + const formatActivityTaskStartedEventAttributes = ({ lastFailure, scheduledEventId, ...eventAttributes }) => ({ ...eventAttributes, - lastFailureDetails: lastFailure?.details || null, + lastFailureDetails: formatFailureDetails(lastFailure), lastFailureReason: lastFailure?.reason || '', scheduledEventId: parseInt(scheduledEventId), }); diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-timed-out-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-timed-out-event-attributes.js index 288b1405f..f92349038 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-timed-out-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-activity-task-timed-out-event-attributes.js @@ -19,6 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); const formatPayload = require('../format-payload'); const formatActivityTaskTimedOutEventAttributes = ({ @@ -30,7 +31,7 @@ const formatActivityTaskTimedOutEventAttributes = ({ }) => ({ ...eventAttributes, details: formatPayload(details), - lastFailureDetails: lastFailure?.details || null, + lastFailureDetails: formatFailureDetails(lastFailure), lastFailureReason: lastFailure?.reason || '', scheduledEventId: parseInt(scheduledEventId), startedEventId: parseInt(startedEventId), diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-child-workflow-execution-failed-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-child-workflow-execution-failed-event-attributes.js index 53c6c633b..437f7568e 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-child-workflow-execution-failed-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-child-workflow-execution-failed-event-attributes.js @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); + const formatChildWorkflowExecutionFailedEventAttributes = ({ failure, initiatedEventId, @@ -26,7 +28,7 @@ const formatChildWorkflowExecutionFailedEventAttributes = ({ ...eventAttributes }) => ({ ...eventAttributes, - details: failure?.details || null, + details: formatFailureDetails(failure), initiatedEventId: parseInt(initiatedEventId), reason: failure?.reason || '', startedEventId: parseInt(startedEventId), diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-decision-task-failed-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-decision-task-failed-event-attributes.js index 49500e301..c3297612e 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-decision-task-failed-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-decision-task-failed-event-attributes.js @@ -19,6 +19,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); + const formatDecisionTaskFailedEventAttributes = ({ failure, forkEventVersion, @@ -27,7 +29,7 @@ const formatDecisionTaskFailedEventAttributes = ({ ...eventAttributes }) => ({ ...eventAttributes, - details: failure?.details || null, + details: formatFailureDetails(failure), forkEventVersion: parseInt(forkEventVersion), reason: failure?.reason || '', scheduledEventId: parseInt(scheduledEventId), diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-continued-as-new-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-continued-as-new-event-attributes.js index 5a7bc18b1..cde98d2a4 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-continued-as-new-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-continued-as-new-event-attributes.js @@ -20,6 +20,7 @@ // THE SOFTWARE. const formatEnum = require('../format-enum'); +const formatFailureDetails = require('../format-failure-details'); const formatPayload = require('../format-payload'); const formatPayloadMap = require('../format-payload-map'); const formatDurationToSeconds = require('../format-duration-to-seconds'); @@ -44,7 +45,7 @@ const formatWorkflowExecutionContinuedAsNewEventAttributes = ({ executionStartToCloseTimeoutSeconds: formatDurationToSeconds( executionStartToCloseTimeout ), - failureDetails: failure?.details || null, + failureDetails: formatFailureDetails(failure), failureReason: failure?.reason || '', header: formatPayloadMap(header, 'fields'), initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'), diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-failed-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-failed-event-attributes.js index e7f24382e..008b84634 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-failed-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-failed-event-attributes.js @@ -19,12 +19,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const formatFailureDetails = require('../format-failure-details'); + const formatWorkflowExecutionFailedEventAttributes = ({ failure, decisionTaskCompletedEventId, }) => ({ decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId), - details: failure?.details || null, + details: formatFailureDetails(failure), reason: failure?.reason || '', }); diff --git a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-started-event-attributes.js b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-started-event-attributes.js index 1e93e79d8..a9cac8ad4 100644 --- a/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-started-event-attributes.js +++ b/server/middleware/grpc-client/format-response/format-history-event-details/format-workflow-execution-started-event-attributes.js @@ -20,6 +20,7 @@ // THE SOFTWARE. const formatEnum = require('../format-enum'); +const formatFailureDetails = require('../format-failure-details'); const formatPayload = require('../format-payload'); const formatPayloadMap = require('../format-payload-map'); const formatTimestampToDatetime = require('../format-timestamp-to-datetime'); @@ -63,7 +64,7 @@ const formatWorkflowExecutionStartedEventAttributes = ({ ), attempt: attempt || null, continuedExecutionRunId: continuedExecutionRunId || null, - continuedFailureDetails: continuedFailure?.details || null, + continuedFailureDetails: formatFailureDetails(continuedFailure), continuedFailureReason: continuedFailure?.reason || null, cronSchedule: cronSchedule || null, expirationTimestamp: formatTimestampToDatetime(expirationTime), diff --git a/server/middleware/grpc-client/format-response/format-response-describe-workflow.js b/server/middleware/grpc-client/format-response/format-response-describe-workflow.js index 24e311967..7b6f9dbd0 100644 --- a/server/middleware/grpc-client/format-response/format-response-describe-workflow.js +++ b/server/middleware/grpc-client/format-response/format-response-describe-workflow.js @@ -20,6 +20,7 @@ // THE SOFTWARE. const formatEnum = require('./format-enum'); +const formatFailureDetails = require('./format-failure-details'); const formatTimestampToDatetime = require('./format-timestamp-to-datetime'); const formatDurationToSeconds = require('./format-duration-to-seconds'); @@ -65,7 +66,7 @@ const formatResponseDescribeWorkflow = ({ ...pendingActivity, activityID: parseInt(activityId), expirationTimestamp: formatTimestampToDatetime(expirationTime), - lastFailureDetails: lastFailure?.details || null, + lastFailureDetails: formatFailureDetails(lastFailure), lastFailureReason: lastFailure?.reason || null, lastHeartbeatTimestamp: formatTimestampToDatetime(lastHeartbeatTime), lastStartedTimestamp: formatTimestampToDatetime(lastStartedTime),