Skip to content

Commit 7ea19c4

Browse files
authored
Refactoring the fuzzing hours labels by moving from is_batch to runtime (#5079)
Fix b/469019068 It does update the fuzzing hours metrics to add KATA CONTAINER as a runtime. It removes the label `is_batch` and move it to the `runtime` label as `BATCH`. Signed-off-by: Javan Lacerda <[email protected]>
1 parent 39a9b8d commit 7ea19c4

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,14 @@ def __exit__(self, exc_type, value, traceback):
424424
'fuzzer': self.fuzzer_name,
425425
'timeout': self.timeout,
426426
'platform': environment.platform(),
427-
'is_batch': environment.is_uworker(),
427+
'runtime': environment.get_runtime().value,
428428
})
429429
monitoring_metrics.JOB_TOTAL_FUZZ_TIME.increment_by(
430430
int(duration), {
431431
'job': self.job_type,
432432
'timeout': self.timeout,
433433
'platform': environment.platform(),
434-
'is_batch': environment.is_uworker()
434+
'runtime': environment.get_runtime().value
435435
})
436436

437437

src/clusterfuzz/_internal/metrics/monitoring_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
monitor.StringField('fuzzer'),
147147
monitor.BooleanField('timeout'),
148148
monitor.StringField('platform'),
149-
monitor.StringField('is_batch')
149+
monitor.StringField('runtime')
150150
],
151151
)
152152

@@ -171,7 +171,7 @@
171171
monitor.StringField('job'),
172172
monitor.BooleanField('timeout'),
173173
monitor.StringField('platform'),
174-
monitor.StringField('is_batch')
174+
monitor.StringField('runtime')
175175
],
176176
)
177177

src/clusterfuzz/_internal/system/environment.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Environment functions."""
1515

1616
import ast
17+
import enum
1718
import functools
1819
import os
1920
import re
@@ -56,6 +57,13 @@
5657
}
5758

5859

60+
class UtaskMainRuntime(enum.Enum):
61+
62+
BATCH = 'batch'
63+
KATA_CONTAINER = 'kata_container'
64+
INSTANCE_GROUP = 'instance_group'
65+
66+
5967
def _eval_value(value_string):
6068
"""Returns evaluated value."""
6169
try:
@@ -726,6 +734,24 @@ def is_uworker():
726734
return get_value('UWORKER')
727735

728736

737+
def get_runtime() -> UtaskMainRuntime:
738+
"""
739+
Get the current runtime for running the tasks.
740+
It can be KATA_CONTAINER, BATCH or INSTANCE_GROUP.
741+
742+
:return: Enum UtaskMainRuntime with one of KATA_CONTAINER,
743+
BATCH or INSTANCE_GROUP
744+
:rtype: UtaskMainRuntime
745+
"""
746+
if is_uworker() and is_running_on_k8s():
747+
return UtaskMainRuntime.KATA_CONTAINER
748+
749+
if is_uworker() and not is_running_on_k8s():
750+
return UtaskMainRuntime.BATCH
751+
752+
return UtaskMainRuntime.INSTANCE_GROUP
753+
754+
729755
def is_swarming_bot():
730756
"""Return whether or not the current bot is a swarming bot."""
731757
return get_value('SWARMING_BOT')

src/clusterfuzz/_internal/tests/core/bot/tasks/utasks/fuzz_task_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def _test(self, timeout):
215215
'fuzzer': 'fuzzer',
216216
'timeout': timeout,
217217
'platform': 'some_platform',
218-
'is_batch': environment.is_uworker()
218+
'runtime': environment.get_runtime().value
219219
})
220220
self.assertEqual(5, fuzzer_total_time)
221221

0 commit comments

Comments
 (0)