Allow Keystone config in init_config for http check

Now the user will be able to configure one, default Keystone for all
services in `http_check.yml` instead of providing them one by one for
every instance.

Setting Keystone config in every instance is marked as depreciated.

Story: 2001843
Task: 12610

Change-Id: If52b52efab6cc14a7df583b1dc2596b04e6813bc
This commit is contained in:
Dobroslaw Zybort 2018-04-09 12:56:05 +02:00
parent bd42ecb1c3
commit e13de8083e
3 changed files with 45 additions and 19 deletions

View File

@ -1,6 +1,16 @@
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
init_config:
# If your service uses keystone for authentication, you can optionally
# specify the information to collect a token to be used in the check.
# This information should follow the same guidelines presented in
# agent.yaml.template
# https://github.com/openstack/monasca-agent/blob/master/agent.yaml.template
# keystone_config:
# keystone_url: http://endpoint.com/v3/
# project_name: project
# username: user
# password: password
instances:
# - name: Some Service Name
@ -12,19 +22,10 @@ instances:
# username: user
# password: pass
# If your service uses keystone for authentication, you can optionally
# specify the information to collect a token to be used in the check.
# This information should follow the same guidelines presented in
# agent.yaml.template
# https://github.com/openstack/monasca-agent/blob/master/agent.yaml.template
# If use_keystone=True and keystone_config is not specified, the keystone information
# If use_keystone=True then Keystone information from `init_config`
# will be used, and if it's not there then Keystone configuration
# from the agent config will be used.
# use_keystone: True
# keystone_config:
# keystone_url: http://endpoint.com/v3/
# project_name: project
# username: user
# password: password
# The (optional) match_pattern parameter will instruct the check
# to match the HTTP response body against a regular-expression-

View File

@ -1330,20 +1330,38 @@ This section describes the http endpoint check that can be performed by the Agen
The Agent supports additional functionality through the use of Python scripts. A YAML file (http_check.yaml) contains the list of URLs to check (among other optional parameters). A Python script (http_check.py) runs checks each host in turn, returning a 0 on success and a 1 on failure in the result sent through the Forwarder and on the Monitoring API.
Similar to other checks, the configuration is done in YAML, and consists of two keys: init_config and instances. The former is not used by http_check, while the later contains one or more URLs to check, plus optional parameters like a timeout, username/password, pattern to match against the HTTP response body, whether or not to include the HTTP response in the metric (as a 'detail' dimension), whether or not to also record the response time, and more.
If the endpoint being checked requires authentication, there are two options. First, a username and password supplied in the instance options will be used by the check for authentication. Alternately, the check can retrieve a keystone token for authentication. Specific keystone information can be provided for each check, otherwise the information from the agent config will be used.
Similar to other checks, the configuration is done in YAML, and consists of two
keys: `init_config` and `instances`. In the former, you can provide Keystone
configuration for checks to retrieve token for authentication that will be used
for all checks. While the later contains one or more URLs to check, plus
optional parameters like a timeout, username/password, pattern to match against
the HTTP response body, whether or not to include the HTTP response
in the metric (as a 'detail' dimension), whether or not to also record
the response time, and more.
If the endpoint being checked requires authentication, there are two options.
First, a username and password supplied in the instance options will be used
by the check for authentication. Alternately, the check can retrieve
a keystone token for authentication. Specific keystone information can
be provided for all checks in `init_config` section, or if it's not
provided there, the information from the agent config will be used.
DEPRECATED: providing Keystone configuration in each instance.
Sample config:
```
init_config:
keystone_config:
keystone_url: http://endpoint.com/v3/
project_name: project
username: user
password: password
instances:
url: http://192.168.0.254/healthcheck
timeout: 1
include_content: true
collect_response_time: true
match_pattern: '.*OK.*OK.*OK.*OK.*OK'
url: http://192.168.0.254/healthcheck
timeout: 1
include_content: true
collect_response_time: true
match_pattern: '.*OK.*OK.*OK.*OK.*OK'
```
The http_status checks return the following metrics:

View File

@ -33,6 +33,9 @@ class HTTPCheck(services_checks.ServicesCheck):
# init the keystone client if instance has use_keystone
self._api_config = cfg.Config().get_config('Api')
self._ksclients = {}
init_keystone_config = init_config.get('keystone_config', None)
for instance in instances:
addr, username, password, timeout, headers, response_time, \
disable_ssl_validation, use_keystone, keystone_config, \
@ -40,7 +43,11 @@ class HTTPCheck(services_checks.ServicesCheck):
if use_keystone:
# keystone is a singleton. It will be initialized once,
# the first config instance used.
if keystone_config:
if init_keystone_config:
ksclient = keystone.Keystone(init_keystone_config)
elif keystone_config:
# Using Keystone config in each instance is deprecated
# in Rocky.
ksclient = keystone.Keystone(keystone_config)
else:
ksclient = keystone.Keystone(self._api_config)