Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Record deployment latency for both ubuntu16 and debian8 images (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo authored May 11, 2018
1 parent 700aeac commit 6ca8575
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 49 deletions.
1 change: 1 addition & 0 deletions cloudbuild-test-runner/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty gcloudignore
2 changes: 1 addition & 1 deletion cloudbuild-test-runner/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Dockerfile for running phpunit within a cloudbuild step.

FROM ${PHP_56_IMAGE}
FROM ${TEST_RUNNER_BASE_IMAGE}

RUN mkdir -p /opt/bin
ENV PATH=${PATH}:/usr/local/bin:/opt/gcloud/google-cloud-sdk/bin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ private static function createApp($phpVersion)
copy(__DIR__ . '/files/app.yaml', $tempDir . '/app.yaml');
copy(__DIR__ . '/files/web/index.php', $tempDir . '/web/index.php');
chdir($tempDir);
self::execWithError(
'composer require google/cloud',
'composer require google/cloud'
);
self::execWithError(
'composer --ignore-platform-reqs require php:' . $phpVersion . '.*',
'composer require php'
);
$composerJSON = [
'require' => [
'php' => $phpVersion . '.*',
'google/cloud' => '*'
]
];
file_put_contents('composer.json', json_encode($composerJSON));
return $tempDir;
}

Expand All @@ -58,49 +57,66 @@ public function testDeploymentLatency()
$phpVersions = [
'5.6',
'7.0',
'7.1'
'7.1',
'7.2'
];
$types = [
'xrt',
'builder'
'debian8',
'ubuntu16'
];
$gcloudTrack = getenv('GCLOUD_TRACK') === 'beta' ? 'beta' : '';
foreach ($phpVersions as $phpVersion) {
$dir = self::createApp($phpVersion);
chdir($dir);
foreach ($types as $type) {
$reportName = sprintf('%s-%s', $type, $phpVersion);
$failureCount = 0;
$command = 'gcloud -q ' . $gcloudTrack . ' app deploy'
. ' --version '
. str_replace('.', '', $reportName)
. ' --no-stop-previous-version --no-promote';
$configCmd = 'gcloud config set app/use_runtime_builders '
. ($type === 'xrt' ? 'false' : 'true');
self::execWithError($configCmd, 'runtime-builders-config');
$latency = 0.0;
while ($failureCount < self::DEPLOYMENT_MAX_RETRY) {
$start = microtime(true);
$ret = self::execWithResult($command);
if ($ret === 0) {
$latency = microtime(true) - $start;
break;
$dir = self::createApp($phpVersion);
chdir($dir);
try {
$reportName = sprintf('%s-%s', $type, $phpVersion);
$failureCount = 0;
$command = 'gcloud -q ' . $gcloudTrack . ' app deploy'
. ' --version '
. str_replace('.', '', $reportName)
. ' --no-stop-previous-version --no-promote';
$configCmd = 'gcloud config set app/use_runtime_builders true';
self::execWithError($configCmd, 'runtime-builders-config');
$f = fopen('app.yaml', 'a+');
fwrite($f, " base_os: $type\n");
$latency = 0.0;
while ($failureCount < self::DEPLOYMENT_MAX_RETRY) {
$start = microtime(true);
$ret = self::execWithResult($command);
if ($ret === 0) {
$latency = microtime(true) - $start;
break;
}
$failureCount++;
}
self::$bigQuery = self::createBigQueryClient();
$dataset = self::$bigQuery->dataset(self::DATASET_ID);
$table = $dataset->table(self::TABLE_ID);
$timestamp = self::$bigQuery->timestamp(new \DateTime());
$row = [
'deployment_latency_seconds' => $latency,
'report_name' => $reportName,
'failure_count' => $failureCount,
't' => $timestamp
];
$table->insertRow($row);
echo "Inserted: $reportName failure: $failureCount" . PHP_EOL;
echo "Inserted: $reportName latency: $latency" . PHP_EOL;
} finally {
$command = 'gcloud -q ' . $gcloudTrack . ' app versions delete '
. str_replace('.', '', $reportName);
$failureCount = 0;
while ($failureCount < self::DEPLOYMENT_MAX_RETRY) {
$start = microtime(true);
$ret = self::execWithResult($command);
if ($ret === 0) {
break;
}
$failureCount++;
}
$failureCount++;
exec("rm -rf $dir");
}
self::$bigQuery = self::createBigQueryClient();
$dataset = self::$bigQuery->dataset(self::DATASET_ID);
$table = $dataset->table(self::TABLE_ID);
$timestamp = self::$bigQuery->timestamp(new \DateTime());
$row = [
'deployment_latency_seconds' => $latency,
'report_name' => $reportName,
'failure_count' => $failureCount,
't' => $timestamp
];
$table->insertRow($row);
echo "Inserted: $reportName failure: $failureCount" . PHP_EOL;
echo "Inserted: $reportName latency: $latency" . PHP_EOL;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export BASE_IMAGE="gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_PREFIX}php:${TAG}"
export PHP_56_IMAGE="gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_PREFIX}php56:${TAG}"
export PHP_71_IMAGE="gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_PREFIX}php71:${TAG}"
export PHP_72_IMAGE="gcr.io/${GOOGLE_PROJECT_ID}/${IMAGE_PREFIX}php71:${TAG}"
export TEST_RUNNER_BASE_IMAGE=${PHP_56_IMAGE}

if [ -z "${RUNTIME_DISTRIBUTION}" ]; then
RUNTIME_DISTRIBUTION="${DEFAULT_RUNTIME_DISTRIBUTION}"
Expand All @@ -51,7 +52,7 @@ export RUNTIME_DISTRIBUTION

for TEMPLATE in `find . -name Dockerfile.in`
do
envsubst '${BASE_IMAGE} ${PHP_BASE_IMAGE} ${PHP_71_IMAGE} ${PHP_56_IMAGE} ${PHP_72_IMAGE}' \
envsubst '${BASE_IMAGE} ${PHP_BASE_IMAGE} ${PHP_71_IMAGE} ${PHP_56_IMAGE} ${PHP_72_IMAGE} ${TEST_RUNNER_BASE_IMAGE}' \
< ${TEMPLATE} \
> $(dirname ${TEMPLATE})/$(basename -s .in ${TEMPLATE})
done
Expand Down
4 changes: 2 additions & 2 deletions scripts/check_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ gcloud auth activate-service-account \
SRC_TMP=$(mktemp -d)

# build the php test runner
export PHP_56_IMAGE="gcr.io/google-appengine/php56:latest"
envsubst '${PHP_56_IMAGE}' \
export TEST_RUNNER_BASE_IMAGE="gcr.io/google-appengine/php56:latest"
envsubst '${TEST_RUNNER_BASE_IMAGE}' \
< cloudbuild-test-runner/Dockerfile.in \
> cloudbuild-test-runner/Dockerfile

Expand Down
4 changes: 2 additions & 2 deletions scripts/record_deployment_latency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ TEST_RUNNER="gcr.io/${GOOGLE_PROJECT_ID}/php-test-runner:${TAG}"

if [ -n "${REBUILD_TEST_RUNNER}" ]; then
# build the php test runner
export PHP_56_IMAGE="gcr.io/google-appengine/php56:latest"
envsubst '${PHP_56_IMAGE}' \
export TEST_RUNNER_BASE_IMAGE="gcr.io/google-appengine/ubuntu-php72:latest"
envsubst '${TEST_RUNNER_BASE_IMAGE}' \
< cloudbuild-test-runner/Dockerfile.in \
> cloudbuild-test-runner/Dockerfile
gcloud -q container builds submit --tag "${TEST_RUNNER}" \
Expand Down
1 change: 1 addition & 0 deletions scripts/run_acceptance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fi
export PHP_BASE_IMAGE="gcr.io/google-appengine/php-base"
export BASE_IMAGE="gcr.io/google-appengine/php"
export PHP_56_IMAGE="gcr.io/google-appengine/php56"
export TEST_RUNNER_BASE_IMAGE=${PHP_56_IMAGE}

for TEMPLATE in `find . -name Dockerfile.in`
do
Expand Down

0 comments on commit 6ca8575

Please sign in to comment.