-
Notifications
You must be signed in to change notification settings - Fork 41
adding custom logging test + local runtimes-common integration test #134
Changes from 6 commits
991e696
d1ea344
d2aa233
bf08154
5e98cd7
649b8d2
b05354e
0cffb44
ff6b6cf
e3eff4c
1654ef9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/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} <image_under_test>" | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're not really doing a shutdown logging test here. |
||
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} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,13 +35,33 @@ | |
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-monitoring</artifactId> | ||
<version>0.20.1-alpha</version> | ||
<version>0.22.0-alpha</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.auth</groupId> | ||
<artifactId>google-auth-library-credentials</artifactId> | ||
<version>0.7.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.api</groupId> | ||
<artifactId>gax</artifactId> | ||
<version>1.6.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.api</groupId> | ||
<artifactId>gax-grpc</artifactId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this (and the one above) not a transitive dependency of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch - let me double check & I will clarify in comments. |
||
<version>0.23.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-logging</artifactId> | ||
<version>1.4.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>2.8.47</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
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 org.springframework.beans.factory.annotation.Autowired; | ||
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; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
import static org.springframework.web.bind.annotation.RequestMethod.POST; | ||
|
||
@RestController | ||
public class LoggingTestController { | ||
|
||
@Autowired | ||
@Lazy | ||
private Logging logging; | ||
|
||
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 handleLoggingTestRequest(@RequestBody LoggingTestRequest loggingTestRequest) throws IOException, InterruptedException { | ||
LOG.info(String.valueOf(loggingTestRequest)); | ||
|
||
List<LogEntry> 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the Logging client lib directly, we should be able to use the JUL appender. Can you also look at #72 that has been put on the back-burner, and reconcile it with what you're doing in this PR? Ideally, we would like to close out #72 as well, but I think there are some unresolved complications there with setting up JUL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the Custom Logging Test should use the client library and make an explicit call to Stackdriver Logging (by creating only one LogEntry), whereas the Standard Logging Test should redirect the output of JUL to Stackdriver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @cassand - I was planning to use JUL for standard logging tests and Logging library directly for custom, just so that we have both covered. If you're okay with that, I will review #72 in the context of the Standard Logging test (I just added a new, separate issue for it: #139) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm OK with Damien's suggestion. |
||
LOG.info("Log written to StackDriver: " + entries); | ||
return "OK"; | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readme instructions don't mention
GOOGLE_APPLICATION_CREDENTIALS
.Can we just leverage gcloud for the default credentials?