-
Notifications
You must be signed in to change notification settings - Fork 867
/
SpringBootSmokeTest.groovy
103 lines (82 loc) · 3.3 KB
/
SpringBootSmokeTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.smoketest
import io.opentelemetry.api.trace.TraceId
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest
import spock.lang.IgnoreIf
import spock.lang.Unroll
import java.time.Duration
import java.util.jar.Attributes
import java.util.jar.JarFile
import static io.opentelemetry.smoketest.TestContainerManager.useWindowsContainers
import static java.util.stream.Collectors.toSet
@IgnoreIf({ useWindowsContainers() })
class SpringBootSmokeTest extends SmokeTest {
protected String getTargetImage(String jdk) {
"ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk$jdk-20230321.4484174638"
}
@Override
protected boolean getSetServiceName() {
return false
}
@Override
protected Map<String, String> getExtraEnv() {
return Collections.singletonMap("OTEL_METRICS_EXPORTER", "otlp")
}
@Override
protected TargetWaitStrategy getWaitStrategy() {
return new TargetWaitStrategy.Log(Duration.ofMinutes(1), ".*Started SpringbootApplication in.*")
}
@Unroll
def "spring boot smoke test on JDK #jdk"(int jdk) {
setup:
def output = startTarget(jdk)
def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION).toString()
when:
def response = client().get("/greeting").aggregate().join()
Collection<ExportTraceServiceRequest> traces = waitForTraces()
then: "spans are exported"
response.contentUtf8() == "Hi!"
countSpansByName(traces, 'GET /greeting') == 1
countSpansByName(traces, 'WebController.greeting') == 1
countSpansByName(traces, 'WebController.withSpan') == 1
then: "thread details are recorded"
getSpanStream(traces)
.allMatch { it.attributesList.stream().map { it.key }.collect(toSet()).containsAll(["thread.id", "thread.name"]) }
then: "correct agent version is captured in the resource"
[currentAgentVersion] as Set == findResourceAttribute(traces, "telemetry.auto.version")
.map { it.stringValue }
.collect(toSet())
then: "OS is captured in the resource"
findResourceAttribute(traces, "os.type")
.map { it.stringValue }
.findAny()
.isPresent()
then: "javaagent logs its version on startup"
isVersionLogged(output, currentAgentVersion)
then: "correct traceIds are logged via MDC instrumentation"
def loggedTraceIds = getLoggedTraceIds(output)
def spanTraceIds = getSpanStream(traces)
.map({ TraceId.fromBytes(it.getTraceId().toByteArray()) })
.collect(toSet())
loggedTraceIds == spanTraceIds
then: "JVM metrics are exported"
def metrics = new MetricsInspector(waitForMetrics())
metrics.hasMetricsNamed("process.runtime.jvm.memory.init")
metrics.hasMetricsNamed("process.runtime.jvm.memory.usage")
metrics.hasMetricsNamed("process.runtime.jvm.memory.committed")
metrics.hasMetricsNamed("process.runtime.jvm.memory.limit")
then: "service name is autodetected"
def serviceName = findResourceAttribute(traces, "service.name")
.map { it.stringValue }
.findAny()
serviceName.isPresent()
serviceName.get() == "otel-spring-test-app"
cleanup:
stopTarget()
where:
jdk << [8, 11, 17, 19]
}
}