rest: Extends metric list filters
Change-Id: I821c2d1a8c4cf0a217e72d95d8373f274024f9e0
This commit is contained in:
parent
0986bc24ed
commit
dd0a877361
|
@ -167,9 +167,9 @@ METRIC_DEFAULT_PAGINATION = ['id:asc']
|
|||
|
||||
def get_pagination_options(params, default):
|
||||
max_limit = pecan.request.conf.api.max_limit
|
||||
limit = params.get('limit', max_limit)
|
||||
marker = params.get('marker')
|
||||
sorts = params.get('sort', default)
|
||||
limit = params.pop('limit', max_limit)
|
||||
marker = params.pop('marker', None)
|
||||
sorts = params.pop('sort', default)
|
||||
if not isinstance(sorts, list):
|
||||
sorts = [sorts]
|
||||
|
||||
|
@ -536,14 +536,30 @@ class MetricsController(rest.RestController):
|
|||
pecan.response.status = 201
|
||||
return m
|
||||
|
||||
@staticmethod
|
||||
MetricListSchema = voluptuous.Schema({
|
||||
"user_id": six.text_type,
|
||||
"project_id": six.text_type,
|
||||
"creator": six.text_type,
|
||||
"limit": six.text_type,
|
||||
"name": six.text_type,
|
||||
"id": six.text_type,
|
||||
"unit": six.text_type,
|
||||
"archive_policy_name": six.text_type,
|
||||
"status": voluptuous.Any("active", "delete"),
|
||||
"sort": voluptuous.Any([six.text_type], six.text_type),
|
||||
"marker": six.text_type,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@pecan.expose('json')
|
||||
def get_all(**kwargs):
|
||||
def get_all(cls, **kwargs):
|
||||
kwargs = cls.MetricListSchema(kwargs)
|
||||
|
||||
# Compat with old user/project API
|
||||
provided_user_id = kwargs.get('user_id')
|
||||
provided_project_id = kwargs.get('project_id')
|
||||
provided_user_id = kwargs.pop('user_id', None)
|
||||
provided_project_id = kwargs.pop('project_id', None)
|
||||
if provided_user_id is None and provided_project_id is None:
|
||||
provided_creator = kwargs.get('creator')
|
||||
provided_creator = kwargs.pop('creator', None)
|
||||
else:
|
||||
provided_creator = (
|
||||
(provided_user_id or "")
|
||||
|
@ -563,6 +579,7 @@ class MetricsController(rest.RestController):
|
|||
attr_filter['creator'] = provided_creator
|
||||
attr_filter.update(get_pagination_options(
|
||||
kwargs, METRIC_DEFAULT_PAGINATION))
|
||||
attr_filter.update(kwargs)
|
||||
try:
|
||||
return pecan.request.indexer.list_metrics(**attr_filter)
|
||||
except indexer.IndexerException as e:
|
||||
|
|
|
@ -97,6 +97,40 @@ tests:
|
|||
response_json_paths:
|
||||
$.`len`: 4
|
||||
|
||||
- name: list metrics by id
|
||||
GET: /v1/metric?id=$HISTORY['create metric 1'].$RESPONSE['id']
|
||||
response_json_paths:
|
||||
$.`len`: 1
|
||||
$[0].name: disk.io.rate
|
||||
$[0].archive_policy.name: first_archive
|
||||
|
||||
- name: list metrics by name
|
||||
GET: /v1/metric?name=disk.io.rate
|
||||
response_json_paths:
|
||||
$.`len`: 2
|
||||
$[0].name: disk.io.rate
|
||||
$[1].name: disk.io.rate
|
||||
$[0].archive_policy.name: first_archive
|
||||
$[1].archive_policy.name: first_archive
|
||||
|
||||
- name: list metrics by unit
|
||||
GET: /v1/metric?unit=ns
|
||||
response_json_paths:
|
||||
$.`len`: 1
|
||||
$[0].name: cpu
|
||||
$[0].archive_policy.name: second_archive
|
||||
|
||||
- name: list metrics by archive_policy
|
||||
GET: /v1/metric?archive_policy_name=first_archive&sort=name:desc
|
||||
response_json_paths:
|
||||
$.`len`: 3
|
||||
$[0].name: disk.io.rate
|
||||
$[1].name: disk.io.rate
|
||||
$[2].name: cpu_util
|
||||
$[0].archive_policy.name: first_archive
|
||||
$[1].archive_policy.name: first_archive
|
||||
$[2].archive_policy.name: first_archive
|
||||
|
||||
- name: list metrics by user_id
|
||||
GET: /v1/metric?user_id=faf30294217c4e1a91387d9c8f1fb1fb
|
||||
response_json_paths:
|
||||
|
|
Loading…
Reference in New Issue