Skip to content

Commit

Permalink
add lyrebrid metrics swich (#849)
Browse files Browse the repository at this point in the history
* add switch on lyrebird metrics

* add config in unit test

* change switch locate

* recover

* version

---------

Co-authored-by: wujiasheng03 <[email protected]>
  • Loading branch information
noO0oOo0ob and wujiasheng03 authored May 8, 2024
1 parent 5ec6c48 commit de19e25
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 14 deletions.
13 changes: 9 additions & 4 deletions lyrebird/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self):
self.any_channel = []
self.broadcast_executor = ThreadPoolExecutor(thread_name_prefix='event-broadcast-')
self.only_report_channel = application.config.get('event.only_report_channel', [])
self.lyrebird_metrics_report = application.config.get('event.lyrebird_metrics_report', True)

def broadcast_handler(self, callback_fn, event, args, kwargs):
"""
Expand Down Expand Up @@ -78,11 +79,15 @@ def broadcast_handler(self, callback_fn, event, args, kwargs):
except Exception:
logger.error(f'Event callback function [{callback_fn.__name__}] error. {traceback.format_exc()}')
finally:
event_end_time = time.time()
event_duration = (event_end_time - event_start_time) * 1000
# Report the operation of Event
# Prevent loop reporting, and only time-consuming event(more than 1ms) are reported
if event.channel != 'lyrebird_metrics' and event_duration > 1:
if event.channel == 'lyrebird_metrics':
return
if not self.lyrebird_metrics_report:
return
event_end_time = time.time()
event_duration = (event_end_time - event_start_time) * 1000
if event_duration > 1:
trace_info = {
'channel': event.channel,
'callback_fn': callback_fn.__name__,
Expand Down Expand Up @@ -166,7 +171,7 @@ def publish(self, channel, message, state=False, *args, **kwargs):
}
message['sender'] = sender_dict

if not (channel not in self.pubsub_channels and channel in self.only_report_channel):
if channel in self.pubsub_channels or channel not in self.only_report_channel:
self.event_queue.put(Event(event_id, channel, message))

# TODO Remove state and raw data
Expand Down
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (2, 26, 3)
IVERSION = (2, 26, 4)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION
3 changes: 2 additions & 1 deletion tests/test_common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
'mock.port': 9090,
'custom_key': 'custom_value',
'config.value.tojsonKey': ['custom.[a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12}'],
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"custom_key": "custom_value"}
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"custom_key": "custom_value"},
'event.lyrebird_metrics_report': False
}

origin_data = '"keyA":"valueA","keyB":"{{config.get(\'custom.8df051be-4381-41b6-9252-120d9b558bf6\')}}","keyC":"valueC","keyD":"{{today}}"'
Expand Down
3 changes: 2 additions & 1 deletion tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
def event_server(tmpdir):
_conf = {
'ip': '127.0.0.1',
'mock.port': 9090
'mock.port': 9090,
'event.lyrebird_metrics_report': False
}
_personal_conf = personal_config_template
application._cm = MockConfigManager(config=_conf, personal_config=_personal_conf, ROOT=Path(tmpdir), root=Path(tmpdir))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def data_manager(root, tmpdir):
'ip': '127.0.0.1',
'mock.port': 9090,
'config.value.tojsonKey': ['custom.[a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12}'],
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"key": "value"}
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"key": "value"},
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)
lyrebird.mock.context.application.socket_io = FakeSocketio()
Expand All @@ -375,7 +376,8 @@ def test_load_from_path(root):
'ip': '127.0.0.1',
'mock.port': 9090,
'config.value.tojsonKey': ['custom.[a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12}'],
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"key": "value"}
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"key": "value"},
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_dm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def client(root, tmpdir):
_conf = {
'ip': '127.0.0.1',
'mock.port': 9090,
'mock.data': 'data'
'mock.data': 'data',
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)
lyrebird.mock.context.application.socket_io = FakeSocketio()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dm_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def config():
'mock.port': 9090,
'custom_key': 'custom_value',
'config.value.tojsonKey': ['custom.[a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12}'],
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"custom_key": "custom_value"}
'custom.8df051be-4381-41b6-9252-120d9b558bf6': {"custom_key": "custom_value"},
'event.lyrebird_metrics_report': False
}
application._cm = ConfigManager()
application._cm.config = _conf
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dm_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def root(tmpdir):
def data_manager(root):
_conf = {
'ip': '127.0.0.1',
'mock.port': 9090
'mock.port': 9090,
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)
_dm = dm.DataManager()
Expand Down
1 change: 1 addition & 0 deletions tests/test_dm_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def data_manager(root, tmpdir):
_conf = {
'ip': '127.0.0.1',
'mock.port': 9090,
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)
lyrebird.mock.context.application.socket_io = FakeSocketio()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def callback_tester():
def event_server():
_conf = {
'ip': '127.0.0.1',
'mock.port': 9090
'mock.port': 9090,
'event.lyrebird_metrics_report': False
}
application._cm = MockConfigManager(config=_conf)
lyrebird.mock.context.application.socket_io = FakeSocketio()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_flow_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def test_func(flow):
'checker.workspace': '',
'checker.switch': {
FILENAME: True
}
},
'event.lyrebird_metrics_report': False
}


Expand Down

0 comments on commit de19e25

Please sign in to comment.