Skip to content

Commit

Permalink
修复监控插件失败无异常输出的问题 (#6910)
Browse files Browse the repository at this point in the history
* bugfix: 修复监控插件失败无异常输出的问题

* test: 修复单元测试的问题

* test: 修复单元测试的问题
  • Loading branch information
hanshuaikang committed Aug 10, 2023
1 parent e70cc45 commit 667da6d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",'
Expand Down

0 comments on commit 667da6d

Please sign in to comment.