Skip to content

Commit 738e024

Browse files
authored
Handle null bot name correctly when trying to find region in monitoring (#4592)
This fixes the following error in app engine crons: ``` Failed to flush metrics: expected string or bytes-like object, got 'NoneType' Traceback (most recent call last): File "/layers/google.python.runtime/python/lib/python3.11/threading.py", line 1002, in _bootstrap self._bootstrap_inner() File "/layers/google.python.runtime/python/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() File "/layers/google.python.runtime/python/lib/python3.11/threading.py", line 982, in run self._target(*self._args, **self._kwargs) File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 171, in _flush_loop self._flush_function() File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 134, in _flush_metrics logs.error(f'Failed to flush metrics: {e}') LogError: Failed to flush metrics: expected string or bytes-like object, got 'NoneType' Traceback (most recent call last): File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 118, in _flush_metrics metric.monitoring_v3_time_series(series, labels, start_time, end_time, File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 343, in monitoring_v3_time_series self.monitoring_v3_metric(time_series.metric, labels) File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 321, in monitoring_v3_metric metric.labels['region'] = _get_region(bot_name) ^^^^^^^^^^^^^^^^^^^^^ File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 637, in _get_region if re.match(pattern['pattern'], bot_name): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/layers/google.python.runtime/python/lib/python3.11/re/__init__.py", line 166, in match return _compile(pattern, flags).match(string) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: expected string or bytes-like object, got 'NoneType' ```
1 parent 4c364a1 commit 738e024

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/clusterfuzz/_internal/cron/triage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ def main():
493493
else:
494494
_set_testcase_stuck_state(testcase, False)
495495
logs.info(
496-
f'Skipping testcase {testcase_id}, since the crash is not important.'
497-
)
496+
f'Skipping testcase {testcase_id}, as the crash is not important.')
498497
continue
499498

500499
# Require that all tasks like minimizaton, regression testing, etc have

src/clusterfuzz/_internal/metrics/monitor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ def monitoring_v3_metric(self, metric, labels=None):
313313
for key, value in labels.items():
314314
metric.labels[key] = str(value)
315315

316-
if not environment.is_running_on_k8s():
317-
bot_name = environment.get_value('BOT_NAME', None)
318-
metric.labels['region'] = _get_region(bot_name)
316+
bot_name = environment.get_value('BOT_NAME', None)
317+
metric.labels['region'] = _get_region(bot_name)
319318

320319
return metric
321320

@@ -625,6 +624,9 @@ def metrics_store():
625624

626625
def _get_region(bot_name):
627626
"""Get bot region."""
627+
if not bot_name:
628+
return 'unknown'
629+
628630
try:
629631
regions = local_config.MonitoringRegionsConfig()
630632
except errors.BadConfigError:

0 commit comments

Comments
 (0)