Merge "Fix Prometheus Plugin syntax error"
This commit is contained in:
commit
286234013e
|
@ -260,7 +260,7 @@ The following are the parameters required by this interface.
|
|||
* ``performanceMetric`` and ``performanceMetricGroup``, at least one of
|
||||
the two attributes shall be present.
|
||||
* ``objectType`` has only the following values: ``Vnf``, ``Vnfc``,
|
||||
``VnfIntCP``, ``VnfExtCP``.
|
||||
``VnfIntCp``, ``VnfExtCp``.
|
||||
|
||||
|
||||
|
||||
|
@ -284,7 +284,7 @@ as follows:
|
|||
"VcpuUsageMeanVnf.495ffedf-2755-42c8-bf14-a5433701311e"
|
||||
],
|
||||
"performanceMetricGroup": [
|
||||
"VirtualizedComputeResource"
|
||||
"VirtualisedComputeResource"
|
||||
],
|
||||
"collectionPeriod": 5,
|
||||
"reportingPeriod": 10,
|
||||
|
|
|
@ -58,7 +58,7 @@ Alert = {
|
|||
'annotations': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'value': {'type': 'number'},
|
||||
'value': {'type': ['number', 'string']},
|
||||
'probable_cause': {'type': 'string'},
|
||||
'fault_type': {'type': 'string'},
|
||||
'fault_details': {'type': 'string'}
|
||||
|
|
|
@ -51,8 +51,8 @@ CreatePmJobRequest_V210 = {
|
|||
# the types can be extended.
|
||||
'Vnf',
|
||||
'Vnfc',
|
||||
'VnfIntCP',
|
||||
'VnfExtCP']
|
||||
'VnfIntCp',
|
||||
'VnfExtCp']
|
||||
},
|
||||
'objectInstanceIds': {
|
||||
'type': 'array',
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import datetime
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import paramiko
|
||||
|
@ -78,10 +79,10 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
self.sol_exp_map = {
|
||||
'VCpuUsageMeanVnf':
|
||||
'avg(sum(rate(pod_cpu_usage_seconds_total'
|
||||
'{{pod=~"{pod}"}}[{reporting_period}s]))',
|
||||
'{{pod=~"{pod}"}}[{reporting_period}s])))',
|
||||
'VCpuUsagePeakVnf':
|
||||
'max(sum(rate(pod_cpu_usage_seconds_total'
|
||||
'{{pod=~"{pod}"}}[{reporting_period}s]))',
|
||||
'{{pod=~"{pod}"}}[{reporting_period}s])))',
|
||||
'VMemoryUsageMeanVnf':
|
||||
'avg(pod_memory_working_set_bytes{{pod=~"{pod}"}} / '
|
||||
'on(pod) (kube_node_status_capacity{{resource="memory"}} * '
|
||||
|
@ -93,11 +94,11 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
'VDiskUsageMeanVnf':
|
||||
'avg(container_fs_usage_bytes{{container="{container}",'
|
||||
'pod=~"{pod}"}}/container_fs_limit_bytes{{container='
|
||||
'"{container}",pod=~"{pod}"}}))',
|
||||
'"{container}",pod=~"{pod}"}})',
|
||||
'VDiskUsagePeakVnf':
|
||||
'max(container_fs_usage_bytes{{container="{container}",'
|
||||
'pod=~"{pod}"}}/container_fs_limit_bytes{{container='
|
||||
'"{container}",pod=~"{pod}"}}))',
|
||||
'"{container}",pod=~"{pod}"}})',
|
||||
'ByteIncomingVnfIntCp':
|
||||
'sum(container_network_receive_bytes_total'
|
||||
'{{interface="{sub_object_instance_id}",pod=~"{pod}"}})',
|
||||
|
@ -164,6 +165,8 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
if not report:
|
||||
return None
|
||||
|
||||
report = list(map(lambda x: x.entries, report))
|
||||
report = list(itertools.chain.from_iterable(report))
|
||||
entries_of_same_object = list(
|
||||
filter(
|
||||
lambda x: (
|
||||
|
@ -171,7 +174,7 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
(not x.obj_attr_is_set('subObjectInstanceId') or
|
||||
x.subObjectInstanceId == sub_object_instance_id) and
|
||||
x.performanceMetric == metric),
|
||||
report.entries))
|
||||
report))
|
||||
if len(entries_of_same_object) == 0:
|
||||
return None
|
||||
values = sum(list(map(
|
||||
|
@ -283,7 +286,7 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
pm_job.criteria.performanceMetricGroup) else []
|
||||
for obj in pm_job.objectInstanceIds:
|
||||
for grp in metric_grps:
|
||||
if grp == 'VirtualizedComputeResource':
|
||||
if grp == 'VirtualisedComputeResource':
|
||||
metrics.append(f'VCpuUsageMeanVnf.{obj}')
|
||||
metrics.append(f'VCpuUsagePeakVnf.{obj}')
|
||||
metrics.append(f'VMemoryUsageMeanVnf.{obj}')
|
||||
|
@ -346,8 +349,8 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
# ['test-test1-756757f8f-xcwmt',
|
||||
# 'test-test2-756757f8f-kmghr', ...]
|
||||
# convert them to a regex string such as:
|
||||
# '(test\-test1\-[0-9a-f]{1,10}-[0-9a-z]{5}$|
|
||||
# test\-test2\-[0-9a-f]{1,10}-[0-9a-z]{5}$|...)'
|
||||
# '(test-test1-[0-9a-f]{1,10}-[0-9a-z]{5}$|
|
||||
# test-test2-[0-9a-f]{1,10}-[0-9a-z]{5}$|...)'
|
||||
deployments = list(filter(
|
||||
lambda r:
|
||||
r.computeResource.obj_attr_is_set(
|
||||
|
@ -359,10 +362,10 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
'Deployment', resource_info
|
||||
))
|
||||
deployments = list(set(list(map(
|
||||
lambda d: re.escape(re.sub(
|
||||
r'\-[0-9a-f]{1,10}-[0-9a-z]{5}$', '',
|
||||
d.computeResource.resourceId)) +
|
||||
r'\-[0-9a-f]{1,10}-[0-9a-z]{5}$',
|
||||
lambda d: re.sub(
|
||||
r'\-[0-9a-f]{1,10}\-[0-9a-z]{5}$', '',
|
||||
d.computeResource.resourceId) +
|
||||
r'-[0-9a-f]{1,10}-[0-9a-z]{5}$',
|
||||
deployments
|
||||
))))
|
||||
pods_regexp = '(' + '|'.join(deployments) + ')'
|
||||
|
@ -379,8 +382,8 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
# ['test-test1-756757f8f-xcwmt',
|
||||
# 'test-test2-756757f8f-kmghr', ...]
|
||||
# convert them to a regex string such as:
|
||||
# '(test\-test1\-[0-9a-f]{1,10}-[0-9a-z]{5}$|
|
||||
# test\-test2\-[0-9a-f]{1,10}-[0-9a-z]{5}$|...)'
|
||||
# '(test-test1-[0-9a-f]{1,10}-[0-9a-z]{5}$|
|
||||
# test-test2-[0-9a-f]{1,10}-[0-9a-z]{5}$|...)'
|
||||
resource_info = self.get_vnfc_resource_info(context, obj, inst_map)
|
||||
if not resource_info:
|
||||
continue
|
||||
|
@ -443,12 +446,11 @@ class PrometheusPluginPm(PrometheusPlugin, mon_base.MonitoringPlugin):
|
|||
continue
|
||||
resource_id = compute_resource.resourceId
|
||||
deployment = re.sub(
|
||||
r'\-[0-9a-f]{1,10}-[0-9a-z]{5}$', '', resource_id)
|
||||
r'\-[0-9a-f]{1,10}\-[0-9a-z]{5}$', '', resource_id)
|
||||
g = re.match(r'^(.+)\-\1{1,}[0-9]+', deployment)
|
||||
if not g:
|
||||
continue
|
||||
container = g.group(1)
|
||||
resource_id = re.escape(resource_id)
|
||||
expr = self.make_prom_ql(
|
||||
target, resource_id, container=container,
|
||||
collection_period=collection_period,
|
||||
|
|
|
@ -40,8 +40,8 @@ CONF = config.CONF
|
|||
OBJ_TYPE_TO_GROUP_TYPE = {
|
||||
'Vnf': 'VirtualisedComputeResource',
|
||||
'Vnfc': 'VirtualisedComputeResource',
|
||||
'VnfIntCP': 'VnfInternalCP',
|
||||
'VnfExtCP': 'VnfExternalCP'
|
||||
'VnfIntCp': 'VnfInternalCp',
|
||||
'VnfExtCp': 'VnfExternalCp'
|
||||
}
|
||||
|
||||
OBJ_TYPE_TO_METRIC_LISt = {
|
||||
|
@ -51,9 +51,9 @@ OBJ_TYPE_TO_METRIC_LISt = {
|
|||
'Vnfc': {'VCpuUsageMeanVnf', 'VCpuUsagePeakVnf',
|
||||
'VMemoryUsageMeanVnf', 'VMemoryUsagePeakVnf',
|
||||
'VDiskUsageMeanVnf', 'VDiskUsagePeakVnf'},
|
||||
'VnfIntCP': {'ByteIncomingVnfIntCp', 'ByteOutgoingVnfIntCp',
|
||||
'VnfIntCp': {'ByteIncomingVnfIntCp', 'ByteOutgoingVnfIntCp',
|
||||
'PacketIncomingVnfIntCp', 'PacketOutgoingVnfIntCp'},
|
||||
'VnfExtCP': {'ByteIncomingVnfExtCp', 'ByteOutgoingVnfExtCp',
|
||||
'VnfExtCp': {'ByteIncomingVnfExtCp', 'ByteOutgoingVnfExtCp',
|
||||
'PacketIncomingVnfExtCp', 'PacketOutgoingVnfExtCp'}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ _body_pm_alert1 = {
|
|||
'object_instance_id': '25b9b9d0-2461-4109-866e-a7767375415b'
|
||||
},
|
||||
'annotations': {
|
||||
'value': 99,
|
||||
'value': '99',
|
||||
},
|
||||
'startsAt': '2022-06-21T23:47:36.453Z',
|
||||
'endsAt': '0001-01-01T00:00:00Z',
|
||||
|
@ -110,7 +110,7 @@ _pm_job = {
|
|||
'VcpuUsageMeanVnf.25b9b9d0-2461-4109-866e-a7767375415b'
|
||||
],
|
||||
'performanceMetricGroup': [
|
||||
'VirtualizedComputeResource',
|
||||
'VirtualisedComputeResource',
|
||||
'InvalidGroupName'
|
||||
],
|
||||
'collectionPeriod': 15,
|
||||
|
@ -331,8 +331,8 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
self.config_fixture.config(
|
||||
group='prometheus_plugin', performance_management=True)
|
||||
mock_pm_job.return_value = objects.PmJobV2.from_dict(_pm_job)
|
||||
mock_pm_report.return_value = objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)
|
||||
mock_pm_report.return_value = [objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)]
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
|
||||
|
@ -350,8 +350,8 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
self.config_fixture.config(
|
||||
group='prometheus_plugin', performance_management=True)
|
||||
mock_pm_job.return_value = objects.PmJobV2.from_dict(_pm_job)
|
||||
mock_pm_report.return_value = objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)
|
||||
mock_pm_report.return_value = [objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)]
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
unload_uuidsentinel()
|
||||
|
@ -367,8 +367,8 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
self.config_fixture.config(
|
||||
group='prometheus_plugin', performance_management=True)
|
||||
mock_pm_job.return_value = objects.PmJobV2.from_dict(_pm_job)
|
||||
mock_pm_report.return_value = objects.PerformanceReportV2.from_dict(
|
||||
_pm_report2)
|
||||
mock_pm_report.return_value = [objects.PerformanceReportV2.from_dict(
|
||||
_pm_report2)]
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
unload_uuidsentinel()
|
||||
|
@ -393,8 +393,8 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
self.config_fixture.config(
|
||||
group='prometheus_plugin', performance_management=True)
|
||||
mock_pm_job.return_value = objects.PmJobV2.from_dict(_pm_job)
|
||||
mock_pm_report.return_value = objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)
|
||||
mock_pm_report.return_value = [objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)]
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
unload_uuidsentinel()
|
||||
|
@ -417,8 +417,8 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
self.config_fixture.config(
|
||||
group='prometheus_plugin', performance_management=True)
|
||||
mock_pm_job.return_value = objects.PmJobV2.from_dict(_pm_job)
|
||||
mock_pm_report.return_value = objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)
|
||||
mock_pm_report.return_value = [objects.PerformanceReportV2.from_dict(
|
||||
_pm_report)]
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
pp.set_callback(None)
|
||||
|
@ -487,7 +487,7 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
group='prometheus_plugin', performance_management=True)
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
# VirtualizedComputeResource
|
||||
# VirtualisedComputeResource
|
||||
job = objects.PmJobV2.from_dict(_pm_job)
|
||||
rule = pp.create_job(context=self.context, pm_job=job)
|
||||
self.assertTrue(len(rule['groups'][0]['rules']) > 0)
|
||||
|
@ -515,7 +515,7 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
group='prometheus_plugin', performance_management=True)
|
||||
pp = mon_base.MonitoringPlugin.get_instance(
|
||||
prometheus_plugin.PrometheusPluginPm)
|
||||
# VirtualizedComputeResource
|
||||
# VirtualisedComputeResource
|
||||
job = copy.deepcopy(_pm_job)
|
||||
job['subObjectInstanceIds'] = ['vnfc_info1']
|
||||
job = objects.PmJobV2.from_dict(job)
|
||||
|
@ -638,7 +638,7 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
pp.create_job, context=self.context, pm_job=job
|
||||
)
|
||||
|
||||
# resourcename mismatch: VirtualizedComputeResource
|
||||
# resourcename mismatch: VirtualisedComputeResource
|
||||
ins = copy.deepcopy(_inst1)
|
||||
_ = ins['instantiatedVnfInfo']['vnfcResourceInfo']
|
||||
del _[0]['computeResource']['resourceId']
|
||||
|
@ -650,7 +650,7 @@ class TestPrometheusPluginPm(base.TestCase):
|
|||
sol_ex.PrometheusPluginError,
|
||||
pp.create_job, context=self.context, pm_job=job
|
||||
)
|
||||
# resourcename mismatch: VirtualizedComputeResource
|
||||
# resourcename mismatch: VirtualisedComputeResource
|
||||
ins = copy.deepcopy(_inst1)
|
||||
_ = ins['instantiatedVnfInfo']['vnfcResourceInfo'][0]
|
||||
_['computeResource']['resourceId'] = 'test-xxx1-756757f8f-xcwmt'
|
||||
|
|
|
@ -100,7 +100,7 @@ class TestVnfpmV2(base.BaseTestCase):
|
|||
vnfpm_v2._check_performance_metric_or_group,
|
||||
obj_type='Vnf',
|
||||
metric_group=['VirtualisedComputeResource',
|
||||
'VnfInternalCP'],
|
||||
'VnfInternalCp'],
|
||||
performance_metric=['VCpuUsageMeanVnf.VNF'])
|
||||
|
||||
self.assertRaises(sol_ex.PMJobInvalidRequest,
|
||||
|
|
Loading…
Reference in New Issue