Merge "Add support of paging in live query"
This commit is contained in:
commit
06a3aee531
surveil
api
tests/api/controllers/v2/status
@ -18,6 +18,7 @@ import wsme
|
|||||||
import wsme.types as wtypes
|
import wsme.types as wtypes
|
||||||
|
|
||||||
from surveil.api.datamodel.status.metrics import time_interval
|
from surveil.api.datamodel.status.metrics import time_interval
|
||||||
|
from surveil.api.datamodel.status import paging
|
||||||
from surveil.api.datamodel import types
|
from surveil.api.datamodel import types
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ class LiveQuery(types.Base):
|
|||||||
time_interval = wsme.wsattr(time_interval.TimeInterval, mandatory=False)
|
time_interval = wsme.wsattr(time_interval.TimeInterval, mandatory=False)
|
||||||
"Time interval of the query."
|
"Time interval of the query."
|
||||||
|
|
||||||
|
paging = wsme.wsattr(paging.Paging, mandatory=False)
|
||||||
|
"Paging."
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(
|
return cls(
|
||||||
@ -41,6 +45,10 @@ class LiveQuery(types.Base):
|
|||||||
start_time='2015-01-29T21:50:44Z',
|
start_time='2015-01-29T21:50:44Z',
|
||||||
end_time='2015-01-29T22:50:44Z'
|
end_time='2015-01-29T22:50:44Z'
|
||||||
),
|
),
|
||||||
|
paging=paging.Paging(
|
||||||
|
page=3,
|
||||||
|
size=100
|
||||||
|
),
|
||||||
filters=json.dumps({
|
filters=json.dumps({
|
||||||
"isnot": {
|
"isnot": {
|
||||||
"state": ["0", "1"],
|
"state": ["0", "1"],
|
||||||
|
33
surveil/api/datamodel/status/paging.py
Normal file
33
surveil/api/datamodel/status/paging.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Copyright 2015 - Savoir-Faire Linux inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import wsme
|
||||||
|
|
||||||
|
from surveil.api.datamodel import types
|
||||||
|
|
||||||
|
|
||||||
|
class Paging(types.Base):
|
||||||
|
|
||||||
|
size = wsme.wsattr(int, mandatory=False)
|
||||||
|
"""Size of the result."""
|
||||||
|
|
||||||
|
page = wsme.wsattr(int, mandatory=False)
|
||||||
|
"""Page number."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def sample(cls):
|
||||||
|
return cls(
|
||||||
|
page=1,
|
||||||
|
size=100
|
||||||
|
)
|
@ -26,11 +26,15 @@ def build_influxdb_query(live_query,
|
|||||||
|
|
||||||
filters = {}
|
filters = {}
|
||||||
time = None
|
time = None
|
||||||
|
offset = None
|
||||||
if live_query:
|
if live_query:
|
||||||
if live_query.filters:
|
if live_query.filters:
|
||||||
filters.update(json.loads(live_query.filters))
|
filters.update(json.loads(live_query.filters))
|
||||||
if live_query.time_interval:
|
if live_query.time_interval:
|
||||||
time = live_query.time_interval
|
time = live_query.time_interval
|
||||||
|
if live_query.paging:
|
||||||
|
limit = live_query.paging.size
|
||||||
|
offset = limit * live_query.paging.page
|
||||||
|
|
||||||
filters.update(additional_filters)
|
filters.update(additional_filters)
|
||||||
query += _build_where_clause(filters, time)
|
query += _build_where_clause(filters, time)
|
||||||
@ -46,6 +50,9 @@ def build_influxdb_query(live_query,
|
|||||||
if limit is not None:
|
if limit is not None:
|
||||||
query.append('LIMIT %d' % limit)
|
query.append('LIMIT %d' % limit)
|
||||||
|
|
||||||
|
if offset is not None:
|
||||||
|
query.append('OFFSET %d' % offset)
|
||||||
|
|
||||||
return ' '.join(query)
|
return ' '.join(query)
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,6 +198,10 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
'time_interval': {
|
'time_interval': {
|
||||||
'start_time': '2015-04-19T00:09:24Z',
|
'start_time': '2015-04-19T00:09:24Z',
|
||||||
'end_time': '2015-04-19T02:09:25Z'
|
'end_time': '2015-04-19T02:09:25Z'
|
||||||
|
},
|
||||||
|
'paging': {
|
||||||
|
'size': 10,
|
||||||
|
'page': 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +229,8 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
"and time <= '2015-04-19t02:09:25z' "
|
"and time <= '2015-04-19t02:09:25z' "
|
||||||
"and host_name='srv-monitoring-01' "
|
"and host_name='srv-monitoring-01' "
|
||||||
"and service_description='load' "
|
"and service_description='load' "
|
||||||
"order by time desc"
|
"order by time desc "
|
||||||
|
"limit 10 offset 30"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.assert_count_equal_backport(
|
self.assert_count_equal_backport(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user