Add support of paging in live query
Change-Id: Ib2262db65d68188559da237dc451a1bd562392c5
This commit is contained in:
parent
1cb311b96a
commit
21a5a24714
@ -18,6 +18,7 @@ import wsme
|
||||
import wsme.types as wtypes
|
||||
|
||||
from surveil.api.datamodel.status.metrics import time_interval
|
||||
from surveil.api.datamodel.status import paging
|
||||
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 of the query."
|
||||
|
||||
paging = wsme.wsattr(paging.Paging, mandatory=False)
|
||||
"Paging."
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
return cls(
|
||||
@ -41,6 +45,10 @@ class LiveQuery(types.Base):
|
||||
start_time='2015-01-29T21:50:44Z',
|
||||
end_time='2015-01-29T22:50:44Z'
|
||||
),
|
||||
paging=paging.Paging(
|
||||
page=3,
|
||||
size=100
|
||||
),
|
||||
filters=json.dumps({
|
||||
"isnot": {
|
||||
"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 = {}
|
||||
time = None
|
||||
offset = None
|
||||
if live_query:
|
||||
if live_query.filters:
|
||||
filters.update(json.loads(live_query.filters))
|
||||
if 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)
|
||||
query += _build_where_clause(filters, time)
|
||||
@ -46,6 +50,9 @@ def build_influxdb_query(live_query,
|
||||
if limit is not None:
|
||||
query.append('LIMIT %d' % limit)
|
||||
|
||||
if offset is not None:
|
||||
query.append('OFFSET %d' % offset)
|
||||
|
||||
return ' '.join(query)
|
||||
|
||||
|
||||
|
@ -198,6 +198,10 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
'time_interval': {
|
||||
'start_time': '2015-04-19T00:09:24Z',
|
||||
'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 host_name='srv-monitoring-01' "
|
||||
"and service_description='load' "
|
||||
"order by time desc"
|
||||
"order by time desc "
|
||||
"limit 10 offset 30"
|
||||
]
|
||||
)
|
||||
self.assert_count_equal_backport(
|
||||
|
Loading…
x
Reference in New Issue
Block a user