-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
JobErrorReporter: Report connector_command tag for errors encountered during sync #15925
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba616d6
set connector command on failurereason metadata
pedroslopez a4759ee
report connector command from failurereason metadata
pedroslopez 3a723af
update tests
pedroslopez b8e9d13
add more tests around failurehelper
pedroslopez e0949b4
fix PMD
pedroslopez 3981454
add workspace_url tag
pedroslopez d85d1db
Merge branch 'master' into pedroslopez/sentry-cmd-tag
pedroslopez b527a45
fix reporting non-connector-command errors (normalization)
pedroslopez 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 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 |
---|---|---|
|
@@ -36,6 +36,7 @@ public class JobErrorReporter { | |
private static final String FAILURE_ORIGIN_META_KEY = "failure_origin"; | ||
private static final String FAILURE_TYPE_META_KEY = "failure_type"; | ||
private static final String WORKSPACE_ID_META_KEY = "workspace_id"; | ||
private static final String WORKSPACE_URL_META_KEY = "workspace_url"; | ||
private static final String CONNECTION_ID_META_KEY = "connection_id"; | ||
private static final String CONNECTION_URL_META_KEY = "connection_url"; | ||
private static final String CONNECTOR_NAME_META_KEY = "connector_name"; | ||
|
@@ -140,9 +141,7 @@ public void reportSourceCheckJobFailure(final UUID sourceDefinitionId, | |
final StandardSourceDefinition sourceDefinition = configRepository.getStandardSourceDefinition(sourceDefinitionId); | ||
final Map<String, String> metadata = MoreMaps.merge( | ||
getSourceMetadata(sourceDefinition), | ||
Map.of( | ||
JOB_ID_KEY, jobContext.jobId().toString(), | ||
CONNECTOR_COMMAND_META_KEY, "check")); | ||
Map.of(JOB_ID_KEY, jobContext.jobId().toString())); | ||
reportJobFailureReason(workspace, failureReason.withFailureOrigin(FailureOrigin.SOURCE), jobContext.dockerImage(), metadata); | ||
} | ||
|
||
|
@@ -163,9 +162,7 @@ public void reportDestinationCheckJobFailure(final UUID destinationDefinitionId, | |
final StandardDestinationDefinition destinationDefinition = configRepository.getStandardDestinationDefinition(destinationDefinitionId); | ||
final Map<String, String> metadata = MoreMaps.merge( | ||
getDestinationMetadata(destinationDefinition), | ||
Map.of( | ||
JOB_ID_KEY, jobContext.jobId().toString(), | ||
CONNECTOR_COMMAND_META_KEY, "check")); | ||
Map.of(JOB_ID_KEY, jobContext.jobId().toString())); | ||
reportJobFailureReason(workspace, failureReason.withFailureOrigin(FailureOrigin.DESTINATION), jobContext.dockerImage(), metadata); | ||
} | ||
|
||
|
@@ -185,9 +182,7 @@ public void reportDiscoverJobFailure(final UUID sourceDefinitionId, | |
final StandardSourceDefinition sourceDefinition = configRepository.getStandardSourceDefinition(sourceDefinitionId); | ||
final Map<String, String> metadata = MoreMaps.merge( | ||
getSourceMetadata(sourceDefinition), | ||
Map.of( | ||
JOB_ID_KEY, jobContext.jobId().toString(), | ||
CONNECTOR_COMMAND_META_KEY, "discover")); | ||
Map.of(JOB_ID_KEY, jobContext.jobId().toString())); | ||
reportJobFailureReason(workspace, failureReason, jobContext.dockerImage(), metadata); | ||
} | ||
|
||
|
@@ -202,8 +197,7 @@ public void reportSpecJobFailure(final FailureReason failureReason, final Connec | |
final String connectorRepository = dockerImage.split(":")[0]; | ||
final Map<String, String> metadata = Map.of( | ||
JOB_ID_KEY, jobContext.jobId().toString(), | ||
CONNECTOR_REPOSITORY_META_KEY, connectorRepository, | ||
CONNECTOR_COMMAND_META_KEY, "spec"); | ||
CONNECTOR_REPOSITORY_META_KEY, connectorRepository); | ||
reportJobFailureReason(null, failureReason, dockerImage, metadata); | ||
} | ||
|
||
|
@@ -236,13 +230,40 @@ private Map<String, String> getNormalizationMetadata() { | |
} | ||
|
||
private Map<String, String> prefixConnectorMetadataKeys(final Map<String, String> connectorMetadata, final String prefix) { | ||
Map<String, String> prefixedMetadata = new HashMap<>(); | ||
final Map<String, String> prefixedMetadata = new HashMap<>(); | ||
for (final Map.Entry<String, String> entry : connectorMetadata.entrySet()) { | ||
prefixedMetadata.put(String.format("%s_%s", prefix, entry.getKey()), entry.getValue()); | ||
} | ||
return prefixedMetadata; | ||
} | ||
|
||
private Map<String, String> getFailureReasonMetadata(final FailureReason failureReason) { | ||
final Map<String, Object> failureReasonAdditionalProps = failureReason.getMetadata().getAdditionalProperties(); | ||
final Map<String, String> outMetadata = new HashMap<>(); | ||
|
||
if (failureReasonAdditionalProps.containsKey(CONNECTOR_COMMAND_META_KEY) | ||
&& failureReasonAdditionalProps.get(CONNECTOR_COMMAND_META_KEY) != null) { | ||
outMetadata.put(CONNECTOR_COMMAND_META_KEY, failureReasonAdditionalProps.get(CONNECTOR_COMMAND_META_KEY).toString()); | ||
} | ||
|
||
if (failureReason.getFailureOrigin() != null) { | ||
outMetadata.put(FAILURE_ORIGIN_META_KEY, failureReason.getFailureOrigin().value()); | ||
} | ||
|
||
if (failureReason.getFailureType() != null) { | ||
outMetadata.put(FAILURE_TYPE_META_KEY, failureReason.getFailureType().value()); | ||
} | ||
|
||
return outMetadata; | ||
} | ||
|
||
private Map<String, String> getWorkspaceMetadata(final UUID workspaceId) { | ||
final String workspaceUrl = webUrlHelper.getWorkspaceUrl(workspaceId); | ||
return Map.ofEntries( | ||
Map.entry(WORKSPACE_ID_META_KEY, workspaceId.toString()), | ||
Map.entry(WORKSPACE_URL_META_KEY, workspaceUrl)); | ||
Comment on lines
+263
to
+264
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. This wasn't in scope on the original issue, but added this here quickly since we're not getting any urls for synchronous job errors (due to them not being encountered in the context of a connection) |
||
} | ||
|
||
private void reportJobFailureReason(@Nullable final StandardWorkspace workspace, | ||
final FailureReason failureReason, | ||
final String dockerImage, | ||
|
@@ -252,19 +273,16 @@ private void reportJobFailureReason(@Nullable final StandardWorkspace workspace, | |
Map.entry(DEPLOYMENT_MODE_META_KEY, deploymentMode.name()))); | ||
|
||
if (workspace != null) { | ||
commonMetadata.put(WORKSPACE_ID_META_KEY, workspace.getWorkspaceId().toString()); | ||
commonMetadata.putAll(getWorkspaceMetadata(workspace.getWorkspaceId())); | ||
} | ||
|
||
if (failureReason.getFailureOrigin() != null) { | ||
commonMetadata.put(FAILURE_ORIGIN_META_KEY, failureReason.getFailureOrigin().value()); | ||
} | ||
|
||
if (failureReason.getFailureType() != null) { | ||
commonMetadata.put(FAILURE_TYPE_META_KEY, failureReason.getFailureType().value()); | ||
} | ||
final Map<String, String> allMetadata = MoreMaps.merge( | ||
commonMetadata, | ||
getFailureReasonMetadata(failureReason), | ||
metadata); | ||
|
||
try { | ||
jobErrorReportingClient.reportJobFailureReason(workspace, failureReason, dockerImage, MoreMaps.merge(commonMetadata, metadata)); | ||
jobErrorReportingClient.reportJobFailureReason(workspace, failureReason, dockerImage, allMetadata); | ||
} catch (final Exception e) { | ||
LOGGER.error("Error when reporting job failure reason: {}", failureReason, e); | ||
} | ||
|
This file contains 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 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.
Connector command will now be already set on the FailureReason as metadata, so don't need to set it here when reporting the error