Merge "Statistics groupby handling improvement"
This commit is contained in:
@@ -179,6 +179,26 @@ class StatisticsManagerTest(utils.BaseTestCase):
|
||||
self.assertEqual(stats[0].groupby.get('resource_id'), 'foo')
|
||||
self.assertEqual(stats[1].groupby.get('resource_id'), 'bar')
|
||||
|
||||
def test_list_by_meter_name_with_groupby_as_str(self):
|
||||
stats = list(self.mgr.list(meter_name='instance',
|
||||
q=[
|
||||
{"field": "resource_id",
|
||||
"value": "foo"},
|
||||
{"field": "source",
|
||||
"value": "bar"},
|
||||
],
|
||||
groupby='resource_id'))
|
||||
expect = [
|
||||
('GET',
|
||||
'%s?%s%s' % (base_url, qry, groupby), {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(stats))
|
||||
self.assertEqual(135, stats[0].count)
|
||||
self.assertEqual(12, stats[1].count)
|
||||
self.assertEqual('foo', stats[0].groupby.get('resource_id'))
|
||||
self.assertEqual('bar', stats[1].groupby.get('resource_id'))
|
||||
|
||||
def test_list_by_meter_name_with_aggregates(self):
|
||||
aggregates = [
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from ceilometerclient.common import base
|
||||
from ceilometerclient.v2 import options
|
||||
|
||||
@@ -43,6 +45,8 @@ class StatisticsManager(base.Manager):
|
||||
|
||||
def list(self, meter_name, q=None, period=None, groupby=[], aggregates=[]):
|
||||
p = ['period=%s' % period] if period else []
|
||||
if isinstance(groupby, six.string_types):
|
||||
groupby = [groupby]
|
||||
p.extend(['groupby=%s' % g for g in groupby] if groupby else [])
|
||||
p.extend(self._build_aggregates(aggregates))
|
||||
return self._list(options.build_url(
|
||||
|
||||
Reference in New Issue
Block a user