Skip to content

Commit 8eaf0ac

Browse files
authored
Merge branch 'master' into no_space_left
2 parents 539f480 + 28e1d2a commit 8eaf0ac

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,15 @@ def __exit__(self, exc_type, value, traceback):
425425
'timeout': self.timeout,
426426
'platform': environment.platform(),
427427
'is_batch': environment.is_uworker(),
428+
'runtime': environment.get_runtime().value,
428429
})
429430
monitoring_metrics.JOB_TOTAL_FUZZ_TIME.increment_by(
430431
int(duration), {
431432
'job': self.job_type,
432433
'timeout': self.timeout,
433434
'platform': environment.platform(),
434-
'is_batch': environment.is_uworker()
435+
'is_batch': environment.is_uworker(),
436+
'runtime': environment.get_runtime().value
435437
})
436438

437439

src/clusterfuzz/_internal/metrics/monitoring_metrics.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@
146146
monitor.StringField('fuzzer'),
147147
monitor.BooleanField('timeout'),
148148
monitor.StringField('platform'),
149-
monitor.StringField('is_batch')
149+
# Even this label is duplicated with "runtime"
150+
# we are keeping it to avoid missing the historical metrics.
151+
monitor.StringField('is_batch'),
152+
monitor.StringField('runtime')
150153
],
151154
)
152155

@@ -171,7 +174,10 @@
171174
monitor.StringField('job'),
172175
monitor.BooleanField('timeout'),
173176
monitor.StringField('platform'),
174-
monitor.StringField('is_batch')
177+
# Even this label is duplicated with "runtime"
178+
# we are keeping it to avoid missing the historical metrics.
179+
monitor.StringField('is_batch'),
180+
monitor.StringField('runtime')
175181
],
176182
)
177183

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ def _test(self, timeout):
215215
'fuzzer': 'fuzzer',
216216
'timeout': timeout,
217217
'platform': 'some_platform',
218-
'is_batch': environment.is_uworker()
218+
'is_batch': environment.is_uworker(),
219+
'runtime': environment.get_runtime().value,
219220
})
220221
self.assertEqual(5, fuzzer_total_time)
221222

0 commit comments

Comments
 (0)