Add Shipyard profiler

This commit adds the Werkzeug ProfilerMiddleware to Shipyard API
requests. This option can be enabled using the
`conf.shipyard.base.profiler` option and should not be used in
production.

Change-Id: I293840d78baf670478047faad87fdcfe2f8af70e
This commit is contained in:
Drew Walters 2018-10-03 22:25:15 +00:00
parent e11c621a84
commit 54224ea98d
6 changed files with 39 additions and 1 deletions

View File

@ -84,8 +84,16 @@ spec:
subPath: policy.yaml subPath: policy.yaml
mountPath: /etc/shipyard/policy.yaml mountPath: /etc/shipyard/policy.yaml
readOnly: true readOnly: true
{{ if .Values.conf.shipyard.base.profiler }}
- name: tmp-profiles
mountPath: /tmp/profiles
{{ end }}
{{ if $mounts_shipyard.volumeMounts }}{{ toYaml $mounts_shipyard.volumeMounts | indent 12 }}{{ end }} {{ if $mounts_shipyard.volumeMounts }}{{ toYaml $mounts_shipyard.volumeMounts | indent 12 }}{{ end }}
volumes: volumes:
{{ if .Values.conf.shipyard.base.profiler }}
- name: tmp-profiles
emptyDir: {}
{{ end }}
- name: etc-shipyard - name: etc-shipyard
emptyDir: {} emptyDir: {}
- name: shipyard-etc - name: shipyard-etc

View File

@ -388,6 +388,7 @@ conf:
shipyard: shipyard:
base: base:
web_server: web_server:
profiler: false
shipyard: shipyard:
service_type: shipyard service_type: shipyard
deckhand: deckhand:

View File

@ -68,6 +68,9 @@
# The directory containing the alembic.ini file (string value) # The directory containing the alembic.ini file (string value)
#alembic_ini_path = /home/shipyard/shipyard #alembic_ini_path = /home/shipyard/shipyard
# Enable profiling of API requests. Do NOT use in production. (boolean value)
#profiler = false
[deckhand] [deckhand]
@ -315,6 +318,12 @@
# Timeout value for http requests (integer value) # Timeout value for http requests (integer value)
#timeout = <None> #timeout = <None>
# Collect per-API call timing information. (boolean value)
#collect_timing = false
# Log requests to multiple loggers. (boolean value)
#split_loggers = false
[logging] [logging]

View File

@ -35,6 +35,9 @@ SQLAlchemy==1.2.12
ulid==1.1 ulid==1.1
uwsgi==2.0.17 uwsgi==2.0.17
# To support profiling in non-prod
Werkzeug==0.14.1
# Dependencies for other UCP components # Dependencies for other UCP components
git+https://git.openstack.org/openstack/airship-deckhand@0b5aa2e98a1ab5ab8a58c9dec3c1f88ef00d17a9#egg=deckhand git+https://git.openstack.org/openstack/airship-deckhand@0b5aa2e98a1ab5ab8a58c9dec3c1f88ef00d17a9#egg=deckhand
git+https://git.openstack.org/openstack/airship-drydock.git@b1d24ad254c04cdbb4dc4e06f2bfe92c266aad70#egg=drydock_provisioner&subdirectory=python git+https://git.openstack.org/openstack/airship-drydock.git@b1d24ad254c04cdbb4dc4e06f2bfe92c266aad70#egg=drydock_provisioner&subdirectory=python

View File

@ -91,6 +91,12 @@ SECTIONS = [
default='/home/shipyard/shipyard', default='/home/shipyard/shipyard',
help='The directory containing the alembic.ini file' help='The directory containing the alembic.ini file'
), ),
cfg.BoolOpt(
'profiler',
default=False,
help=('Enable profiling of API requests. Do NOT '
'use in production.')
),
] ]
), ),
ConfigSection( ConfigSection(

View File

@ -16,7 +16,10 @@
Sets up the global configurations for the Shipyard service. Hands off Sets up the global configurations for the Shipyard service. Hands off
to the api startup to handle the Falcon specific setup. to the api startup to handle the Falcon specific setup.
""" """
import logging
from oslo_config import cfg from oslo_config import cfg
from werkzeug.contrib.profiler import ProfilerMiddleware
from shipyard_airflow.conf import config from shipyard_airflow.conf import config
import shipyard_airflow.control.api as api import shipyard_airflow.control.api as api
@ -24,6 +27,7 @@ from shipyard_airflow.control.logging.logging_config import LoggingConfig
from shipyard_airflow import policy from shipyard_airflow import policy
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def start_shipyard(default_config_files=None): def start_shipyard(default_config_files=None):
@ -40,4 +44,11 @@ def start_shipyard(default_config_files=None):
policy.policy_engine.register_policy() policy.policy_engine.register_policy()
# Start the API # Start the API
return api.start_api() if CONF.base.profiler:
LOG.warning("Profiler ENABLED. Expect significant "
"performance overhead.")
return ProfilerMiddleware(
api.start_api(),
profile_dir="/tmp/profiles") # nosec
else:
return api.start_api()