Skip to content

Commit 70f129b

Browse files
authored
Add CI for examples/instrumentation-quickstart (#290)
1 parent 19657f1 commit 70f129b

7 files changed

Lines changed: 102 additions & 26 deletions

File tree

.github/workflows/pr-build.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,54 @@ on:
66
- main
77
jobs:
88
test:
9-
name: Test
9+
strategy:
10+
matrix:
11+
include:
12+
- build-root: .
13+
name: root
14+
java-version: 11
15+
- build-root: examples/instrumentation-quickstart
16+
java-version: 17
17+
name: Test (${{matrix.name || matrix.build-root}})
1018
runs-on: ubuntu-latest
1119
steps:
1220
- uses: actions/checkout@v2
1321
with:
1422
fetch-depth: 0
15-
- id: setup-java-11
16-
name: Setup Java 11
23+
- id: setup-java
24+
name: Setup Java ${{matrix.java-version}}
1725
uses: actions/setup-java@v1
1826
with:
19-
java-version: 11
27+
java-version: ${{matrix.java-version}}
2028
- uses: burrunan/gradle-cache-action@v1.6
2129
with:
30+
job-id: java-${{matrix.java-version}}
2231
remote-build-cache-proxy-enabled: false
32+
build-root-directory: ${{matrix.build-root}}
2333
arguments: test
2434
style:
25-
name: Stylecheck
35+
name: Stylecheck (${{matrix.name || matrix.build-root}})
2636
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
include:
40+
- build-root: .
41+
name: root
42+
java-version: 11
43+
- build-root: examples/instrumentation-quickstart
44+
java-version: 17
2745
steps:
2846
- uses: actions/checkout@v2
2947
with:
3048
fetch-depth: 0
31-
- id: setup-java-11
32-
name: Setup Java 11
49+
- id: setup-java
50+
name: Setup Java ${{matrix.java-version}}
3351
uses: actions/setup-java@v1
3452
with:
35-
java-version: 11
53+
java-version: ${{matrix.java-version}}
3654
- uses: burrunan/gradle-cache-action@v1.6
3755
with:
56+
job-id: java-${{matrix.java-version}}
3857
remote-build-cache-proxy-enabled: false
58+
build-root-directory: ${{matrix.build-root}}
3959
arguments: spotlessCheck

examples/instrumentation-quickstart/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ bin/
2424
Dockerfile
2525
docker-compose*.yaml
2626
otel-collector-config.yaml
27+
cloudbuild-integration.yaml

examples/instrumentation-quickstart/build.gradle

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ plugins {
1818
id 'java'
1919
id 'org.springframework.boot' version '2.7.18'
2020
id 'io.spring.dependency-management' version '1.1.4'
21+
id 'com.diffplug.spotless' version '6.25.0'
2122
}
2223

2324
group = 'com.example'
@@ -28,6 +29,16 @@ repositories {
2829
mavenCentral()
2930
}
3031

32+
spotless {
33+
java {
34+
googleJavaFormat("1.10.0")
35+
}
36+
groovyGradle {
37+
target '*.gradle' // default target of groovyGradle
38+
greclipse()
39+
}
40+
}
41+
3142
dependencies {
3243
implementation 'org.springframework.boot:spring-boot-starter-webflux'
3344

@@ -44,12 +55,18 @@ dependencies {
4455
tasks.named('test') {
4556
useJUnitPlatform {
4657
// Individual integration tests are annotated with @Tag('integrationTest')
47-
excludeTags 'integrationTest'
48-
}
58+
excludeTags 'integrationTest'
59+
}
4960
}
5061

5162
tasks.register("integrationTest", Test) {
52-
useJUnitPlatform {
63+
useJUnitPlatform {
5364
includeTags 'integrationTest'
54-
}
65+
}
66+
67+
// Passing -DcomposeOverrideFile=foo.yaml will merge docker-compose.yaml with foo.yaml.
68+
// This is used to set overrides for Cloud Build.
69+
if (System.getProperty('composeOverrideFile')) {
70+
systemProperty 'composeOverrideFile', System.getProperty('composeOverrideFile')
71+
}
5572
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- name: eclipse-temurin:17-jdk-alpine
17+
id: integration-test
18+
dir: examples/instrumentation-quickstart
19+
script: ./gradlew integrationTest -i -DcomposeOverrideFile=docker-compose.test.yaml
20+
21+
logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This compose file is only used for integration tests in Cloud Build
16+
17+
version: "3"
18+
19+
networks:
20+
# Make containers use default Cloud Build network for ADC
21+
# https://cloud.google.com/build/docs/build-config-file-schema#network
22+
default:
23+
name: cloudbuild
24+
external: true

examples/instrumentation-quickstart/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol:4317
2222
- OTEL_SERVICE_NAME=otel-quickstart-spring-boot
2323
- OTEL_METRIC_EXPORT_INTERVAL=5000
24-
- GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT?}
24+
- GOOGLE_CLOUD_PROJECT
2525
volumes:
2626
- logs:/var/log:rw
2727
depends_on:
@@ -32,7 +32,7 @@ services:
3232
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro
3333
- logs:/var/log:ro
3434
environment:
35-
- GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT?}
35+
- GOOGLE_CLOUD_PROJECT
3636
loadgen:
3737
image: golang:1.21
3838
command:

examples/instrumentation-quickstart/src/test/java/com/example/demo/DockerComposeTestsIT.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
public class DockerComposeTestsIT {
3838
@Container
3939
public static ComposeContainer environment =
40-
new ComposeContainer(new File("docker-compose.yaml"), new File("docker-compose.creds.yaml"))
40+
new ComposeContainer(
41+
new File("docker-compose.yaml"),
42+
new File(System.getProperty("composeOverrideFile", "docker-compose.creds.yaml")))
4143
.withEnv("USERID", System.getenv("USERID"))
42-
.withEnv("GOOGLE_CLOUD_PROJECT", getenvNotNull("GOOGLE_CLOUD_PROJECT"))
44+
.withEnv("GOOGLE_CLOUD_PROJECT", System.getenv("GOOGLE_CLOUD_PROJECT"))
4345
.withEnv(
44-
"GOOGLE_APPLICATION_CREDENTIALS", getenvNotNull("GOOGLE_APPLICATION_CREDENTIALS"))
46+
"GOOGLE_APPLICATION_CREDENTIALS", System.getenv("GOOGLE_APPLICATION_CREDENTIALS"))
4547
.withExposedService("app", 8080)
4648
.withExposedService("otelcol", 8888)
4749
.waitingFor("app", Wait.forHttp("/multi"))
@@ -82,13 +84,4 @@ public void testApp() throws InterruptedException, IOException, URISyntaxExcepti
8284
assertThat(promText).containsMatch(re);
8385
}
8486
}
85-
86-
private static String getenvNotNull(String key) {
87-
String val = System.getenv(key);
88-
if (val == null) {
89-
throw new IllegalArgumentException(
90-
"Environment variable " + key + " is required but was not set");
91-
}
92-
return val;
93-
}
9487
}

0 commit comments

Comments
 (0)