Merge "Aggregate by label when querying instance cpu usage in prometheus"
This commit is contained in:
@@ -342,10 +342,12 @@ class PrometheusHelper(base.DataSourceBase):
|
|||||||
)
|
)
|
||||||
vcpus = 1
|
vcpus = 1
|
||||||
query_args = (
|
query_args = (
|
||||||
"clamp_max((%s by (instance)(rate(%s{%s='%s'}[%ss]))/10e+8) "
|
"clamp_max((%(agg)s by (%(label)s)"
|
||||||
"*(100/%s), 100)" %
|
"(rate(%(meter)s{%(label)s='%(label_value)s'}[%(period)ss]))"
|
||||||
(aggregate, meter, uuid_label_key, instance_label, period,
|
"/10e+8) *(100/%(vcpus)s), 100)"
|
||||||
vcpus)
|
% {'label': uuid_label_key, 'label_value': instance_label,
|
||||||
|
'agg': aggregate, 'meter': meter, 'period': period,
|
||||||
|
'vcpus': vcpus}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise exception.InvalidParameter(
|
raise exception.InvalidParameter(
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ class TestPrometheusHelper(base.BaseTestCase):
|
|||||||
self.assertEqual(expected_cpu_usage, result_cpu)
|
self.assertEqual(expected_cpu_usage, result_cpu)
|
||||||
self.assertIsInstance(result_cpu, float)
|
self.assertIsInstance(result_cpu, float)
|
||||||
mock_prometheus_query.assert_called_once_with(
|
mock_prometheus_query.assert_called_once_with(
|
||||||
"clamp_max((avg by (instance)(rate("
|
"clamp_max((avg by (resource)(rate("
|
||||||
"ceilometer_cpu{resource='uuid-0'}[300s]))"
|
"ceilometer_cpu{resource='uuid-0'}[300s]))"
|
||||||
"/10e+8) *(100/2), 100)"
|
"/10e+8) *(100/2), 100)"
|
||||||
)
|
)
|
||||||
@@ -644,7 +644,7 @@ class TestPrometheusHelper(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_build_prometheus_query_instance_cpu_avg_agg(self):
|
def test_build_prometheus_query_instance_cpu_avg_agg(self):
|
||||||
expected_query = (
|
expected_query = (
|
||||||
"clamp_max((avg by (instance)(rate("
|
"clamp_max((avg by (resource)(rate("
|
||||||
"ceilometer_cpu{resource='uuid-0'}[222s]))"
|
"ceilometer_cpu{resource='uuid-0'}[222s]))"
|
||||||
"/10e+8) *(100/2), 100)"
|
"/10e+8) *(100/2), 100)"
|
||||||
)
|
)
|
||||||
@@ -655,7 +655,7 @@ class TestPrometheusHelper(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_build_prometheus_query_instance_cpu_max_agg(self):
|
def test_build_prometheus_query_instance_cpu_max_agg(self):
|
||||||
expected_query = (
|
expected_query = (
|
||||||
"clamp_max((max by (instance)(rate("
|
"clamp_max((max by (resource)(rate("
|
||||||
"ceilometer_cpu{resource='uuid-0'}[555s]))"
|
"ceilometer_cpu{resource='uuid-0'}[555s]))"
|
||||||
"/10e+8) *(100/4), 100)"
|
"/10e+8) *(100/4), 100)"
|
||||||
)
|
)
|
||||||
@@ -699,7 +699,7 @@ class TestPrometheusHelper(base.BaseTestCase):
|
|||||||
def test_prometheus_query_custom_uuid_label(self, mock_prometheus_get):
|
def test_prometheus_query_custom_uuid_label(self, mock_prometheus_get):
|
||||||
cfg.CONF.prometheus_client.instance_uuid_label = 'custom_uuid_label'
|
cfg.CONF.prometheus_client.instance_uuid_label = 'custom_uuid_label'
|
||||||
expected_query = (
|
expected_query = (
|
||||||
"clamp_max((max by (instance)"
|
"clamp_max((max by (custom_uuid_label)"
|
||||||
"(rate(ceilometer_cpu{custom_uuid_label='uuid-0'}[555s]))"
|
"(rate(ceilometer_cpu{custom_uuid_label='uuid-0'}[555s]))"
|
||||||
"/10e+8) *(100/4), 100)"
|
"/10e+8) *(100/4), 100)"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user