-
Notifications
You must be signed in to change notification settings - Fork 346
Mix Databricks repair attempt into Spark parent trace id #12022
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
Open
aboitreaud
wants to merge
7
commits into
master
Choose a base branch
from
adrien.boitreaud/databricks-repair-run-spark-trace-correlation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
103f0b8
Mix Databricks repair attempt into Spark parent trace id
aboitreaud 2383404
Test databricks repair attempt extraction from unity.scope.data
aboitreaud 51d60eb
Harden repair attempt extraction and move its test out of the Spock f…
aboitreaud d581603
spotless apply
aboitreaud d74fb41
Fix CI: add spark-core test dependency and drop Java 9+ readAllBytes
aboitreaud 56ca820
Merge branch 'master' into adrien.boitreaud/databricks-repair-run-spa…
aboitreaud 1d6a64f
Rename indexOf helper to indexOfDatabricksAttemptKey
aboitreaud 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
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
128 changes: 128 additions & 0 deletions
128
...common/src/test/java/datadog/trace/instrumentation/spark/DatabricksRepairAttemptTest.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,128 @@ | ||
| package datadog.trace.instrumentation.spark; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
|
||
| import datadog.trace.api.DDSpanId; | ||
| import datadog.trace.api.DDTraceId; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.UncheckedIOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Properties; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class DatabricksRepairAttemptTest { | ||
|
|
||
| private static String loadResource(String path) { | ||
| try (InputStream stream = DatabricksRepairAttemptTest.class.getResourceAsStream(path)) { | ||
| if (stream == null) { | ||
| throw new IllegalStateException("missing test resource " + path); | ||
| } | ||
| ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
| byte[] chunk = new byte[4096]; | ||
| int read; | ||
| while ((read = stream.read(chunk)) != -1) { | ||
| bytes.write(chunk, 0, read); | ||
| } | ||
| return new String(bytes.toByteArray(), StandardCharsets.UTF_8).trim(); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void extractsAttemptZeroFromOriginalRunPayload() { | ||
| Properties properties = new Properties(); | ||
| properties.setProperty( | ||
| "unity.scope.data", loadResource("/databricks/unity-scope-data-original.txt")); | ||
|
|
||
| assertEquals(0, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void extractsAttemptOneFromRepairedRunPayload() { | ||
| Properties properties = new Properties(); | ||
| properties.setProperty( | ||
| "unity.scope.data", loadResource("/databricks/unity-scope-data-repaired.txt")); | ||
|
|
||
| assertEquals(1, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void fallsBackToZeroWhenPropertyIsMissing() { | ||
| Properties properties = new Properties(); | ||
|
|
||
| assertEquals(0, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void fallsBackToZeroWhenPayloadIsNotValidBase64() { | ||
| Properties properties = new Properties(); | ||
| properties.setProperty("unity.scope.data", "not-valid-base64-@@@"); | ||
|
|
||
| assertEquals(0, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void fallsBackToZeroWhenKeyIsAbsent() { | ||
| // Base64 of a serialized map that never mentions jobRunAttemptNum at all. | ||
| Properties properties = new Properties(); | ||
| properties.setProperty( | ||
| "unity.scope.data", | ||
| java.util.Base64.getEncoder() | ||
| .encodeToString("no attempt info in here".getBytes(StandardCharsets.UTF_8))); | ||
|
|
||
| assertEquals(0, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void fallsBackToZeroWhenValueIsABackreferenceRatherThanAString() { | ||
| // If the attempt value string was already written earlier in the serialized stream, Java | ||
| // serialization emits a TC_REFERENCE (0x71) back-pointer instead of repeating the string. We | ||
| // don't resolve backreferences, so this must safely fall back to attempt 0 rather than risk | ||
| // scanning forward and matching an unrelated byte as the value. | ||
| byte[] key = "jobRunAttemptNum".getBytes(StandardCharsets.UTF_8); | ||
| byte[] payload = new byte[key.length + 5]; | ||
| System.arraycopy(key, 0, payload, 0, key.length); | ||
| payload[key.length] = 0x71; // TC_REFERENCE | ||
| payload[key.length + 1] = 0x00; | ||
| payload[key.length + 2] = 0x00; | ||
| payload[key.length + 3] = 0x00; | ||
| payload[key.length + 4] = 0x01; | ||
|
|
||
| Properties properties = new Properties(); | ||
| properties.setProperty( | ||
| "unity.scope.data", java.util.Base64.getEncoder().encodeToString(payload)); | ||
|
|
||
| assertEquals(0, AbstractDatadogSparkListener.getDatabricksJobRunAttempt(properties)); | ||
| } | ||
|
|
||
| @Test | ||
| void computesDistinctTraceIdsForOriginalAndRepairedAttemptOfTheSameRun() { | ||
| // A repaired run reuses the same jobId/parentRunId as the original (that's the whole reason | ||
| // spans collided before this fix); it gets a fresh taskRunId per attempt, but that alone isn't | ||
| // enough since the job span (the trace root) is keyed on jobId+parentRunId, not taskRunId. | ||
| String jobId = "1234"; | ||
| String parentRunId = "5678"; | ||
|
|
||
| DatabricksParentContext original = new DatabricksParentContext(jobId, parentRunId, "9012", 0); | ||
| DatabricksParentContext repaired = new DatabricksParentContext(jobId, parentRunId, "3456", 1); | ||
|
|
||
| assertEquals(DDTraceId.from("8944764253919609482"), original.getTraceId()); | ||
| assertNotEquals(original.getTraceId(), repaired.getTraceId()); | ||
| assertNotEquals(DDSpanId.ZERO, repaired.getSpanId()); | ||
| } | ||
|
|
||
| @Test | ||
| void attemptZeroReproducesTheOriginalNonRepairAwareTraceId() { | ||
| // Backward compatibility: runs that were never repaired must keep the exact trace id they | ||
| // always had, since attempt 0 is the overwhelmingly common case. | ||
| DatabricksParentContext withDefaultAttempt = | ||
| new DatabricksParentContext("1234", "5678", "9012", 0); | ||
|
|
||
| assertEquals(DDTraceId.from("8944764253919609482"), withDefaultAttempt.getTraceId()); | ||
| assertEquals(DDSpanId.from("15104224823446433673"), withDefaultAttempt.getSpanId()); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...umentation/spark/spark-common/src/test/resources/databricks/unity-scope-data-original.txt
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 @@ | ||
| rO0ABXNyABdqYXZhLnV0aWwuTGlua2VkSGFzaE1hcDTATlwQbMD7AgABWgALYWNjZXNzT3JkZXJ4cgARamF2YS51dGlsLkhhc2hNYXAFB9rBwxZg0QMAAkYACmxvYWRGYWN0b3JJAAl0aHJlc2hvbGR4cD9AAAAAAAAMdwgAAAAQAAAABXQACHByaW9yS2V5dAACNDJ0AA1qb2JSdW5BdHRlbXB0dAABOXQAEGpvYlJ1bkF0dGVtcHROdW10AAEwdAAVam9iUnVuT3JpZ2luYWxBdHRlbXB0dAABM3QAC3RyYWlsaW5nS2V5dAAFc2V2ZW54AA== |
1 change: 1 addition & 0 deletions
1
...umentation/spark/spark-common/src/test/resources/databricks/unity-scope-data-repaired.txt
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 @@ | ||
| rO0ABXNyABdqYXZhLnV0aWwuTGlua2VkSGFzaE1hcDTATlwQbMD7AgABWgALYWNjZXNzT3JkZXJ4cgARamF2YS51dGlsLkhhc2hNYXAFB9rBwxZg0QMAAkYACmxvYWRGYWN0b3JJAAl0aHJlc2hvbGR4cD9AAAAAAAAMdwgAAAAQAAAABXQACHByaW9yS2V5dAACNDJ0AA1qb2JSdW5BdHRlbXB0dAABOXQAEGpvYlJ1bkF0dGVtcHROdW10AAExdAAVam9iUnVuT3JpZ2luYWxBdHRlbXB0dAABM3QAC3RyYWlsaW5nS2V5dAAFc2V2ZW54AA== |
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
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.
The root
/workspace/dd-trace-java/AGENTS.mdTest frameworks guideline says to use JUnit 5 and migrate an existing Groovy test when it is touched. This change adds repaired-run coverage to the existing Spock fixture instead, so the new coverage remains in the deprecated test framework rather than following the repository instruction.Useful? React with 👍 / 👎.