Merge "Enable uWSGI support in devstack"

This commit is contained in:
Zuul 2018-06-15 09:26:56 +00:00 committed by Gerrit Code Review
commit ddbc1c4efb
8 changed files with 107 additions and 5 deletions

View File

@ -143,6 +143,17 @@ enforce it in following way:
APACHE_MIRROR=http://www-us.apache.org/dist/
```
## Using WSGI
Monasca-api can be deployed with Apache using uwsgi and gunicorn.
By default monasca-api runs under uwsgi.
If you wish to use gunicorn make sure that ```devstack/local.conf```
contains:
```sh
MONASCA_API_USE_MOD_WSGI=False
```
# License
(c) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP

View File

@ -156,6 +156,8 @@ MONASCA_PERSISTER_IMPLEMENTATION_LANG=${MONASCA_PERSISTER_IMPLEMENTATION_LANG:-p
# MONASCA_METRICS_DB=${MONASCA_METRICS_DB:-cassandra}
MONASCA_METRICS_DB=${MONASCA_METRICS_DB:-influxdb}
MONASCA_API_USE_MOD_WSGI=${MONASCA_API_USE_MOD_WSGI:-True}
# Uncomment one of the following lines and modify accordingly to enable the Monasca DevStack Plugin
enable_plugin monasca-api https://git.openstack.org/openstack/monasca-api
# enable_plugin monasca-api file:///vagrant_home/Documents/repos/openstack/monasca-api.vertica

View File

@ -0,0 +1,18 @@
Listen %PUBLICPORT%
<VirtualHost *:%PUBLICPORT%>
WSGIDaemonProcess monasca-api user=%USER% processes=%APIWORKERS% threads=1 display-name=%{GROUP} %VIRTUALENV%
WSGIProcessGroup monasca-api
WSGIScriptAlias / %PUBLICWSGI%/wsgi.py
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
LogLevel info
ErrorLog /var/log/%APACHE_NAME%/monasca-api.log
CustomLog /var/log/%APACHE_NAME%/monasca-api_access.log combined
SetEnv no-gzip 1
AddDefaultCharset utf-8
</VirtualHost>

View File

@ -93,7 +93,12 @@ if [[ ${USE_VENV} = True ]]; then
else
MONASCA_API_BIN_DIR=$(get_python_exec_prefix)
fi
MONASCA_API_BASE_URI=${MONASCA_API_SERVICE_PROTOCOL}://${MONASCA_API_SERVICE_HOST}:${MONASCA_API_SERVICE_PORT}
if [[ "${MONASCA_API_USE_MOD_WSGI}" == 'True' && "${MONASCA_API_IMPLEMENTATION_LANG}" == "python" ]]; then
MONASCA_API_BASE_URI=${MONASCA_API_SERVICE_PROTOCOL}://${MONASCA_API_SERVICE_HOST}/metrics
else
MONASCA_API_BASE_URI=${MONASCA_API_SERVICE_PROTOCOL}://${MONASCA_API_SERVICE_HOST}:${MONASCA_API_SERVICE_PORT}
fi
MONASCA_API_URI_V2=${MONASCA_API_BASE_URI}/v2.0
# Files inside this directory will be visible in gates log
@ -759,9 +764,14 @@ function install_monasca-api {
git_clone $MONASCA_API_REPO $MONASCA_API_DIR $MONASCA_API_BRANCH
setup_develop $MONASCA_API_DIR
pip_install_gr gunicorn
install_monasca_common
if [[ "${MONASCA_API_USE_MOD_WSGI}" == 'True' ]]; then
pip_install uwsgi
else
pip_install_gr gunicorn
fi
if [[ "${MONASCA_METRICS_DB,,}" == 'influxdb' ]]; then
pip_install_gr influxdb
fi
@ -854,9 +864,20 @@ function configure_monasca_api_python {
ln -sf $MONASCA_API_PASTE_INI $MON_API_GATE_CONFIGURATION_DIR
ln -sf $MONASCA_API_LOGGING_CONF $MON_API_GATE_CONFIGURATION_DIR
if [ "${MONASCA_API_USE_MOD_WSGI}" == 'True' ]; then
configure_monasca_api_python_uwsgi
fi
fi
}
function configure_monasca_api_python_uwsgi {
rm -rf $MONASCA_API_UWSGI_CONF
install -m 600 $MONASCA_API_DIR/etc/api-uwsgi.ini $MONASCA_API_UWSGI_CONF
write_uwsgi_config "$MONASCA_API_UWSGI_CONF" "$MONASCA_API_BIN_DIR/monasca-api-wsgi" "/metrics"
}
function start_monasca_api_python {
if is_service_enabled monasca-api; then
echo_summary "Starting monasca-api"
@ -866,10 +887,16 @@ function start_monasca_api_python {
local gunicorn="$MONASCA_API_BIN_DIR/gunicorn"
restart_service memcached
run_process "monasca-api" "$gunicorn --paste $MONASCA_API_PASTE_INI"
if [ "${MONASCA_API_USE_MOD_WSGI}" == 'True' ]; then
service_uri=$service_protocol://$MONASCA_API_SERVICE_HOST/api/v2.0
run_process "monasca-api" "$MONASCA_API_BIN_DIR/uwsgi --ini $MONASCA_API_UWSGI_CONF" ""
else
service_uri=$service_protocol://$MONASCA_API_SERVICE_HOST:$service_port
run_process "monasca-api" "$gunicorn --paste $MONASCA_API_PASTE_INI"
fi
echo "Waiting for monasca-api to start..."
if ! wait_for_service $SERVICE_TIMEOUT $service_protocol://$SERVICE_HOST:$service_port; then
if ! wait_for_service $SERVICE_TIMEOUT $service_uri; then
die $LINENO "monasca-api did not start"
fi
fi
@ -918,6 +945,14 @@ function clean_monasca_api_python {
apt_get -y purge libmysqlclient-dev
fi
if [ "$MONASCA_API_USE_MOD_WSGI" == "True" ]; then
clean_monasca_api_uwsgi
fi
}
function clean_monasca_api_uwsgi {
sudo rm -rf $MONASCA_API_UWSGI_CONF
}
function start_monasca_api {

View File

@ -190,6 +190,9 @@ MONASCA_API_CONF=${MONASCA_API_CONF:-$MONASCA_API_CONF_DIR/api-config.conf}
MONASCA_API_PASTE_INI=${MONASCA_API_PASTE_INI:-$MONASCA_API_CONF_DIR/api-config.ini}
MONASCA_API_LOGGING_CONF=${MONASCA_API_LOGGING_CONF:-$MONASCA_API_CONF_DIR/api-logging.conf}
MONASCA_API_LOG_DIR=${MONASCA_API_LOG_DIR:-/var/log/monasca/api}
MONASCA_API_USE_MOD_WSGI=${MONASCA_API_USE_MOD_WSGI:-$ENABLE_HTTPD_MOD_WSGI_SERVICES}
MONASCA_API_UWSGI_CONF=${MONASCA_API_UWSGI_CONF:-$MONASCA_API_CONF_DIR/api-uwsgi.ini}
## storm settings
STORM_UI_HOST=${STORM_UI_HOST:-${SERVICE_HOST}}

25
etc/api-uwsgi.ini Normal file
View File

@ -0,0 +1,25 @@
[uwsgi]
wsgi-file = /usr/local/bin/monasca-api-wsgi
# Versions of mod_proxy_uwsgi>=2.0.6 should use a UNIX socket, see
# http://uwsgi-docs.readthedocs.org/en/latest/Apache.html#mod-proxy-uwsgi
uwsgi-socket = 127.0.0.1:8070
# Override the default size for headers from the 4k default.
buffer-size = 65535
# This is running standalone
master = true
enable-threads = true
# Tune this to your environment.
processes = 4
# uwsgi recommends this to prevent thundering herd on accept.
thunder-lock = true
plugins = python
# This ensures that file descriptors aren't shared between keystone processes.
lazy-apps = true

View File

@ -17,4 +17,9 @@
from monasca_api.api import server
application = server.get_wsgi_app(config_base_path='/etc/monasca')
def main():
return server.get_wsgi_app(config_base_path='/etc/monasca')
if __name__ == '__main__':
application = main()

View File

@ -36,6 +36,9 @@ cassandra =
console_scripts =
monasca-api = monasca_api.api.server:launch
wsgi_scripts =
monasca-api-wsgi = monasca_api.api.wsgi:main
oslo.config.opts =
monasca_api = monasca_api.conf:list_opts