From 667da6d0b9d6945538e1e0aeb32df8724df5b751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=95=B0?= <33194175+hanshuaikang@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:31:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=A4=B1=E8=B4=A5=E6=97=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98=20(#6910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bugfix: 修复监控插件失败无异常输出的问题 * test: 修复单元测试的问题 * test: 修复单元测试的问题 --- .../collections/sites/open/monitor/base.py | 1 + .../monitor_test/alarm_shield/test_v1_1.py | 9 ++++++++ .../alarm_shield_strategy/test_v1_1.py | 14 +++++++++---- .../alarm_shield_strategy/test_v1_2.py | 16 ++++++++++---- .../open/monitor_test/test_alarm_shield.py | 21 ++++++++++++++----- .../test_alarm_shield_strategy.py | 14 +++++++++---- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/pipeline_plugins/components/collections/sites/open/monitor/base.py b/pipeline_plugins/components/collections/sites/open/monitor/base.py index 9a1713a1db..a37fd45581 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/base.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/base.py @@ -74,6 +74,7 @@ def send_request(self, request_body, data, client): if not response["result"]: message = monitor_handle_api_error("monitor.create_shield", request_body, response) self.logger.error(message) + data.outputs.ex_data = message shield_id = "" ret_flag = False else: diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_1.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_1.py index 62a6108623..bc656755c6 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_1.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_1.py @@ -142,6 +142,15 @@ def get_module_id_list_by_name(bk_biz_id, username, set_list, service_template_l execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " + 'params={"begin_time":"2020-09-28 11:18:58",' + '"bk_biz_id":2,"category":"scope","cycle_config":{"begin_time":"","end_time":"","day_list":[],' + '"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":' + '{"scope_type":"node","target":[{"bk_obj_id":"module","bk_inst_id":1},{"bk_obj_id":"module",' + '"bk_inst_id":2},{"bk_obj_id":"module","bk_inst_id":3},{"bk_obj_id":"module","bk_inst_id":4},' + '{"bk_obj_id":"module","bk_inst_id":5}],"metric_id":["bk_monitor.system.load.load5",' + '"bk_monitor.system.cpu_summary.usage"]},"end_time":"2020-09-28 11:18:58","notice_config":{},' + '"shield_notice":false}', "shield_id": "", "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " 'params={"begin_time":"2020-09-28 11:18:58",' diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_1.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_1.py index 08a4d6b1c3..1778bdb808 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_1.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_1.py @@ -13,15 +13,15 @@ from django.test import TestCase from mock import MagicMock - from pipeline.component_framework.test import ( - ComponentTestMixin, - ComponentTestCase, + Call, CallAssertion, + ComponentTestCase, + ComponentTestMixin, ExecuteAssertion, - Call, Patcher, ) + from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield_strategy.v1_1 import ( MonitorAlarmShieldStrategyComponent, ) @@ -113,6 +113,12 @@ def __init__(self): execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " + 'params={"begin_time":"2019-11-04 00:00:00",' + '"bk_biz_id":2,"category":"strategy","cycle_config":{"begin_time":"","end_time":"","day_list":' + '[],"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":{"id":"123",' + '"scope_type":"ip","target":[{"ip":"127.0.0.1","bk_cloud_id":0},{"ip":"127.0.0.2",' + '"bk_cloud_id":1}]},"end_time":"2019-11-05 00:00:00","notice_config":{},"shield_notice":false}', "shield_id": "", "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " 'params={"begin_time":"2019-11-04 00:00:00",' diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_2.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_2.py index 1257676fee..c8f2d87607 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_2.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield_strategy/test_v1_2.py @@ -11,15 +11,15 @@ specific language governing permissions and limitations under the License. """ from django.test import TestCase +from mock import MagicMock from pipeline.component_framework.test import ( - ComponentTestMixin, + Call, + CallAssertion, ComponentTestCase, + ComponentTestMixin, ExecuteAssertion, - CallAssertion, - Call, Patcher, ) -from mock import MagicMock from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield_strategy.v1_2 import ( MonitorAlarmShieldStrategyComponent, @@ -112,6 +112,14 @@ def __init__(self): execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " + 'params={"begin_time":"2019-11-04 00:00:00",' + '"bk_biz_id":2,"category":"strategy","cycle_config":{"begin_time":"","end_time":"","day_list":' + '[],"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":{"id":"123",' + '"dimension_conditions":[{"condition":"and","key":"bk_biz_id","method":"eq","value":["1","2"],' + '"name":"bk_biz_id"}],' # noqa + '"scope_type":"ip","target":[{"ip":"127.0.0.1","bk_cloud_id":0},{"ip":"127.0.0.2",' + '"bk_cloud_id":1}]},"end_time":"2019-11-05 00:00:00","notice_config":{},"shield_notice":false}', "shield_id": "", "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " 'params={"begin_time":"2019-11-04 00:00:00",' diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield.py index 8a983b2e96..305b4976f1 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield.py @@ -13,16 +13,18 @@ from django.test import TestCase from mock import MagicMock - from pipeline.component_framework.test import ( - ComponentTestMixin, - ComponentTestCase, + Call, CallAssertion, + ComponentTestCase, + ComponentTestMixin, ExecuteAssertion, - Call, Patcher, ) -from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.v1_0 import MonitorAlarmShieldComponent + +from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.v1_0 import ( + MonitorAlarmShieldComponent, +) class MonitorAlarmShieldComponentTest(TestCase, ComponentTestMixin): @@ -138,6 +140,15 @@ def get_module_id_list_by_name(bk_biz_id, username, set_list, service_template_l execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " + 'params={"begin_time":"2020-09-28 11:18:58",' + '"bk_biz_id":2,"category":"scope","cycle_config":{"begin_time":"","end_time":"","day_list":[],' + '"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":' + '{"scope_type":"node","target":[{"bk_obj_id":"module","bk_inst_id":1},{"bk_obj_id":"module",' + '"bk_inst_id":2},{"bk_obj_id":"module","bk_inst_id":3},{"bk_obj_id":"module","bk_inst_id":4},' + '{"bk_obj_id":"module","bk_inst_id":5}],"metric_id":["bk_monitor.system.load.load5",' + '"bk_monitor.system.cpu_summary.usage"]},"end_time":"2020-09-28 11:18:58","notice_config":{},' + '"shield_notice":false}', "shield_id": "", "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " 'params={"begin_time":"2020-09-28 11:18:58",' diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield_strategy.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield_strategy.py index 7df9721089..b703cb8e46 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield_strategy.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/test_alarm_shield_strategy.py @@ -13,15 +13,15 @@ from django.test import TestCase from mock import MagicMock - from pipeline.component_framework.test import ( - ComponentTestMixin, - ComponentTestCase, + Call, CallAssertion, + ComponentTestCase, + ComponentTestMixin, ExecuteAssertion, - Call, Patcher, ) + from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield_strategy.v1_0 import ( MonitorAlarmShieldStrategyComponent, ) @@ -117,6 +117,12 @@ def __init__(self): execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " + 'params={"begin_time":"2019-11-04 00:00:00",' + '"bk_biz_id":2,"category":"strategy","cycle_config":{"begin_time":"","end_time":"","day_list":' + '[],"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":{"id":"123",' + '"scope_type":"ip","target":[{"ip":"127.0.0.1","bk_cloud_id":0},{"ip":"127.0.0.2",' + '"bk_cloud_id":1}]},"end_time":"2019-11-05 00:00:00","notice_config":{},"shield_notice":false}', "shield_id": "", "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " 'params={"begin_time":"2019-11-04 00:00:00",' From 749372c53d5f9342d590dd2988f9d3e3b7ca18ca Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Thu, 10 Aug 2023 15:59:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitor_test/alarm_shield/test_v1_2.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_2.py b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_2.py index bc0aebc718..f0d35dae36 100644 --- a/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_2.py +++ b/pipeline_plugins/tests/components/collections/sites/open/monitor_test/alarm_shield/test_v1_2.py @@ -22,9 +22,7 @@ Patcher, ) -from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.v1_2 import ( - MonitorAlarmShieldComponent, -) +from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.v1_2 import MonitorAlarmShieldComponent class MonitorAlarmShieldComponentTest(TestCase, ComponentTestMixin): @@ -141,16 +139,27 @@ def get_module_id_list_by_name(bk_biz_id, username, set_list, service_template_l execute_assertion=ExecuteAssertion( success=False, outputs={ + "ex_data": "调用监控平台(Monitor)接口monitor.create_shield返回失败," + " error=create shield fail, " + 'params={"begin_time":"2020-09-28 11:18:58","bk_biz_id":2,"category":"scope",' + '"cycle_config":{"begin_time":"","end_time":"","day_list":[],"week_list":[],"type":1},' + '"description":"shield by bk_sops","dimension_config":{"scope_type":"node",' + '"target":[{"bk_obj_id":"module","bk_inst_id":1},{"bk_obj_id":"module","bk_inst_id":2},' + '{"bk_obj_id":"module","bk_inst_id":3},{"bk_obj_id":"module","bk_inst_id":4},' + '{"bk_obj_id":"module","bk_inst_id":5}],' + '"metric_id":["bk_monitor.system.load.load5","bk_monitor.system.cpu_summary.usage"]},' + '"end_time":"2020-09-28 11:18:58","notice_config":{},"shield_notice":false}', "shield_id": "", - "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败, error=create shield fail, " - 'params={"begin_time":"2020-09-28 11:18:58",' - '"bk_biz_id":2,"category":"scope","cycle_config":{"begin_time":"","end_time":"","day_list":[],' - '"week_list":[],"type":1},"description":"shield by bk_sops","dimension_config":' - '{"scope_type":"node","target":[{"bk_obj_id":"module","bk_inst_id":1},{"bk_obj_id":"module",' - '"bk_inst_id":2},{"bk_obj_id":"module","bk_inst_id":3},{"bk_obj_id":"module","bk_inst_id":4},' - '{"bk_obj_id":"module","bk_inst_id":5}],"metric_id":["bk_monitor.system.load.load5",' - '"bk_monitor.system.cpu_summary.usage"]},"end_time":"2020-09-28 11:18:58","notice_config":{},' - '"shield_notice":false}', + "message": "调用监控平台(Monitor)接口monitor.create_shield返回失败," + " error=create shield fail, " + 'params={"begin_time":"2020-09-28 11:18:58","bk_biz_id":2,"category":"scope",' + '"cycle_config":{"begin_time":"","end_time":"","day_list":[],"week_list":[],"type":1},' + '"description":"shield by bk_sops","dimension_config":{"scope_type":"node",' + '"target":[{"bk_obj_id":"module","bk_inst_id":1},{"bk_obj_id":"module","bk_inst_id":2},' + '{"bk_obj_id":"module","bk_inst_id":3},{"bk_obj_id":"module","bk_inst_id":4},' + '{"bk_obj_id":"module","bk_inst_id":5}],' + '"metric_id":["bk_monitor.system.load.load5","bk_monitor.system.cpu_summary.usage"]},' + '"end_time":"2020-09-28 11:18:58","notice_config":{},"shield_notice":false}', }, ), schedule_assertion=None,