Update /v2/alarms/count api endpoint

* Brings alarms count endpoint to parity with the alarms list endpoint
* Brings alarms count endpoint to parity with the alarms counnt endpoint
  in the depricated java api
* Allow metric_dimensions filter to filter on multiple dimension values:
  metric_dimensions=dns|compute|nova

Change-Id: I46ca0e6a6da46cb850af44768de237e41a43484a
Story: 2005311
Task: 30216
This commit is contained in:
Ethan Apodaca 2019-03-27 13:20:58 -07:00
parent 8437530b87
commit 1d3efdb215
No known key found for this signature in database
GPG Key ID: D33C693B9B3921E1
3 changed files with 26 additions and 5 deletions

View File

@ -2873,7 +2873,7 @@ None
#### Query Parameters
* alarm_definition_id (string, optional) - Alarm definition ID to filter by.
* metric_name (string(255), optional) - Name of metric to filter by.
* metric_dimensions ({string(255): string(255)}, optional) - Dimensions of metrics to filter by specified as a comma separated array of (key, value) pairs as `key1:value1,key1:value1,...`
* metric_dimensions ({string(255): string(255)}, optional) - One or more dimensions of metrics to filter by specified as a comma separated array of (key, value or multiple values sperated by `|`) pairs as `key1:value1,key2:value2,key3:value3|value4,...`
* state (string, optional) - State of alarm to filter by, either `OK`, `ALARM` or `UNDETERMINED`.
* severity (string, optional) - One or more severities to filter by, separated with `|`, ex. `severity=LOW|MEDIUM`.
* lifecycle_state (string(50), optional) - Lifecycle state to filter by.

View File

@ -548,12 +548,26 @@ class AlarmsRepository(sql_repository.SQLRepository,
sub_query_md_base = select([md.c.dimension_set_id]).select_from(md)
for i, metric_dimension in enumerate(query_parms['metric_dimensions'].items()):
dimension_value = metric_dimension[1] if six.PY3 else \
metric_dimension[1].encode('utf8')
if '|' in dimension_value:
dimension_value = tuple(dimension_value.split('|'))
md_name = "b_md_name_{}".format(i)
md_value = "b_md_value_{}".format(i)
sub_query_md = (sub_query_md_base
.where(md.c.name == bindparam(md_name))
.where(md.c.value == bindparam(md_value))
.where(md.c.name == bindparam(md_name)))
if isinstance(dimension_value, tuple):
sub_query_md = (sub_query_md
.where(md.c.value.op('IN')(bindparam(md_value))))
else:
sub_query_md = (sub_query_md
.where(md.c.value == bindparam(md_value)))
sub_query_md = (sub_query_md
.distinct()
.alias('md_{}'.format(i)))
@ -564,8 +578,7 @@ class AlarmsRepository(sql_repository.SQLRepository,
parms[md_name] = metric_dimension[0] if six.PY3 else \
metric_dimension[0].encode('utf8')
parms[md_value] = metric_dimension[1] if six.PY3 else \
metric_dimension[1].encode('utf8')
parms[md_value] = dimension_value
sub_query = (sub_query
.select_from(sub_query_from)

View File

@ -0,0 +1,8 @@
---
features:
- |
Allow metric_dimensions filter to filter on multiple dimension values,
on alarms count endpoint (IE metric_dimension=hostname:host1|host2).
This brings the query parameters into parity between the alarms list
and alarms count endpoints. This also restores functionality that was
available on the deprecated java api.