From 991e696ed27f633eabdff2331e68621124fcac0b Mon Sep 17 00:00:00 2001 From: balopat Date: Wed, 16 Aug 2017 17:14:05 -0400 Subject: [PATCH 1/9] adding custom logging test + local runtimes-common integration test --- scripts/integration_test.yaml | 1 - scripts/local_integration_test.sh | 124 +++++++++++++----- test-application/pom.xml | 11 ++ .../cloud/runtimes/LoggingTestController.java | 84 ++++++++++++ .../runtimes/MonitoringTestController.java | 8 +- .../runtimes/config/GCPConfiguration.java | 35 +++++ .../runtimes/config/MockGCPConfiguration.java | 53 ++++++++ .../StackDriverMonitoringService.java | 5 +- .../src/main/resources/application.properties | 3 +- 9 files changed, 289 insertions(+), 35 deletions(-) create mode 100644 test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java create mode 100644 test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java create mode 100644 test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java diff --git a/scripts/integration_test.yaml b/scripts/integration_test.yaml index 511034fc..0968b816 100755 --- a/scripts/integration_test.yaml +++ b/scripts/integration_test.yaml @@ -9,7 +9,6 @@ steps: - name: 'gcr.io/java-runtime-test/integration-test' args: - '--url=${_DEPLOYED_APP_URL}' - - '--skip-custom-logging-tests' # blocked by b/33415496 - '--skip-standard-logging-tests' # blocked by b/33415496 - '--skip-custom-tests' diff --git a/scripts/local_integration_test.sh b/scripts/local_integration_test.sh index b11440b4..c953b0fb 100755 --- a/scripts/local_integration_test.sh +++ b/scripts/local_integration_test.sh @@ -14,26 +14,72 @@ # See the License for the specific language governing permissions and # limitations under the License. - # exit on command failure set -e +function usage() { + echo $1 + echo "Usage: ${0} [OPTIONS]" + echo "Options:" + echo "-v: verbose (displays logs for container and test driver)" + echo "-g: test integration with GCP services (requires GOOGLE_APPLICATION_CREDENTIALS)" + exit 1 +} + +function getPort() { + docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' ${CONTAINER} +} + + +function waitForOutput() { + found_output='false' + for run in {1..10} + do + grep "$1" ${OUTPUT_FILE} && found_output='true' && break + sleep 1 + done + + if [ "$found_output" == "false" ]; then + cat ${OUTPUT_FILE} + echo "did not match '$1' in '$OUTPUT_FILE'" + exit 1 + fi +} + + readonly dir=$(dirname $0) readonly projectRoot="$dir/.." readonly testAppDir="$projectRoot/test-application" readonly deployDir="$testAppDir/target/deploy" APP_IMAGE='openjdk-local-integration' +TEST_DRIVER_IMAGE='gcr.io/java-runtime-test/integration-test' CONTAINER=${APP_IMAGE}-container OUTPUT_FILE=${CONTAINER}-output.txt DEPLOYMENT_TOKEN=$(uuidgen) readonly imageUnderTest=$1 if [[ -z "$imageUnderTest" ]]; then - echo "Usage: ${0} " - exit 1 + usage "Error: missing image!" fi +shift + +while getopts ":gv" opt; do + case $opt in + v) + VERBOSE="true" + DRIVER_OPTS="--verbose" + ;; + g) + WITH_GCP="true" + ;; + \?) + usage "Invalid option: -$OPTARG" + ;; + esac +done + # build the test app pushd ${testAppDir} mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode @@ -44,48 +90,66 @@ pushd $deployDir export STAGING_IMAGE=$imageUnderTest envsubst < Dockerfile.in > Dockerfile echo "Building app container..." -docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . +docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . || usage "Error building test-app image from base image \"${imageUnderTest}\", please make sure it exists!" + + +if [[ "$WITH_GCP" ]]; then + echo "--------" + echo "Starting test in GCP mode!" + echo "--------" + + if [[ -z ${GOOGLE_APPLICATION_CREDENTIALS} ]]; then + usage "Error: In GCP mode GOOGLE_APPLICATION_CREDENTIALS must be set." + fi + # we setup the container for GCP relying on the environment + GCP_CONTAINER_OPTS="-v ${GOOGLE_APPLICATION_CREDENTIALS}:/gcp_creds.json -e GOOGLE_APPLICATION_CREDENTIALS=/gcp_creds.json" + APP_CMD= + DRIVER_OPTS="$DRIVER_OPTS --skip-standard-logging-tests \ + --skip-custom-tests" +else + echo "--------" + echo "Starting test in MOCK-GCP mode!" + echo "--------" + # mock-gcp profile, the container is started as mock-gcp + GCP_CONTAINER_OPTS= + APP_CMD='java -Dspring.profiles.active=mock-gcp -jar app.jar' + DRIVER_OPTS="$DRIVER_OPTS --skip-monitoring-tests \ + --skip-custom-logging-tests \ + --skip-standard-logging-tests \ + --skip-custom-tests" +fi + +docker rm -f $CONTAINER &>/dev/null || echo "Integration-test-app container is not running, ready to start a new instance." -docker rm -f $CONTAINER || echo "Integration-test-app container is not running, ready to start a new instance." # run app container locally to test shutdown logging echo "Starting app container..." -docker run --rm --name $CONTAINER -p 8080 -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" -e "SHUTDOWN_LOGGING_HEAP_INFO=true" $APP_IMAGE &> $OUTPUT_FILE & - -function waitForOutput() { - found_output='false' - for run in {1..10} - do - grep "$1" $OUTPUT_FILE && found_output='true' && break - sleep 1 - done - - if [ "$found_output" == "false" ]; then - cat $OUTPUT_FILE - echo "did not match '$1' in '$OUTPUT_FILE'" - exit 1 - fi -} +docker run --rm --name ${CONTAINER} ${GCP_CONTAINER_OPTS} -p 8080 \ + -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" \ + -e "SHUTDOWN_LOGGING_HEAP_INFO=true" \ + ${APP_IMAGE} ${APP_CMD} &> ${OUTPUT_FILE} & waitForOutput 'Started Application' -getPort() { - docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' ${CONTAINER} -} - - PORT=`getPort` -echo port is $PORT +DEPLOYED_APP_URL=http://localhost:${PORT} + +echo "App deployed to URL: $DEPLOYED_APP_URL, making sure it accepts connections..." -until [[ $(curl --silent --fail "http://localhost:$PORT/deployment.token" | grep "$DEPLOYMENT_TOKEN") ]]; do +until [[ $(curl --silent --fail "${DEPLOYED_APP_URL}/deployment.token" | grep "${DEPLOYMENT_TOKEN}") ]]; do sleep 2 done +DRIVER_OPTS="${DRIVER_OPTS} --url=${DEPLOYED_APP_URL}" + +[[ "${VERBOSE}" ]] && docker logs -f ${CONTAINER} & + +docker run --rm ${GCP_CONTAINER_OPTS} --net=host ${TEST_DRIVER_IMAGE} ${DRIVER_OPTS} -docker stop $CONTAINER +docker stop ${CONTAINER} -docker rmi $APP_IMAGE +docker rmi -f ${APP_IMAGE} echo 'verify thread dump' waitForOutput 'Full thread dump OpenJDK 64-Bit Server VM' diff --git a/test-application/pom.xml b/test-application/pom.xml index a4b4e11c..804f6fef 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -25,6 +25,7 @@ ${java.version} ${java.version} default_deployment_token + gcp @@ -42,6 +43,16 @@ google-auth-library-credentials 0.7.0 + + com.google.cloud + google-cloud-logging + 1.2.1 + + + org.mockito + mockito-core + 2.8.47 + diff --git a/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java new file mode 100644 index 00000000..be1f23bf --- /dev/null +++ b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java @@ -0,0 +1,84 @@ +package com.google.cloud.runtimes; + +import com.google.cloud.MonitoredResource; +import com.google.cloud.logging.LogEntry; +import com.google.cloud.logging.Logging; +import com.google.cloud.logging.Payload; +import com.google.cloud.logging.Severity; +import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import sun.util.logging.resources.logging; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +import static com.google.cloud.ServiceOptions.getDefaultProjectId; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + +@RestController +public class LoggingTestController { + + @Autowired + private Logging logging; + @Autowired + @Qualifier("projectId") + private String projectId; + + private static Logger LOG = Logger.getLogger(LoggingTestController.class.getName()); + + public static class LoggingTestRequest { + private String level; + private String log_name; + private String token; + + public void setLevel(String level) { + this.level = level; + } + + public void setLog_name(String log_name) { + this.log_name = log_name; + } + + public void setToken(String token) { + this.token = token; + } + + + @Override + public String toString() { + return "LoggingTestRequest{" + + "level='" + level + '\'' + + ", log_name='" + log_name + '\'' + + ", token='" + token + '\'' + + '}'; + } + } + + @RequestMapping(path = "/logging_custom", method = POST) + public String handleMonitoringRequest(@RequestBody LoggingTestRequest loggingTestRequest) throws IOException, InterruptedException { + LOG.info(String.valueOf(loggingTestRequest)); + + List entries = new ArrayList<>(); + Payload.StringPayload payload = Payload.StringPayload.of(loggingTestRequest.token); + Severity severity = Severity.valueOf(loggingTestRequest.level); + LogEntry entry = LogEntry.newBuilder(payload) + .setSeverity(severity) + .setLogName(loggingTestRequest.log_name) + .setResource(MonitoredResource.newBuilder("global").build()) + .build(); + entries.add(entry); + logging.write(entries); + LOG.info("Log written to StackDriver: " + entries); + return "OK"; + } + + +} diff --git a/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java b/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java index 7bf5b55c..d542a7a8 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java @@ -2,6 +2,7 @@ import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -9,7 +10,6 @@ import java.io.IOException; import java.util.logging.Logger; -import static com.google.cloud.ServiceOptions.getDefaultProjectId; import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @@ -18,6 +18,10 @@ public class MonitoringTestController { @Autowired private StackDriverMonitoringService stackDriverMonitoringService; + @Autowired + @Qualifier("projectId") + private String projectId; + private static Logger LOG = Logger.getLogger(MonitoringTestController.class.getName()); public static class MonitoringTestRequest { @@ -45,7 +49,7 @@ public String toString() { public String handleMonitoringRequest(@RequestBody MonitoringTestRequest monitoringTestRequest) throws IOException, InterruptedException { LOG.info(String.valueOf(monitoringTestRequest)); - stackDriverMonitoringService.createMetricAndInsertTestToken(getDefaultProjectId(), + stackDriverMonitoringService.createMetricAndInsertTestToken(projectId, monitoringTestRequest.name, monitoringTestRequest.token); diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java new file mode 100644 index 00000000..5b89ed3e --- /dev/null +++ b/test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java @@ -0,0 +1,35 @@ +package com.google.cloud.runtimes.config; + +import com.google.cloud.logging.Logging; +import com.google.cloud.logging.LoggingOptions; +import com.google.cloud.monitoring.v3.MetricServiceClient; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.io.IOException; + +import static com.google.cloud.ServiceOptions.getDefaultProjectId; + +@Configuration +@Profile("gcp") +public class GCPConfiguration { + + @Bean + public Logging getLogging() { + LoggingOptions options = LoggingOptions.getDefaultInstance(); + return options.getService(); + } + + @Bean + public MetricServiceClient getMetricServiceClient() throws IOException { + return MetricServiceClient.create(); + } + + @Qualifier("projectId") + @Bean + public String getProjectId() { + return getDefaultProjectId(); + } +} diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java new file mode 100644 index 00000000..ef7e4d84 --- /dev/null +++ b/test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java @@ -0,0 +1,53 @@ +package com.google.cloud.runtimes.config; + +import com.google.api.gax.core.CredentialsProvider; +import com.google.auth.Credentials; +import com.google.cloud.logging.Logging; +import com.google.cloud.monitoring.v3.MetricServiceClient; +import com.google.cloud.monitoring.v3.MetricServiceSettings; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.io.IOException; +import java.util.logging.Logger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; + +@Configuration +@Profile("mock-gcp") +public class MockGCPConfiguration { + + private final static Logger LOG = Logger.getLogger(MockGCPConfiguration.class.getName()); + + @Bean + public Logging getLogging() { + Logging loggingMock = mock(Logging.class); + doAnswer(invocationOnMock -> { + LOG.warning("Mock-GCP setup, Logging.write will result in no side-effects!"); + return null; + }).when(loggingMock).write(any()); + return loggingMock; + } + + @Bean + public MetricServiceClient getMetricServiceClient() throws IOException { + //it would be great if MetricServiceClient wouldn't have the final modifier + //in all the public methods - it makes it impossible to mock it nicely, + //that's why we are relying on mocking the part that breaks: authentication + MetricServiceSettings mockSettings = MetricServiceSettings.defaultBuilder() + .setCredentialsProvider(() -> mock(Credentials.class)) + .build(); + return MetricServiceClient.create(mockSettings); + } + + @Qualifier("projectId") + @Bean + public String getProjectId() { + return "mock-project-id"; + } +} diff --git a/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java b/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java index 21e98a77..9149b31d 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java @@ -6,6 +6,7 @@ import com.google.cloud.monitoring.v3.MetricServiceClient; import com.google.monitoring.v3.*; import com.google.protobuf.util.Timestamps; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -19,8 +20,10 @@ public class StackDriverMonitoringService { private int maxRetries; private static Logger LOG = Logger.getLogger(StackDriverMonitoringService.class.getName()); + @Autowired + private MetricServiceClient metricServiceClient; + public void createMetricAndInsertTestToken(String projectId, String metricType, long metricValue) throws IOException { - MetricServiceClient metricServiceClient = MetricServiceClient.create(); int retries = maxRetries; while (retries > 0) { try { diff --git a/test-application/src/main/resources/application.properties b/test-application/src/main/resources/application.properties index 2c668e38..fb3f121a 100644 --- a/test-application/src/main/resources/application.properties +++ b/test-application/src/main/resources/application.properties @@ -1,2 +1,3 @@ monitoring.write.retries=3 -deployment.token=@deployment.token@ \ No newline at end of file +deployment.token=@deployment.token@ +spring.profiles.active=@spring.profile@ \ No newline at end of file From d1ea344a93e2c6ee41c19d8dfeb286456878e0ec Mon Sep 17 00:00:00 2001 From: balopat Date: Tue, 22 Aug 2017 11:17:39 -0400 Subject: [PATCH 2/9] organize imports + namings --- .../com/google/cloud/runtimes/ExceptionController.java | 4 ++-- .../java/com/google/cloud/runtimes/HelloController.java | 4 ++-- .../com/google/cloud/runtimes/LoggingTestController.java | 7 +------ .../{GCPConfiguration.java => GcpConfiguration.java} | 3 ++- ...MockGCPConfiguration.java => MockGcpConfiguration.java} | 7 +++---- 5 files changed, 10 insertions(+), 15 deletions(-) rename test-application/src/main/java/com/google/cloud/runtimes/config/{GCPConfiguration.java => GcpConfiguration.java} (96%) rename test-application/src/main/java/com/google/cloud/runtimes/config/{MockGCPConfiguration.java => MockGcpConfiguration.java} (90%) diff --git a/test-application/src/main/java/com/google/cloud/runtimes/ExceptionController.java b/test-application/src/main/java/com/google/cloud/runtimes/ExceptionController.java index ec81e63c..5b4bfab7 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/ExceptionController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/ExceptionController.java @@ -1,11 +1,11 @@ package com.google.cloud.runtimes; -import static org.springframework.web.bind.annotation.RequestMethod.POST; - import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + @RestController public class ExceptionController { diff --git a/test-application/src/main/java/com/google/cloud/runtimes/HelloController.java b/test-application/src/main/java/com/google/cloud/runtimes/HelloController.java index 55e6276b..d4779bd4 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/HelloController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/HelloController.java @@ -1,10 +1,10 @@ package com.google.cloud.runtimes; -import static org.springframework.web.bind.annotation.RequestMethod.GET; - import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import static org.springframework.web.bind.annotation.RequestMethod.GET; + @RestController public class HelloController { diff --git a/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java index be1f23bf..5ab572af 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java @@ -5,22 +5,17 @@ import com.google.cloud.logging.Logging; import com.google.cloud.logging.Payload; import com.google.cloud.logging.Severity; -import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import sun.util.logging.resources.logging; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.logging.Logger; -import static com.google.cloud.ServiceOptions.getDefaultProjectId; import static org.springframework.web.bind.annotation.RequestMethod.POST; @RestController @@ -63,7 +58,7 @@ public String toString() { } @RequestMapping(path = "/logging_custom", method = POST) - public String handleMonitoringRequest(@RequestBody LoggingTestRequest loggingTestRequest) throws IOException, InterruptedException { + public String handleLoggingTestRequest(@RequestBody LoggingTestRequest loggingTestRequest) throws IOException, InterruptedException { LOG.info(String.valueOf(loggingTestRequest)); List entries = new ArrayList<>(); diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java similarity index 96% rename from test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java rename to test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java index 5b89ed3e..fe8ce3cd 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/config/GCPConfiguration.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java @@ -14,11 +14,12 @@ @Configuration @Profile("gcp") -public class GCPConfiguration { +public class GcpConfiguration { @Bean public Logging getLogging() { LoggingOptions options = LoggingOptions.getDefaultInstance(); + return options.getService(); } diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java similarity index 90% rename from test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java rename to test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java index ef7e4d84..97087151 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/config/MockGCPConfiguration.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java @@ -1,11 +1,9 @@ package com.google.cloud.runtimes.config; -import com.google.api.gax.core.CredentialsProvider; import com.google.auth.Credentials; import com.google.cloud.logging.Logging; import com.google.cloud.monitoring.v3.MetricServiceClient; import com.google.cloud.monitoring.v3.MetricServiceSettings; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -20,12 +18,13 @@ @Configuration @Profile("mock-gcp") -public class MockGCPConfiguration { +public class MockGcpConfiguration { - private final static Logger LOG = Logger.getLogger(MockGCPConfiguration.class.getName()); + private final static Logger LOG = Logger.getLogger(MockGcpConfiguration.class.getName()); @Bean public Logging getLogging() { + Logging loggingMock = mock(Logging.class); doAnswer(invocationOnMock -> { LOG.warning("Mock-GCP setup, Logging.write will result in no side-effects!"); From d2aa2330154a1f34df035189538d9abc4bff7bec Mon Sep 17 00:00:00 2001 From: balopat Date: Wed, 23 Aug 2017 16:52:49 -0400 Subject: [PATCH 3/9] changed test-app to lazy init + local-cloud-builder --- scripts/gcloud-init.sh | 1 + scripts/integration_test.sh | 2 +- scripts/local_integration_test.sh | 162 ------------------ .../local_runtimes_common_integration_test.sh | 97 +++++++++++ scripts/local_shutdown_test.sh | 99 +++++++++++ test-application/pom.xml | 14 +- .../cloud/runtimes/LoggingTestController.java | 6 +- .../runtimes/MonitoringTestController.java | 2 + .../runtimes/config/GcpConfiguration.java | 10 +- .../runtimes/config/MockGcpConfiguration.java | 52 ------ .../StackDriverMonitoringService.java | 25 ++- 11 files changed, 241 insertions(+), 229 deletions(-) delete mode 100755 scripts/local_integration_test.sh create mode 100755 scripts/local_runtimes_common_integration_test.sh create mode 100755 scripts/local_shutdown_test.sh delete mode 100644 test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java diff --git a/scripts/gcloud-init.sh b/scripts/gcloud-init.sh index 49da4885..c095030c 100755 --- a/scripts/gcloud-init.sh +++ b/scripts/gcloud-init.sh @@ -46,3 +46,4 @@ gcloud auth activate-service-account --key-file=$KEYFILE gcloud config set project $GCP_PROJECT gcloud config set compute/zone us-east1-b gcloud components install beta kubectl -q +gcloud components install beta container-builder-local diff --git a/scripts/integration_test.sh b/scripts/integration_test.sh index ae13c695..d0de962f 100755 --- a/scripts/integration_test.sh +++ b/scripts/integration_test.sh @@ -32,7 +32,7 @@ fi # is not recommended readonly gaeDeploymentVersion=$2 -${dir}/local_integration_test.sh ${imageUnderTest} +${dir}/local_shutdown_test.sh ${imageUnderTest} ${dir}/ae_integration_test.sh ${imageUnderTest} ${gaeDeploymentVersion} diff --git a/scripts/local_integration_test.sh b/scripts/local_integration_test.sh deleted file mode 100755 index c953b0fb..00000000 --- a/scripts/local_integration_test.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash - -# Copyright 2017 Google Inc. All rights reserved. - -# 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. - -# exit on command failure -set -e - -function usage() { - echo $1 - echo "Usage: ${0} [OPTIONS]" - echo "Options:" - echo "-v: verbose (displays logs for container and test driver)" - echo "-g: test integration with GCP services (requires GOOGLE_APPLICATION_CREDENTIALS)" - exit 1 -} - -function getPort() { - docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' ${CONTAINER} -} - - -function waitForOutput() { - found_output='false' - for run in {1..10} - do - grep "$1" ${OUTPUT_FILE} && found_output='true' && break - sleep 1 - done - - if [ "$found_output" == "false" ]; then - cat ${OUTPUT_FILE} - echo "did not match '$1' in '$OUTPUT_FILE'" - exit 1 - fi -} - - -readonly dir=$(dirname $0) -readonly projectRoot="$dir/.." -readonly testAppDir="$projectRoot/test-application" -readonly deployDir="$testAppDir/target/deploy" - -APP_IMAGE='openjdk-local-integration' -TEST_DRIVER_IMAGE='gcr.io/java-runtime-test/integration-test' -CONTAINER=${APP_IMAGE}-container -OUTPUT_FILE=${CONTAINER}-output.txt -DEPLOYMENT_TOKEN=$(uuidgen) - -readonly imageUnderTest=$1 -if [[ -z "$imageUnderTest" ]]; then - usage "Error: missing image!" -fi - -shift - -while getopts ":gv" opt; do - case $opt in - v) - VERBOSE="true" - DRIVER_OPTS="--verbose" - ;; - g) - WITH_GCP="true" - ;; - \?) - usage "Invalid option: -$OPTARG" - ;; - esac -done - -# build the test app -pushd ${testAppDir} -mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode -popd - -# build app container locally -pushd $deployDir -export STAGING_IMAGE=$imageUnderTest -envsubst < Dockerfile.in > Dockerfile -echo "Building app container..." -docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . || usage "Error building test-app image from base image \"${imageUnderTest}\", please make sure it exists!" - - -if [[ "$WITH_GCP" ]]; then - echo "--------" - echo "Starting test in GCP mode!" - echo "--------" - - if [[ -z ${GOOGLE_APPLICATION_CREDENTIALS} ]]; then - usage "Error: In GCP mode GOOGLE_APPLICATION_CREDENTIALS must be set." - fi - # we setup the container for GCP relying on the environment - GCP_CONTAINER_OPTS="-v ${GOOGLE_APPLICATION_CREDENTIALS}:/gcp_creds.json -e GOOGLE_APPLICATION_CREDENTIALS=/gcp_creds.json" - APP_CMD= - DRIVER_OPTS="$DRIVER_OPTS --skip-standard-logging-tests \ - --skip-custom-tests" -else - echo "--------" - echo "Starting test in MOCK-GCP mode!" - echo "--------" - # mock-gcp profile, the container is started as mock-gcp - GCP_CONTAINER_OPTS= - APP_CMD='java -Dspring.profiles.active=mock-gcp -jar app.jar' - DRIVER_OPTS="$DRIVER_OPTS --skip-monitoring-tests \ - --skip-custom-logging-tests \ - --skip-standard-logging-tests \ - --skip-custom-tests" -fi - -docker rm -f $CONTAINER &>/dev/null || echo "Integration-test-app container is not running, ready to start a new instance." - - -# run app container locally to test shutdown logging -echo "Starting app container..." -docker run --rm --name ${CONTAINER} ${GCP_CONTAINER_OPTS} -p 8080 \ - -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" \ - -e "SHUTDOWN_LOGGING_HEAP_INFO=true" \ - ${APP_IMAGE} ${APP_CMD} &> ${OUTPUT_FILE} & - -waitForOutput 'Started Application' - -PORT=`getPort` - -DEPLOYED_APP_URL=http://localhost:${PORT} - -echo "App deployed to URL: $DEPLOYED_APP_URL, making sure it accepts connections..." - -until [[ $(curl --silent --fail "${DEPLOYED_APP_URL}/deployment.token" | grep "${DEPLOYMENT_TOKEN}") ]]; do - sleep 2 -done - -DRIVER_OPTS="${DRIVER_OPTS} --url=${DEPLOYED_APP_URL}" - -[[ "${VERBOSE}" ]] && docker logs -f ${CONTAINER} & - -docker run --rm ${GCP_CONTAINER_OPTS} --net=host ${TEST_DRIVER_IMAGE} ${DRIVER_OPTS} - -docker stop ${CONTAINER} - -docker rmi -f ${APP_IMAGE} - -echo 'verify thread dump' -waitForOutput 'Full thread dump OpenJDK 64-Bit Server VM' - -echo 'verify heap info' -waitForOutput 'num.*instances.*bytes.*class name' - -popd - -echo 'OK' \ No newline at end of file diff --git a/scripts/local_runtimes_common_integration_test.sh b/scripts/local_runtimes_common_integration_test.sh new file mode 100755 index 00000000..48d92b14 --- /dev/null +++ b/scripts/local_runtimes_common_integration_test.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + + +# exit on command failure +set -e + +readonly dir=$(dirname $0) +readonly projectRoot="$dir/.." +readonly testAppDir="$projectRoot/test-application" +readonly deployDir="$testAppDir/target/deploy" + +APP_IMAGE='openjdk-local-integration' +CONTAINER=${APP_IMAGE}-container +OUTPUT_FILE=${CONTAINER}-output.txt +DEPLOYMENT_TOKEN=$(uuidgen) + +readonly imageUnderTest=$1 +if [[ -z "$imageUnderTest" ]]; then + echo "Usage: ${0} " + exit 1 +fi + +if [[ -z ${GOOGLE_APPLICATION_CREDENTIALS} ]]; then + echo "Error: GOOGLE_APPLICATION_CREDENTIALS must be set." + exit 1 +fi + + +# build the test app +pushd ${testAppDir} +mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode +popd + +# build app container locally +pushd $deployDir +export STAGING_IMAGE=$imageUnderTest +envsubst < Dockerfile.in > Dockerfile +echo "Building app container..." +docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . + +docker rm -f $CONTAINER || echo "Integration-test-app container is not running, ready to start a new instance." + +# run app container locally to test shutdown logging +echo "Starting app container..." +docker run --rm --name $CONTAINER -p 8080 \ + -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" \ + -e "SHUTDOWN_LOGGING_HEAP_INFO=true" \ + -e "GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS" \ + -v "$GOOGLE_APPLICATION_CREDENTIALS:$GOOGLE_APPLICATION_CREDENTIALS" $APP_IMAGE &> $OUTPUT_FILE & + +function waitForOutput() { + found_output='false' + for run in {1..10} + do + grep "$1" $OUTPUT_FILE && found_output='true' && break + sleep 1 + done + + if [ "$found_output" == "false" ]; then + cat $OUTPUT_FILE + echo "did not match '$1' in '$OUTPUT_FILE'" + exit 1 + fi +} + +waitForOutput 'Started Application' + +getPort() { + docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' ${CONTAINER} +} + + +PORT=`getPort` + +nslookup `hostname` | grep Address | grep -v 127.0 | awk '{print $2}' > /tmp/myip +MYIP=`cat /tmp/myip` + +DEPLOYED_APP_URL=http://$MYIP:$PORT + +echo app is deployed to $DEPLOYED_APP_URL, making sure it accepts connections + + +until [[ $(curl --silent --fail "$DEPLOYED_APP_URL/deployment.token" | grep "$DEPLOYMENT_TOKEN") ]]; do + sleep 2 +done +popd + +docker rm -f metadata || echo "ready to run local cloud builder" + +# run in cloud container builder +echo "Running integration tests on application that is deployed at $DEPLOYED_APP_URL" +echo `pwd` +container-builder-local \ + --config ${dir}/integration_test.yaml \ + --substitutions "_DEPLOYED_APP_URL=$DEPLOYED_APP_URL" \ + --dryrun=false \ + ${dir} \ No newline at end of file diff --git a/scripts/local_shutdown_test.sh b/scripts/local_shutdown_test.sh new file mode 100755 index 00000000..e344cddd --- /dev/null +++ b/scripts/local_shutdown_test.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# Copyright 2017 Google Inc. All rights reserved. + +# 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. + + +# exit on command failure +set -e + + +readonly dir=$(dirname $0) +readonly projectRoot="$dir/.." +readonly testAppDir="$projectRoot/test-application" +readonly deployDir="$testAppDir/target/deploy" + +APP_IMAGE='openjdk-local-integration' +CONTAINER=${APP_IMAGE}-container +OUTPUT_FILE=${CONTAINER}-output.txt +DEPLOYMENT_TOKEN=$(uuidgen) + +readonly imageUnderTest=$1 +if [[ -z "$imageUnderTest" ]]; then + echo "Usage: ${0} " + exit 1 +fi + +# build the test app +pushd ${testAppDir} +mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode +popd + +# build app container locally +pushd $deployDir +export STAGING_IMAGE=$imageUnderTest +envsubst < Dockerfile.in > Dockerfile +echo "Building app container..." +docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . + +docker rm -f $CONTAINER || echo "Integration-test-app container is not running, ready to start a new instance." + +# run app container locally to test shutdown logging +echo "Starting app container..." +docker run --rm --name $CONTAINER -p 8080 -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" -e "SHUTDOWN_LOGGING_HEAP_INFO=true" $APP_IMAGE &> $OUTPUT_FILE & + +function waitForOutput() { + found_output='false' + for run in {1..10} + do + grep "$1" $OUTPUT_FILE && found_output='true' && break + sleep 1 + done + + if [ "$found_output" == "false" ]; then + cat $OUTPUT_FILE + echo "did not match '$1' in '$OUTPUT_FILE'" + exit 1 + fi +} + +waitForOutput 'Started Application' + +getPort() { + docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' ${CONTAINER} +} + + +PORT=`getPort` + +echo port is $PORT + +until [[ $(curl --silent --fail "http://localhost:$PORT/deployment.token" | grep "$DEPLOYMENT_TOKEN") ]]; do + sleep 2 +done + + +docker stop $CONTAINER + +docker rmi $APP_IMAGE + +echo 'verify thread dump' +waitForOutput 'Full thread dump OpenJDK 64-Bit Server VM' + +echo 'verify heap info' +waitForOutput 'num.*instances.*bytes.*class name' + +popd + +echo 'OK' \ No newline at end of file diff --git a/test-application/pom.xml b/test-application/pom.xml index 804f6fef..bc511b93 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -36,17 +36,27 @@ com.google.cloud google-cloud-monitoring - 0.20.1-alpha + 0.22.0-alpha com.google.auth google-auth-library-credentials 0.7.0 + + com.google.api + gax + 1.6.0 + + + com.google.api + gax-grpc + 0.23.0 + com.google.cloud google-cloud-logging - 1.2.1 + 1.4.0 org.mockito diff --git a/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java index 5ab572af..98166192 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/LoggingTestController.java @@ -6,7 +6,7 @@ import com.google.cloud.logging.Payload; import com.google.cloud.logging.Severity; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,10 +22,8 @@ public class LoggingTestController { @Autowired + @Lazy private Logging logging; - @Autowired - @Qualifier("projectId") - private String projectId; private static Logger LOG = Logger.getLogger(LoggingTestController.class.getName()); diff --git a/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java b/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java index d542a7a8..2979b92e 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/MonitoringTestController.java @@ -3,6 +3,7 @@ import com.google.cloud.runtimes.stackdriver.StackDriverMonitoringService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,6 +17,7 @@ public class MonitoringTestController { @Autowired + @Lazy private StackDriverMonitoringService stackDriverMonitoringService; @Autowired diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java index fe8ce3cd..4e9bec77 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/config/GcpConfiguration.java @@ -3,27 +3,29 @@ import com.google.cloud.logging.Logging; import com.google.cloud.logging.LoggingOptions; import com.google.cloud.monitoring.v3.MetricServiceClient; +import com.google.cloud.monitoring.v3.MetricServiceSettings; +import com.google.cloud.monitoring.v3.stub.MetricServiceStub; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.Lazy; import java.io.IOException; import static com.google.cloud.ServiceOptions.getDefaultProjectId; @Configuration -@Profile("gcp") public class GcpConfiguration { @Bean + @Lazy public Logging getLogging() { LoggingOptions options = LoggingOptions.getDefaultInstance(); - return options.getService(); } - @Bean + @Bean(name = "metricServiceClient") + @Lazy public MetricServiceClient getMetricServiceClient() throws IOException { return MetricServiceClient.create(); } diff --git a/test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java b/test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java deleted file mode 100644 index 97087151..00000000 --- a/test-application/src/main/java/com/google/cloud/runtimes/config/MockGcpConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.google.cloud.runtimes.config; - -import com.google.auth.Credentials; -import com.google.cloud.logging.Logging; -import com.google.cloud.monitoring.v3.MetricServiceClient; -import com.google.cloud.monitoring.v3.MetricServiceSettings; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; - -import java.io.IOException; -import java.util.logging.Logger; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; - -@Configuration -@Profile("mock-gcp") -public class MockGcpConfiguration { - - private final static Logger LOG = Logger.getLogger(MockGcpConfiguration.class.getName()); - - @Bean - public Logging getLogging() { - - Logging loggingMock = mock(Logging.class); - doAnswer(invocationOnMock -> { - LOG.warning("Mock-GCP setup, Logging.write will result in no side-effects!"); - return null; - }).when(loggingMock).write(any()); - return loggingMock; - } - - @Bean - public MetricServiceClient getMetricServiceClient() throws IOException { - //it would be great if MetricServiceClient wouldn't have the final modifier - //in all the public methods - it makes it impossible to mock it nicely, - //that's why we are relying on mocking the part that breaks: authentication - MetricServiceSettings mockSettings = MetricServiceSettings.defaultBuilder() - .setCredentialsProvider(() -> mock(Credentials.class)) - .build(); - return MetricServiceClient.create(mockSettings); - } - - @Qualifier("projectId") - @Bean - public String getProjectId() { - return "mock-project-id"; - } -} diff --git a/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java b/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java index 9149b31d..b104feae 100644 --- a/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java +++ b/test-application/src/main/java/com/google/cloud/runtimes/stackdriver/StackDriverMonitoringService.java @@ -4,10 +4,16 @@ import com.google.api.MetricDescriptor; import com.google.api.MonitoredResource; import com.google.cloud.monitoring.v3.MetricServiceClient; +import com.google.cloud.monitoring.v3.stub.MetricServiceStub; +import com.google.cloud.runtimes.config.GcpConfiguration; import com.google.monitoring.v3.*; import com.google.protobuf.util.Timestamps; +import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.io.IOException; @@ -16,31 +22,41 @@ @Service public class StackDriverMonitoringService { + @Autowired + private ApplicationContext applicationContext; + @Value("${monitoring.write.retries}") private int maxRetries; private static Logger LOG = Logger.getLogger(StackDriverMonitoringService.class.getName()); - @Autowired - private MetricServiceClient metricServiceClient; public void createMetricAndInsertTestToken(String projectId, String metricType, long metricValue) throws IOException { int retries = maxRetries; while (retries > 0) { try { CreateTimeSeriesRequest timeSeriesRequest = createTimeSeriesRequest(projectId, metricType, metricValue); - metricServiceClient.createTimeSeries(timeSeriesRequest); + getClient().createTimeSeries(timeSeriesRequest); LOG.info("Metric created with timeseries."); return; } catch (Exception e) { LOG.warning("error creating timeseries request, retrying..." + e.getClass() + ": " + e.getMessage()); retries--; if (retries == 0) { - throw new IllegalStateException("Failed to store timeseries after "+ maxRetries +" attempts! Last error:", e); + throw new IllegalStateException("Failed to store timeseries after " + maxRetries + " attempts! Last error:", e); } } } } + /** + * This pairs up with the @Lazy annotation on {@link GcpConfiguration#getMetricServiceClient()}. + * As MetricServiceClient methods are all `final` and that breaks the "@Autowire @Lazy" combination, + * this is the only way to wire this bean lazily. + */ + private MetricServiceClient getClient() { + return (MetricServiceClient) applicationContext.getBean("metricServiceClient"); + } + private CreateTimeSeriesRequest createTimeSeriesRequest(String projectId, String metricType, Long metricValue) { LOG.info("Creating time series to insert token: " + metricValue); ProjectName projectName = ProjectName.create(projectId); @@ -69,4 +85,5 @@ private CreateTimeSeriesRequest createTimeSeriesRequest(String projectId, String .build(); } + } From 5e98cd749851cbae188a5d6e2a1dcd4cb9a09bdf Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 7 Sep 2017 11:29:53 -0400 Subject: [PATCH 4/9] DEVELOPING instructions updated + enforcer plugin fixed for property resolution --- DEVELOPING.md | 8 +++++++- openjdk-common/pom.xml | 11 +++++++++++ pom.xml | 26 +++++++++----------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 97529dfb..daded9bb 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -56,9 +56,15 @@ $ ./scripts/integration_test.sh $RUNTIME_IMAGE **Run ONLY Local Docker integration tests:** ```bash -$ ./scripts/local_integration_test.sh $RUNTIME_IMAGE +$ ./scripts/local_runtimes_common_integration_test.sh $RUNTIME_IMAGE ``` +**Run ONLY Local shutdown tests:** +```bash +$ ./scripts/local_shutdown_test.sh $RUNTIME_IMAGE +``` + + **Run ONLY App Engine flexible environment integration tests:** ```bash $ ./scripts/ae_integration_test.sh $RUNTIME_IMAGE diff --git a/openjdk-common/pom.xml b/openjdk-common/pom.xml index 24396fca..860e84d1 100644 --- a/openjdk-common/pom.xml +++ b/openjdk-common/pom.xml @@ -31,6 +31,17 @@ + + maven-enforcer-plugin + + + + enforce + + validate + + + org.apache.maven.plugins maven-assembly-plugin diff --git a/pom.xml b/pom.xml index 9f57088d..8a7c6990 100644 --- a/pom.xml +++ b/pom.xml @@ -67,24 +67,16 @@ org.apache.maven.plugins maven-enforcer-plugin 1.4.1 - - - enforce-maven - - enforce - - - - - [3.0,) - - + + + + [3.3,) + + [1.8,) - - - - - + + + From 649b8d2cbeb63d8dcead8ae911d41ed003e8fee5 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 7 Sep 2017 11:45:37 -0400 Subject: [PATCH 5/9] cleanup --- .../local_runtimes_common_integration_test.sh | 16 +++++++++++++++- test-application/pom.xml | 1 - .../src/main/resources/application.properties | 3 +-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/local_runtimes_common_integration_test.sh b/scripts/local_runtimes_common_integration_test.sh index 48d92b14..36f4b190 100755 --- a/scripts/local_runtimes_common_integration_test.sh +++ b/scripts/local_runtimes_common_integration_test.sh @@ -1,4 +1,18 @@ -#!/usr/bin/env bash +#!/bin/bash + +# Copyright 2017 Google Inc. All rights reserved. + +# 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. # exit on command failure diff --git a/test-application/pom.xml b/test-application/pom.xml index bc511b93..a0ba20ff 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -25,7 +25,6 @@ ${java.version} ${java.version} default_deployment_token - gcp diff --git a/test-application/src/main/resources/application.properties b/test-application/src/main/resources/application.properties index fb3f121a..2c668e38 100644 --- a/test-application/src/main/resources/application.properties +++ b/test-application/src/main/resources/application.properties @@ -1,3 +1,2 @@ monitoring.write.retries=3 -deployment.token=@deployment.token@ -spring.profiles.active=@spring.profile@ \ No newline at end of file +deployment.token=@deployment.token@ \ No newline at end of file From b05354e9bf8e17d6cc1785bb3ccfd2d7d844d178 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 7 Sep 2017 11:45:37 -0400 Subject: [PATCH 6/9] cleanup --- .../local_runtimes_common_integration_test.sh | 16 +++++++++++++++- scripts/local_shutdown_test.sh | 1 - test-application/pom.xml | 1 - .../src/main/resources/application.properties | 3 +-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/local_runtimes_common_integration_test.sh b/scripts/local_runtimes_common_integration_test.sh index 48d92b14..36f4b190 100755 --- a/scripts/local_runtimes_common_integration_test.sh +++ b/scripts/local_runtimes_common_integration_test.sh @@ -1,4 +1,18 @@ -#!/usr/bin/env bash +#!/bin/bash + +# Copyright 2017 Google Inc. All rights reserved. + +# 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. # exit on command failure diff --git a/scripts/local_shutdown_test.sh b/scripts/local_shutdown_test.sh index 4f1d1da9..0cd101ce 100755 --- a/scripts/local_shutdown_test.sh +++ b/scripts/local_shutdown_test.sh @@ -18,7 +18,6 @@ # exit on command failure set -e - readonly dir=$(dirname $0) readonly projectRoot="$dir/.." readonly testAppDir="$projectRoot/test-application" diff --git a/test-application/pom.xml b/test-application/pom.xml index bc511b93..a0ba20ff 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -25,7 +25,6 @@ ${java.version} ${java.version} default_deployment_token - gcp diff --git a/test-application/src/main/resources/application.properties b/test-application/src/main/resources/application.properties index fb3f121a..2c668e38 100644 --- a/test-application/src/main/resources/application.properties +++ b/test-application/src/main/resources/application.properties @@ -1,3 +1,2 @@ monitoring.write.retries=3 -deployment.token=@deployment.token@ -spring.profiles.active=@spring.profile@ \ No newline at end of file +deployment.token=@deployment.token@ \ No newline at end of file From 0cffb4419eddd8c596c8650376edac8461da3408 Mon Sep 17 00:00:00 2001 From: Balint Pato Date: Thu, 7 Sep 2017 16:15:58 -0400 Subject: [PATCH 7/9] Add shutdown tests back to maven execution (#149) --- openjdk8/pom.xml | 4 ++++ openjdk9/pom.xml | 4 ++++ pom.xml | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/openjdk8/pom.xml b/openjdk8/pom.xml index bf55316b..deecf261 100644 --- a/openjdk8/pom.xml +++ b/openjdk8/pom.xml @@ -93,6 +93,10 @@ common-structure-test integration-test + + local-shutdown-test + integration-test + openjdk8-structure-test diff --git a/openjdk9/pom.xml b/openjdk9/pom.xml index fcec22a9..fd284bae 100644 --- a/openjdk9/pom.xml +++ b/openjdk9/pom.xml @@ -92,6 +92,10 @@ common-structure-test integration-test + + local-shutdown-test + integration-test + openjdk9-structure-test diff --git a/pom.xml b/pom.xml index 8a7c6990..c6c4e683 100644 --- a/pom.xml +++ b/pom.xml @@ -183,6 +183,22 @@ + + local-shutdown-test + + none + + exec + + + ${project.parent.basedir}/scripts/local_shutdown_test.sh + ${project.build.outputDirectory} + + ${docker.image.name} + + + From e3eff4c6b3b958fa236822eb00567be0e4d63241 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 7 Sep 2017 16:22:32 -0400 Subject: [PATCH 8/9] cleanup + adding automated application-default credentials logic instead of GOOGLE_APPLICATION_CREDENTIALS --- scripts/local_runtimes_common_integration_test.sh | 12 +++++------- test-application/pom.xml | 5 ----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/local_runtimes_common_integration_test.sh b/scripts/local_runtimes_common_integration_test.sh index 36f4b190..953fb3e1 100755 --- a/scripts/local_runtimes_common_integration_test.sh +++ b/scripts/local_runtimes_common_integration_test.sh @@ -34,12 +34,11 @@ if [[ -z "$imageUnderTest" ]]; then exit 1 fi -if [[ -z ${GOOGLE_APPLICATION_CREDENTIALS} ]]; then - echo "Error: GOOGLE_APPLICATION_CREDENTIALS must be set." - exit 1 +if [[ ! -f $HOME/.config/gcloud/application_default_credentials.json ]]; then + # get default application credentials + gcloud auth application-default login fi - # build the test app pushd ${testAppDir} mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode @@ -50,7 +49,7 @@ pushd $deployDir export STAGING_IMAGE=$imageUnderTest envsubst < Dockerfile.in > Dockerfile echo "Building app container..." -docker build -t $APP_IMAGE . || gcloud docker -- build -t $APP_IMAGE . +docker build -t $APP_IMAGE . || docker build -t $APP_IMAGE . docker rm -f $CONTAINER || echo "Integration-test-app container is not running, ready to start a new instance." @@ -59,8 +58,7 @@ echo "Starting app container..." docker run --rm --name $CONTAINER -p 8080 \ -e "SHUTDOWN_LOGGING_THREAD_DUMP=true" \ -e "SHUTDOWN_LOGGING_HEAP_INFO=true" \ - -e "GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS" \ - -v "$GOOGLE_APPLICATION_CREDENTIALS:$GOOGLE_APPLICATION_CREDENTIALS" $APP_IMAGE &> $OUTPUT_FILE & + -v "$HOME/.config/gcloud/:/root/.config/gcloud" $APP_IMAGE &> $OUTPUT_FILE & function waitForOutput() { found_output='false' diff --git a/test-application/pom.xml b/test-application/pom.xml index a0ba20ff..8a05cc86 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -57,11 +57,6 @@ google-cloud-logging 1.4.0 - - org.mockito - mockito-core - 2.8.47 - From 1654ef9ea3d5d9f56e42299ae539546826396c90 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 7 Sep 2017 16:38:29 -0400 Subject: [PATCH 9/9] cleaning up unnecessary dependencies --- test-application/pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test-application/pom.xml b/test-application/pom.xml index 8a05cc86..bb0276df 100644 --- a/test-application/pom.xml +++ b/test-application/pom.xml @@ -37,21 +37,6 @@ google-cloud-monitoring 0.22.0-alpha - - com.google.auth - google-auth-library-credentials - 0.7.0 - - - com.google.api - gax - 1.6.0 - - - com.google.api - gax-grpc - 0.23.0 - com.google.cloud google-cloud-logging