diff --git a/examples/instrumentation-quickstart/.dockerignore b/examples/instrumentation-quickstart/.dockerignore index 9ff65eee..6dc30f26 100644 --- a/examples/instrumentation-quickstart/.dockerignore +++ b/examples/instrumentation-quickstart/.dockerignore @@ -24,3 +24,4 @@ bin/ Dockerfile docker-compose*.yaml otel-collector-config.yaml +cloudbuild-integration.yaml diff --git a/examples/instrumentation-quickstart/build.gradle b/examples/instrumentation-quickstart/build.gradle index 1b76320b..a9b894c9 100644 --- a/examples/instrumentation-quickstart/build.gradle +++ b/examples/instrumentation-quickstart/build.gradle @@ -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') + } } diff --git a/examples/instrumentation-quickstart/cloudbuild-integration.yaml b/examples/instrumentation-quickstart/cloudbuild-integration.yaml new file mode 100644 index 00000000..967fb6f4 --- /dev/null +++ b/examples/instrumentation-quickstart/cloudbuild-integration.yaml @@ -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 diff --git a/examples/instrumentation-quickstart/docker-compose.test.yaml b/examples/instrumentation-quickstart/docker-compose.test.yaml new file mode 100644 index 00000000..7e87cdf6 --- /dev/null +++ b/examples/instrumentation-quickstart/docker-compose.test.yaml @@ -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 diff --git a/examples/instrumentation-quickstart/docker-compose.yaml b/examples/instrumentation-quickstart/docker-compose.yaml index f5382e01..8aa73d92 100644 --- a/examples/instrumentation-quickstart/docker-compose.yaml +++ b/examples/instrumentation-quickstart/docker-compose.yaml @@ -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: @@ -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: diff --git a/examples/instrumentation-quickstart/src/test/java/com/example/demo/DockerComposeTestsIT.java b/examples/instrumentation-quickstart/src/test/java/com/example/demo/DockerComposeTestsIT.java index 90de4391..b3a57c90 100644 --- a/examples/instrumentation-quickstart/src/test/java/com/example/demo/DockerComposeTestsIT.java +++ b/examples/instrumentation-quickstart/src/test/java/com/example/demo/DockerComposeTestsIT.java @@ -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")) @@ -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; - } }