-
Notifications
You must be signed in to change notification settings - Fork 218
Add application err category #2485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4fd8dd9
update protos
THardy98 71c11a4
add ApplicationErrorCategory enum
THardy98 1858f95
Add category field to ApplicationFailure
THardy98 4e8a98e
add category proto converter logic
THardy98 433c066
add logging/metrics checks for benign application failures
THardy98 6875557
fixes, added test for workflow failure metric
THardy98 29ff5dc
fixes for activity failures, added test for activity failures
THardy98 44de349
address PR review
THardy98 a64f646
only check immediate failure
THardy98 d22a2ad
define code enum, convert to/from proto representation
THardy98 823848e
cleanup
THardy98 ab0a99a
Merge branch 'master' into add_application_err_category
THardy98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||
| package io.temporal.failure; | ||||||
|
|
||||||
| import com.google.common.base.Strings; | ||||||
| import io.temporal.api.enums.v1.ApplicationErrorCategory; | ||||||
| import io.temporal.common.converter.DataConverter; | ||||||
| import io.temporal.common.converter.EncodedValues; | ||||||
| import io.temporal.common.converter.Values; | ||||||
|
|
@@ -51,13 +52,15 @@ | |||||
| * <li>nonRetryable is set to false | ||||||
| * <li>details are set to null | ||||||
| * <li>stack trace is copied from the original exception | ||||||
| * <li>stack category is set to ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_UNSPECIFIED | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * </ul> | ||||||
| */ | ||||||
| public final class ApplicationFailure extends TemporalFailure { | ||||||
| private final String type; | ||||||
| private final Values details; | ||||||
| private boolean nonRetryable; | ||||||
| private Duration nextRetryDelay; | ||||||
| private final ApplicationErrorCategory category; | ||||||
|
|
||||||
| /** | ||||||
| * New ApplicationFailure with {@link #isNonRetryable()} flag set to false. | ||||||
|
|
@@ -92,7 +95,14 @@ public static ApplicationFailure newFailure(String message, String type, Object. | |||||
| */ | ||||||
| public static ApplicationFailure newFailureWithCause( | ||||||
| String message, String type, @Nullable Throwable cause, Object... details) { | ||||||
| return new ApplicationFailure(message, type, false, new EncodedValues(details), cause, null); | ||||||
| return new ApplicationFailure( | ||||||
| message, | ||||||
| type, | ||||||
| false, | ||||||
| new EncodedValues(details), | ||||||
| cause, | ||||||
| null, | ||||||
| ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_UNSPECIFIED); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -118,7 +128,13 @@ public static ApplicationFailure newFailureWithCauseAndDelay( | |||||
| Duration nextRetryDelay, | ||||||
| Object... details) { | ||||||
| return new ApplicationFailure( | ||||||
| message, type, false, new EncodedValues(details), cause, nextRetryDelay); | ||||||
| message, | ||||||
| type, | ||||||
| false, | ||||||
| new EncodedValues(details), | ||||||
| cause, | ||||||
| nextRetryDelay, | ||||||
| ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_UNSPECIFIED); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -153,7 +169,40 @@ public static ApplicationFailure newNonRetryableFailure( | |||||
| */ | ||||||
| public static ApplicationFailure newNonRetryableFailureWithCause( | ||||||
| String message, String type, @Nullable Throwable cause, Object... details) { | ||||||
| return new ApplicationFailure(message, type, true, new EncodedValues(details), cause, null); | ||||||
| return new ApplicationFailure( | ||||||
| message, | ||||||
| type, | ||||||
| true, | ||||||
| new EncodedValues(details), | ||||||
| cause, | ||||||
| null, | ||||||
| ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_UNSPECIFIED); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * New ApplicationFailure with a specified category and {@link #isNonRetryable()} flag set to | ||||||
| * false. | ||||||
| * | ||||||
| * <p>Note that this exception still may not be retried by the service if its type is included in | ||||||
| * the doNotRetry property of the correspondent retry policy. | ||||||
| * | ||||||
| * @param message optional error message | ||||||
| * @param type error type | ||||||
| * @param category the category of the application failure. | ||||||
| * @param cause failure cause. Each element of the cause chain will be converted to | ||||||
| * ApplicationFailure for network transmission across network if it doesn't extend {@link | ||||||
| * TemporalFailure} | ||||||
| * @param details optional details about the failure. They are serialized using the same approach | ||||||
| * as arguments and results. | ||||||
| */ | ||||||
| public static ApplicationFailure newFailureWithCategory( | ||||||
| String message, | ||||||
| String type, | ||||||
| ApplicationErrorCategory category, | ||||||
| @Nullable Throwable cause, | ||||||
| Object... details) { | ||||||
| return new ApplicationFailure( | ||||||
| message, type, false, new EncodedValues(details), cause, null, category); | ||||||
| } | ||||||
|
|
||||||
| static ApplicationFailure newFromValues( | ||||||
|
|
@@ -162,8 +211,10 @@ static ApplicationFailure newFromValues( | |||||
| boolean nonRetryable, | ||||||
| Values details, | ||||||
| Throwable cause, | ||||||
| Duration nextRetryDelay) { | ||||||
| return new ApplicationFailure(message, type, nonRetryable, details, cause, nextRetryDelay); | ||||||
| Duration nextRetryDelay, | ||||||
| ApplicationErrorCategory category) { | ||||||
| return new ApplicationFailure( | ||||||
| message, type, nonRetryable, details, cause, nextRetryDelay, category); | ||||||
| } | ||||||
|
|
||||||
| ApplicationFailure( | ||||||
|
|
@@ -172,12 +223,14 @@ static ApplicationFailure newFromValues( | |||||
| boolean nonRetryable, | ||||||
| Values details, | ||||||
| Throwable cause, | ||||||
| Duration nextRetryDelay) { | ||||||
| Duration nextRetryDelay, | ||||||
| ApplicationErrorCategory category) { | ||||||
| super(getMessage(message, Objects.requireNonNull(type), nonRetryable), message, cause); | ||||||
| this.type = type; | ||||||
| this.details = details; | ||||||
| this.nonRetryable = nonRetryable; | ||||||
| this.nextRetryDelay = nextRetryDelay; | ||||||
| this.category = category; | ||||||
| } | ||||||
|
|
||||||
| public String getType() { | ||||||
|
|
@@ -210,6 +263,10 @@ public void setNextRetryDelay(Duration nextRetryDelay) { | |||||
| this.nextRetryDelay = nextRetryDelay; | ||||||
| } | ||||||
|
|
||||||
| public ApplicationErrorCategory getApplicationErrorCategory() { | ||||||
| return category; | ||||||
| } | ||||||
|
|
||||||
| private static String getMessage(String message, String type, boolean nonRetryable) { | ||||||
| return (Strings.isNullOrEmpty(message) ? "" : "message='" + message + "', ") | ||||||
| + "type='" | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
temporal-sdk/src/main/java/io/temporal/internal/common/FailureUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
| * | ||
| * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this material except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.temporal.internal.common; | ||
|
|
||
| import io.temporal.api.enums.v1.ApplicationErrorCategory; | ||
| import io.temporal.api.failure.v1.Failure; | ||
| import io.temporal.failure.ApplicationFailure; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class FailureUtils { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedantic, but would add a private constructor here |
||
| public static boolean isBenignApplicationFailure(@Nullable Throwable t) { | ||
| if (t instanceof ApplicationFailure | ||
| && ((ApplicationFailure) t).getApplicationErrorCategory() | ||
| == ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_BENIGN) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public static boolean isBenignApplicationFailure(@Nullable Failure failure) { | ||
| if (failure != null | ||
| && failure.getApplicationFailureInfo() != null | ||
| && failure.getApplicationFailureInfo().getCategory() | ||
| == ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_BENIGN) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use the proto enum in the user facing API, we should declare our own enum in the Java SDK and convert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I didn't notice before you were still using the proto enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I formerly had this but: #2485 (comment)
It looked like we use raw protos, when do we use each pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All new features should NOT use raw proto, only old features use raw protos