Skip to content

Commit 7930b34

Browse files
author
ffaraoneim
authored
Merge pull request #60 from cloudblue/LITE-22464-task-stats-improvements
LITE-22464: Task stats improvements sending runner_version and runtime
2 parents 647befd + 104377c commit 7930b34

File tree

12 files changed

+90
-8
lines changed

12 files changed

+90
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ temp/
2020
coverage.xml
2121

2222
setup.py
23+
/extension

connect/eaas/dataclasses.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TaskPayload:
5959
output: Optional[str] = None
6060
correlation_id: Optional[str] = None
6161
reply_to: Optional[str] = None
62+
runtime: Optional[float] = 0.0
6263

6364

6465
@dataclasses.dataclass
@@ -82,6 +83,7 @@ class CapabilitiesPayload:
8283
schedulables: Optional[list] = None
8384
readme_url: Optional[str] = None
8485
changelog_url: Optional[str] = None
86+
runner_version: Optional[str] = None
8587

8688

8789
@dataclasses.dataclass

connect/eaas/managers/background.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ async def build_response(self, task_data, future):
6565
timeout=self.config.get_timeout('background'),
6666
)
6767
result_message.result = result.status
68-
elapsed = time.monotonic() - begin_ts
68+
result_message.runtime = time.monotonic() - begin_ts
6969
logger.info(
70-
f'background task {task_data.task_id} result: {result.status}, tooks: {elapsed}',
70+
f'background task {task_data.task_id} result: {result.status}, tooks:'
71+
f' {result_message.runtime}',
7172
)
7273
if result.status in (ResultType.SKIP, ResultType.FAIL):
7374
result_message.output = result.output

connect/eaas/managers/interactive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ async def build_response(self, task_data, future):
4545
result_message.result = result.status
4646
result_message.data = result.data
4747
result_message.output = result.output
48-
elapsed = time.monotonic() - begin_ts
48+
result_message.runtime = time.monotonic() - begin_ts
4949
logger.info(
50-
f'interactive task {task_data.task_id} result: {result.status}, tooks: {elapsed}',
50+
f'interactive task {task_data.task_id} result: {result.status}, tooks:'
51+
f' {result_message.runtime}',
5152
)
5253
except Exception as e:
5354
self.log_exception(task_data, e)

connect/eaas/managers/scheduled.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
import dataclasses
88
import logging
9+
import time
910
import traceback
1011

1112
from connect.eaas.dataclasses import (
@@ -39,12 +40,18 @@ async def build_response(self, task_data, future):
3940
result = None
4041
result_message = TaskPayload(**dataclasses.asdict(task_data))
4142
try:
43+
begin_ts = time.monotonic()
4244
result = await asyncio.wait_for(
4345
future,
4446
timeout=self.config.get_timeout('scheduled'),
4547
)
4648
result_message.result = result.status
4749
result_message.output = result.output
50+
result_message.runtime = time.monotonic() - begin_ts
51+
logger.info(
52+
f'interactive task {task_data.task_id} result: {result.status}, tooks:'
53+
f' {result_message.runtime}',
54+
)
4855
except Exception as e:
4956
self.log_exception(task_data, e)
5057
result_message.result = ResultType.RETRY

connect/eaas/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
StopBackoffError,
4141
)
4242
from connect.eaas.handler import ExtensionHandler
43-
from connect.eaas.helpers import to_ordinal
43+
from connect.eaas.helpers import get_version, to_ordinal
4444
from connect.eaas.managers import (
4545
BackgroundTasksManager,
4646
InteractiveTasksManager,
@@ -196,6 +196,7 @@ def get_capabilities(self):
196196
self.handler.schedulables,
197197
self.handler.readme,
198198
self.handler.changelog,
199+
get_version(),
199200
),
200201
),
201202
)

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ def config_payload():
7777

7878
@pytest.fixture
7979
def task_payload():
80-
def _task_payload(task_category, task_type, object_id):
80+
def _task_payload(task_category, task_type, object_id, runtime=0.0):
8181
return {
8282
'task_id': 'TQ-000',
8383
'task_category': task_category,
8484
'task_type': task_type,
8585
'object_id': object_id,
86+
'runtime': runtime,
8687
}
8788
return _task_payload

tests/managers/test_background.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
import pytest
45

@@ -40,6 +41,9 @@ async def test_sync(mocker, extension_cls, task_type, config_payload):
4041
)
4142
mocker.patch('connect.eaas.handler.get_extension_class')
4243
mocker.patch('connect.eaas.handler.get_extension_type')
44+
mocked_time = mocker.patch('connect.eaas.managers.background.time')
45+
mocked_time.sleep = time.sleep
46+
mocked_time.monotonic.side_effect = (1.0, 2.0)
4347
handler = ExtensionHandler(config)
4448
handler.extension_class = extension_cls(TASK_TYPE_EXT_METHOD_MAP[task_type])
4549
handler.extension_type = 'sync'
@@ -53,6 +57,7 @@ async def test_sync(mocker, extension_cls, task_type, config_payload):
5357
TaskCategory.BACKGROUND,
5458
task_type,
5559
'PR-000',
60+
runtime=1.0,
5661
)
5762

5863
await manager.submit(task)
@@ -78,6 +83,9 @@ async def test_async(mocker, extension_cls, task_type, config_payload):
7883
)
7984
mocker.patch('connect.eaas.handler.get_extension_class')
8085
mocker.patch('connect.eaas.handler.get_extension_type')
86+
mocked_time = mocker.patch('connect.eaas.managers.background.time')
87+
mocked_time.sleep = time.sleep
88+
mocked_time.monotonic.side_effect = (1.0, 2.0)
8189
handler = ExtensionHandler(config)
8290
handler.extension_class = extension_cls(TASK_TYPE_EXT_METHOD_MAP[task_type], async_impl=True)
8391
handler.extension_type = 'async'
@@ -91,6 +99,7 @@ async def test_async(mocker, extension_cls, task_type, config_payload):
9199
TaskCategory.BACKGROUND,
92100
task_type,
93101
'PR-000',
102+
runtime=1.0,
94103
)
95104

96105
await manager.submit(task)
@@ -970,11 +979,14 @@ async def test_build_response_exception(mocker, task_payload):
970979
async def test_send_skip_response(mocker, task_payload):
971980
config = ConfigHelper()
972981
mocked_put = mocker.AsyncMock()
982+
mocked_time = mocker.patch('connect.eaas.managers.background.time')
983+
mocked_time.sleep = time.sleep
984+
mocked_time.monotonic.side_effect = (1.0, 2.0)
973985
manager = BackgroundTasksManager(config, None, mocked_put)
974986

975987
task = TaskPayload(
976988
**task_payload(
977-
TaskCategory.BACKGROUND, TaskType.PART_USAGE_FILE_REQUEST_PROCESSING, 'UFC-000',
989+
TaskCategory.BACKGROUND, TaskType.PART_USAGE_FILE_REQUEST_PROCESSING, 'UFC-000', 1.0,
978990
),
979991
)
980992

tests/managers/test_interactive.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
import pytest
45

@@ -43,6 +44,9 @@ async def test_validation_sync(mocker, extension_cls, task_type, config_payload)
4344
)
4445
mocker.patch('connect.eaas.handler.get_extension_class')
4546
mocker.patch('connect.eaas.handler.get_extension_type')
47+
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
48+
mocked_time.sleep = time.sleep
49+
mocked_time.monotonic.side_effect = (1.0, 2.0)
4650
handler = ExtensionHandler(config)
4751

4852
task_response_data = {'task': 'data', 'valid': True}
@@ -61,6 +65,7 @@ async def test_validation_sync(mocker, extension_cls, task_type, config_payload)
6165
TaskCategory.INTERACTIVE,
6266
task_type,
6367
'ID-000',
68+
runtime=1.0,
6469
)
6570

6671
task.data = {'task': 'data'}
@@ -89,6 +94,9 @@ async def test_validation_async(mocker, extension_cls, task_type, config_payload
8994
)
9095
mocker.patch('connect.eaas.handler.get_extension_class')
9196
mocker.patch('connect.eaas.handler.get_extension_type')
97+
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
98+
mocked_time.sleep = time.sleep
99+
mocked_time.monotonic.side_effect = (1.0, 2.0)
92100
handler = ExtensionHandler(config)
93101

94102
task_response_data = {'task': 'data', 'valid': True}
@@ -108,6 +116,7 @@ async def test_validation_async(mocker, extension_cls, task_type, config_payload
108116
TaskCategory.INTERACTIVE,
109117
task_type,
110118
'ID-000',
119+
runtime=1.0,
111120
)
112121

113122
task.data = {'task': 'data'}
@@ -145,6 +154,9 @@ async def test_others_sync(mocker, extension_cls, task_type, result, config_payl
145154
)
146155
mocker.patch('connect.eaas.handler.get_extension_class')
147156
mocker.patch('connect.eaas.handler.get_extension_type')
157+
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
158+
mocked_time.sleep = time.sleep
159+
mocked_time.monotonic.side_effect = (1.0, 2.0)
148160
handler = ExtensionHandler(config)
149161

150162
handler.extension_class = extension_cls(
@@ -161,6 +173,7 @@ async def test_others_sync(mocker, extension_cls, task_type, result, config_payl
161173
TaskCategory.INTERACTIVE,
162174
task_type,
163175
'ID-000',
176+
runtime=1.0,
164177
)
165178

166179
task.data = {'task': 'data'}
@@ -202,6 +215,9 @@ async def test_others_async(mocker, extension_cls, task_type, result, config_pay
202215
)
203216
mocker.patch('connect.eaas.handler.get_extension_class')
204217
mocker.patch('connect.eaas.handler.get_extension_type')
218+
mocked_time = mocker.patch('connect.eaas.managers.interactive.time')
219+
mocked_time.sleep = time.sleep
220+
mocked_time.monotonic.side_effect = (1.0, 2.0)
205221
handler = ExtensionHandler(config)
206222

207223
handler.extension_class = extension_cls(
@@ -219,6 +235,7 @@ async def test_others_async(mocker, extension_cls, task_type, result, config_pay
219235
TaskCategory.INTERACTIVE,
220236
task_type,
221237
'ID-000',
238+
runtime=1.0,
222239
)
223240

224241
task.data = {'task': 'data'}

tests/managers/test_scheduled.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
import pytest
45

@@ -24,6 +25,9 @@ async def test_sync(mocker, extension_cls, config_payload):
2425
config.update_dynamic_config(ConfigurationPayload(**config_payload))
2526
mocker.patch('connect.eaas.handler.get_extension_class')
2627
mocker.patch('connect.eaas.handler.get_extension_type')
28+
mocked_time = mocker.patch('connect.eaas.managers.scheduled.time')
29+
mocked_time.sleep = time.sleep
30+
mocked_time.monotonic.side_effect = (1.0, 2.0)
2731
handler = ExtensionHandler(config)
2832
handler.extension_class = extension_cls(
2933
'my_sync_schedulable_method',
@@ -42,6 +46,7 @@ async def test_sync(mocker, extension_cls, config_payload):
4246
TaskCategory.SCHEDULED,
4347
TaskType.SCHEDULED_EXECUTION,
4448
'EFS-000',
49+
runtime=1.0,
4550
)
4651

4752
await manager.submit(task)
@@ -58,6 +63,9 @@ async def test_async(mocker, extension_cls, config_payload):
5863
config.update_dynamic_config(ConfigurationPayload(**config_payload))
5964
mocker.patch('connect.eaas.handler.get_extension_class')
6065
mocker.patch('connect.eaas.handler.get_extension_type')
66+
mocked_time = mocker.patch('connect.eaas.managers.scheduled.time')
67+
mocked_time.sleep = time.sleep
68+
mocked_time.monotonic.side_effect = (1.0, 2.0)
6169
handler = ExtensionHandler(config)
6270
handler.extension_class = extension_cls(
6371
'my_async_schedulable_method',
@@ -77,6 +85,7 @@ async def test_async(mocker, extension_cls, config_payload):
7785
TaskCategory.SCHEDULED,
7886
TaskType.SCHEDULED_EXECUTION,
7987
'EFS-000',
88+
runtime=1.0,
8089
)
8190

8291
await manager.submit(task)

0 commit comments

Comments
 (0)