def test_metrics(mock_app_config): # noqa: F811 context = EventContext(app_config=mock_app_config, plugin_config=mock_app_config, event_name='mock_event', track_ids={}, auth_info={ 'auth_type': AuthType.UNSECURED, 'allowed': 'true' }) context.creation_ts = ZERO_TS metrics.datetime = MockDatetime MockDatetime.ts = 3.0 result = metrics.metrics(context) assert result['extra'] == 'metrics.duration=3000.000'
def test_stream_metrics(mock_app_config): # noqa: F811 context = EventContext(app_config=mock_app_config, plugin_config=mock_app_config, event_name='mock_event', track_ids={'track.request_ts': ZERO_TS.isoformat()}, auth_info={ 'auth_type': AuthType.UNSECURED, 'allowed': 'true' }) context.track_ids['stream.submit_ts'] = ONE_TS.isoformat() context.track_ids['stream.read_ts'] = TWO_TS.isoformat() context.creation_ts = ZERO_TS metrics.datetime = MockDatetime MockDatetime.ts = 3.0 result = metrics.stream_metrics(context) assert result[ 'extra'] == 'metrics.stream_age=1000.000 | metrics.request_elapsed=3000.000'