1
1
package datadog.trace.instrumentation.spark
2
2
3
- import datadog.trace.api.DDSpanId
4
3
import org.apache.spark.SparkConf
5
4
import spock.lang.Specification
6
5
7
6
class OpenlineageParentContextTest extends Specification {
8
- def " should create none empty OpenLineageParentContext using SHA-256 for TraceID and root span SpanId if all required fields are present " () {
7
+ def " should create OpenLineageParentContext with particular trace id based on root parent id " () {
9
8
given :
10
9
SparkConf mockSparkConf = Mock (SparkConf )
11
10
12
11
when :
13
12
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> true
14
13
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> true
15
14
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> true
15
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> true
16
16
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> " default"
17
17
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> " dag-push-to-s3-spark.upload_to_s3"
18
18
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> parentRunId
19
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> rootParentRunId
19
20
20
21
then :
21
22
Optional<OpenlineageParentContext > parentContext = OpenlineageParentContext . from(mockSparkConf)
22
23
parentContext. isPresent()
23
24
24
25
parentContext. get(). getParentJobNamespace() == " default"
25
26
parentContext. get(). getParentJobName() == " dag-push-to-s3-spark.upload_to_s3"
26
- parentContext. get(). getParentRunId() == expectedParentRunId
27
+ parentContext. get(). getRootParentRunId() == rootParentRunId
28
+ parentContext. get(). getParentRunId() == parentRunId
27
29
28
- parentContext. get(). traceId. toLong() == expectedTraceId
29
- parentContext. get(). spanId == DDSpanId . ZERO
30
- parentContext. get(). childRootSpanId == expectedRootSpanId
30
+ parentContext. get(). traceId. toString() == expectedTraceId
31
+ parentContext. get(). spanId. toString() == expectedSpanId
31
32
32
33
where :
33
- parentRunId | expectedParentRunId | expectedTraceId | expectedRootSpanId
34
- " ad3b6baa-8d88-3b38-8dbe-f06232249a84 " | " ad3b6baa-8d88-3b38-8dbe-f06232249a84" | 0xa475569dbce5e6cfL | 0xa475569dbce5e6cfL
35
- " ad3b6baa-8d88-3b38-8dbe-f06232249a85 " | " ad3b6baa-8d88-3b38-8dbe-f06232249a85 " | 0x31da6680bd14991bL | 0x31da6680bd14991bL
34
+ rootParentRunId | parentRunId | expectedTraceId | expectedSpanId
35
+ " 01964820-5280-7674-b04e-82fbed085f39 " | " ad3b6baa-8d88-3b38-8dbe-f06232249a84" | " 13959090542865903119 " | " 2903780135964948649 "
36
+ " 1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e " | " 6f6f6f6f-5e5e-4d4d-3c3c-2b2b2b2b2b2b " | " 15830118871223350489 " | " 8020087091656517257 "
36
37
}
37
38
38
39
def " should create empty OpenLineageParentContext if any required field is missing" () {
@@ -43,20 +44,24 @@ class OpenlineageParentContextTest extends Specification {
43
44
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> jobNamespacePresent
44
45
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> jobNamePresent
45
46
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> runIdPresent
47
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> rootParentIdPresent
46
48
47
49
then :
48
50
Optional<OpenlineageParentContext > parentContext = OpenlineageParentContext . from(mockSparkConf)
49
51
parentContext. isPresent() == expected
50
52
51
53
where :
52
- jobNamespacePresent | jobNamePresent | runIdPresent | expected
53
- true | true | false | false
54
- true | false | true | false
55
- false | true | true | false
56
- true | false | false | false
57
- false | true | false | false
58
- false | false | true | false
59
- false | false | false | false
54
+ jobNamespacePresent | jobNamePresent | runIdPresent | rootParentIdPresent | expected
55
+ true | true | true | false | false
56
+ true | true | false | false | false
57
+ true | true | true | false | false
58
+ true | true | false | true | false
59
+ true | false | true | false | false
60
+ false | true | true | true | false
61
+ true | false | false | false | false
62
+ false | true | false | false | false
63
+ false | false | true | true | false
64
+ false | false | false | false | false
60
65
}
61
66
62
67
def " should only generate a non-empty OpenlineageParentContext if parentRunId is a valid UUID" () {
@@ -67,9 +72,12 @@ class OpenlineageParentContextTest extends Specification {
67
72
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> true
68
73
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> true
69
74
mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> true
75
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> true
70
76
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> " default"
71
77
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> " dag-push-to-s3-spark.upload_to_s3"
72
78
mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> runId
79
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> runId
80
+
73
81
74
82
then :
75
83
Optional<OpenlineageParentContext > parentContext = OpenlineageParentContext . from(mockSparkConf)
@@ -83,5 +91,33 @@ class OpenlineageParentContextTest extends Specification {
83
91
" 6afeb6ee-729d-37f7-b8e6f47ca694" | false
84
92
" 6AFEB6EE-729D-37F7-AD73-B8E6F47CA694" | true
85
93
}
94
+
95
+ def " should only generate a non-empty OpenlineageParentContext if rootParentRunId is a valid UUID" () {
96
+ given :
97
+ SparkConf mockSparkConf = Mock (SparkConf )
98
+
99
+ when :
100
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> true
101
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> true
102
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> true
103
+ mockSparkConf. contains(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> true
104
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAMESPACE ) >> " default"
105
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_JOB_NAME ) >> " dag-push-to-s3-spark.upload_to_s3"
106
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_PARENT_RUN_ID ) >> " 6afeb6ee-729d-37f7-ad73-b8e6f47ca694"
107
+ mockSparkConf. get(OpenlineageParentContext . OPENLINEAGE_ROOT_PARENT_RUN_ID ) >> rootParentRunId
108
+
109
+
110
+ then :
111
+ Optional<OpenlineageParentContext > parentContext = OpenlineageParentContext . from(mockSparkConf)
112
+ parentContext. isPresent() == expected
113
+
114
+ where :
115
+ rootParentRunId | expected
116
+ " 6afeb6ee-729d-37f7-ad73-b8e6f47ca694" | true
117
+ " " | false
118
+ " invalid-uuid" | false
119
+ " 6afeb6ee-729d-37f7-b8e6f47ca694" | false
120
+ " 6AFEB6EE-729D-37F7-AD73-B8E6F47CA694" | true
121
+ }
86
122
}
87
123
0 commit comments