From 54224ea98d6dfcbe9bdede6bd2b996818a50c827 Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Wed, 3 Oct 2018 22:25:15 +0000 Subject: [PATCH] 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 --- charts/shipyard/templates/deployment-shipyard.yaml | 8 ++++++++ charts/shipyard/values.yaml | 1 + .../etc/shipyard/shipyard.conf.sample | 9 +++++++++ src/bin/shipyard_airflow/requirements.txt | 3 +++ .../shipyard_airflow/conf/config.py | 6 ++++++ .../shipyard_airflow/control/start_shipyard.py | 13 ++++++++++++- 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/charts/shipyard/templates/deployment-shipyard.yaml b/charts/shipyard/templates/deployment-shipyard.yaml index b459c04f..2d2700c3 100644 --- a/charts/shipyard/templates/deployment-shipyard.yaml +++ b/charts/shipyard/templates/deployment-shipyard.yaml @@ -84,8 +84,16 @@ spec: subPath: policy.yaml mountPath: /etc/shipyard/policy.yaml 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 }} volumes: +{{ if .Values.conf.shipyard.base.profiler }} + - name: tmp-profiles + emptyDir: {} +{{ end }} - name: etc-shipyard emptyDir: {} - name: shipyard-etc diff --git a/charts/shipyard/values.yaml b/charts/shipyard/values.yaml index b97b00a5..d7bd2c28 100644 --- a/charts/shipyard/values.yaml +++ b/charts/shipyard/values.yaml @@ -388,6 +388,7 @@ conf: shipyard: base: web_server: + profiler: false shipyard: service_type: shipyard deckhand: diff --git a/src/bin/shipyard_airflow/etc/shipyard/shipyard.conf.sample b/src/bin/shipyard_airflow/etc/shipyard/shipyard.conf.sample index eac4bfc3..a6e3ba13 100644 --- a/src/bin/shipyard_airflow/etc/shipyard/shipyard.conf.sample +++ b/src/bin/shipyard_airflow/etc/shipyard/shipyard.conf.sample @@ -68,6 +68,9 @@ # The directory containing the alembic.ini file (string value) #alembic_ini_path = /home/shipyard/shipyard +# Enable profiling of API requests. Do NOT use in production. (boolean value) +#profiler = false + [deckhand] @@ -315,6 +318,12 @@ # Timeout value for http requests (integer value) #timeout = +# Collect per-API call timing information. (boolean value) +#collect_timing = false + +# Log requests to multiple loggers. (boolean value) +#split_loggers = false + [logging] diff --git a/src/bin/shipyard_airflow/requirements.txt b/src/bin/shipyard_airflow/requirements.txt index 0d108909..1b26182e 100644 --- a/src/bin/shipyard_airflow/requirements.txt +++ b/src/bin/shipyard_airflow/requirements.txt @@ -35,6 +35,9 @@ SQLAlchemy==1.2.12 ulid==1.1 uwsgi==2.0.17 +# To support profiling in non-prod +Werkzeug==0.14.1 + # Dependencies for other UCP components 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 diff --git a/src/bin/shipyard_airflow/shipyard_airflow/conf/config.py b/src/bin/shipyard_airflow/shipyard_airflow/conf/config.py index 33092545..c3450739 100644 --- a/src/bin/shipyard_airflow/shipyard_airflow/conf/config.py +++ b/src/bin/shipyard_airflow/shipyard_airflow/conf/config.py @@ -91,6 +91,12 @@ SECTIONS = [ default='/home/shipyard/shipyard', 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( diff --git a/src/bin/shipyard_airflow/shipyard_airflow/control/start_shipyard.py b/src/bin/shipyard_airflow/shipyard_airflow/control/start_shipyard.py index 0cd9cb32..c167a95b 100644 --- a/src/bin/shipyard_airflow/shipyard_airflow/control/start_shipyard.py +++ b/src/bin/shipyard_airflow/shipyard_airflow/control/start_shipyard.py @@ -16,7 +16,10 @@ Sets up the global configurations for the Shipyard service. Hands off to the api startup to handle the Falcon specific setup. """ +import logging + from oslo_config import cfg +from werkzeug.contrib.profiler import ProfilerMiddleware from shipyard_airflow.conf import config 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 CONF = cfg.CONF +LOG = logging.getLogger(__name__) def start_shipyard(default_config_files=None): @@ -40,4 +44,11 @@ def start_shipyard(default_config_files=None): policy.policy_engine.register_policy() # 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()