Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit fbdb114

Browse files
committed
Merge pull request #11 from andrewsg/health_checks
handle health checks in middleware
2 parents 7215370 + 6a94c0f commit fbdb114

4 files changed

Lines changed: 52 additions & 11 deletions

File tree

multicore_runtime/dev/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN apt-get -q update && \
55
python2.7 python-pip python-gevent python-greenlet && \
66
apt-get clean && rm /var/lib/apt/lists/*_*
77

8-
COPY python-runtime-0.1.tar.gz /home/vmagent/python-runtime.tar.gz
8+
COPY appengine-python-vm-runtime-0.1.tar.gz /home/vmagent/python-runtime.tar.gz
99

1010
RUN pip install --upgrade pip>=6.1.1 gunicorn==19.1.1
1111
RUN pip install /home/vmagent/python-runtime.tar.gz

multicore_runtime/middleware.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import logging
1818
import os
1919

20+
from werkzeug.wrappers import Request
21+
from werkzeug.wrappers import Response
22+
2023

2124
RESERVED_ENV_KEYS = {
2225
'AUTH_DOMAIN': 'gmail.com', # Default auth domain must be set.
@@ -160,3 +163,23 @@ def get_env_to_hide_service_bridge(wsgi_env):
160163
'SERVER_PORT', https)
161164

162165
return output
166+
167+
168+
def health_check_middleware(app):
169+
"""Intercept requests to /_ah/health and respond healthy (200 OK).
170+
171+
Args:
172+
app: The WSGI app to wrap.
173+
174+
Returns:
175+
The wrapped app, also a WSGI app.
176+
"""
177+
178+
def health_check_intercept_wrapper(wsgi_env, start_response): # pylint: disable=missing-docstring
179+
request = Request(wsgi_env)
180+
if request.path == '/_ah/health': # Only intercept exact matches.
181+
return Response('healthy', status=200)(wsgi_env, start_response)
182+
else:
183+
return app(wsgi_env, start_response)
184+
185+
return health_check_intercept_wrapper

multicore_runtime/wsgi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from dispatcher import dispatcher
2727
from middleware import reset_environment_middleware
28+
from middleware import health_check_middleware
2829
from wsgi_config import env_vars_from_env_config
2930
from wsgi_config import get_module_config
3031
from wsgi_config import get_module_config_filename
@@ -83,7 +84,11 @@
8384
# layer (the middleware code that will process a request first). Inside the
8485
# innermost layer is the actual dispatcher, above.
8586

87+
# Intercept health check requests on /_ah/health. This is a temporary measure
88+
# until container-level health check handlers are in place and turned on.
89+
meta_app = health_check_middleware(meta_app)
90+
8691
# Reset os.environ to the frozen state and add request-specific data.
8792
meta_app = reset_environment_middleware(meta_app, frozen_environment,
8893
frozen_user_env,
89-
frozen_env_config_env)
94+
frozen_env_config_env)

setup.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
from setuptools import setup, find_packages
1+
# Copyright 2015 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Configure and install the runtime package."""
216

3-
setup(name='python-runtime',
17+
from setuptools import find_packages
18+
from setuptools import setup
19+
20+
setup(name='appengine-python-vm-runtime',
421
version='0.1',
522
description='Google App Engine-compatible Python runtime for Managed VMs',
623
url='https://github.com/GoogleCloudPlatform/appengine-python-vm-runtime',
@@ -9,19 +26,15 @@
926
classifiers=[
1027
'Development Status :: 3 - Alpha',
1128
'Intended Audience :: Developers',
12-
'License :: OSI Approved :: MIT License',
29+
'License :: OSI Approved :: Apache Software License',
1330
'Programming Language :: Python :: 2',
1431
'Programming Language :: Python :: 2.7',
1532
],
1633
package_dir={'': 'python_vm_runtime',
1734
'google.appengine.vmruntime': 'multicore_runtime',},
1835
include_package_data=True,
19-
packages=find_packages('python_vm_runtime') + ['google.appengine.vmruntime'],
20-
# namespace_packages=['google'], # While google is a namespace, marking
21-
# it as such makes the installer skip
22-
# __init__.py, which breaks some
23-
# packages expecting google to have
24-
# a __file__ attribute.
36+
packages=find_packages('python_vm_runtime') + ['google.appengine.vmruntime'], # pylint: disable=line-too-long
37+
# namespace_packages=['google'], # This skips google/__init__.py
2538
install_requires=['requests>=2.5.0',
2639
'webapp2>=2.5.2',
2740
'WebOb>=1.4',

0 commit comments

Comments
 (0)