Skip to content

Commit

Permalink
Add CI for examples/instrumentation-quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Feb 8, 2024
1 parent 57545d8 commit 2f86001
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/instrumentation-quickstart/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ bin/
Dockerfile
docker-compose*.yaml
otel-collector-config.yaml
cloudbuild-integration.yaml
6 changes: 6 additions & 0 deletions examples/instrumentation-quickstart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ tasks.register("integrationTest", Test) {
useJUnitPlatform {
includeTags 'integrationTest'
}

// Passing -DcomposeOverrideFile=foo.yaml will merge docker-compose.yaml with foo.yaml.
// This is used to set overrides for Cloud Build.
if (System.getProperty('composeOverrideFile')) {
systemProperty 'composeOverrideFile', System.getProperty('composeOverrideFile')
}
}
21 changes: 21 additions & 0 deletions examples/instrumentation-quickstart/cloudbuild-integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- name: eclipse-temurin:17-jdk-alpine
id: integration-test
dir: examples/instrumentation-quickstart
script: ./gradlew integrationTest -i -DcomposeOverrideFile=docker-compose.test.yaml

logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs
24 changes: 24 additions & 0 deletions examples/instrumentation-quickstart/docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This compose file is only used for integration tests in Cloud Build

version: "3"

networks:
# Make containers use default Cloud Build network for ADC
# https://cloud.google.com/build/docs/build-config-file-schema#network
default:
name: cloudbuild
external: true
4 changes: 2 additions & 2 deletions examples/instrumentation-quickstart/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol:4317
- OTEL_SERVICE_NAME=otel-quickstart-spring-boot
- OTEL_METRIC_EXPORT_INTERVAL=5000
- GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT?}
- GOOGLE_CLOUD_PROJECT
volumes:
- logs:/var/log:rw
depends_on:
Expand All @@ -32,7 +32,7 @@ services:
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro
- logs:/var/log:ro
environment:
- GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT?}
- GOOGLE_CLOUD_PROJECT
loadgen:
image: golang:1.21
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
public class DockerComposeTestsIT {
@Container
public static ComposeContainer environment =
new ComposeContainer(new File("docker-compose.yaml"), new File("docker-compose.creds.yaml"))
new ComposeContainer(
new File("docker-compose.yaml"),
new File(System.getProperty("composeOverrideFile", "docker-compose.creds.yaml")))
.withEnv("USERID", System.getenv("USERID"))
.withEnv("GOOGLE_CLOUD_PROJECT", getenvNotNull("GOOGLE_CLOUD_PROJECT"))
.withEnv("GOOGLE_CLOUD_PROJECT", System.getenv("GOOGLE_CLOUD_PROJECT"))
.withEnv(
"GOOGLE_APPLICATION_CREDENTIALS", getenvNotNull("GOOGLE_APPLICATION_CREDENTIALS"))
"GOOGLE_APPLICATION_CREDENTIALS", System.getenv("GOOGLE_APPLICATION_CREDENTIALS"))
.withExposedService("app", 8080)
.withExposedService("otelcol", 8888)
.waitingFor("app", Wait.forHttp("/multi"))
Expand Down Expand Up @@ -82,13 +84,4 @@ public void testApp() throws InterruptedException, IOException, URISyntaxExcepti
assertThat(promText).containsMatch(re);
}
}

private static String getenvNotNull(String key) {
String val = System.getenv(key);
if (val == null) {
throw new IllegalArgumentException(
"Environment variable " + key + " is required but was not set");
}
return val;
}
}

0 comments on commit 2f86001

Please sign in to comment.