Skip to content

Commit 87bfaea

Browse files
authored
Refactor and set http error to log an warning instead of error (#4953)
It does refact the update_task_enabled function, improving it's readability and move to log warning instead of error for http errors. This change aims to clean [this error group](https://pantheon.corp.google.com/errors/detail/CNqTgJD4sZORdg;time=PT1H;locations=global?project=google.com:clusterfuzz&e=-13802955&mods=logs_tg_prod) as the http error is expected for the cases where the metadata is not set and we have a default behavior for this case. Signed-off-by: Javan Lacerda <[email protected]>
1 parent 11b877c commit 87bfaea

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/clusterfuzz/_internal/system/environment.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,8 @@ def update_task_enabled() -> bool:
12071207
metadata_header = {"Metadata-Flavor": "Google"}
12081208
metadata_key = "update_task_enabled"
12091209

1210+
running_on_batch = bool(is_uworker())
1211+
12101212
try:
12111213
# Construct the full URL for your specific metadata key
12121214
response = requests.get(
@@ -1218,13 +1220,17 @@ def update_task_enabled() -> bool:
12181220
# The metadata value is in the response text
12191221
metadata_value = response.text
12201222
logs.info(f"The value for '{metadata_key}' is: {metadata_value}")
1221-
bool_metadata_value = metadata_value.lower() == 'true'
1223+
is_update_task_enabled = metadata_value.lower() != 'false'
12221224

12231225
# The flag is_uworker is true for Batch environment
12241226
# The update task should run if it's not a Batch environment
12251227
# and the flag is enabled on the VM template metadata
1226-
return not bool(is_uworker()) and bool_metadata_value
1227-
1228-
except Exception as e:
1229-
logs.error(f"Error fetching metadata: {e}")
1230-
return not bool(is_uworker())
1228+
return not running_on_batch and is_update_task_enabled
1229+
1230+
except requests.exceptions.HTTPError as http_error:
1231+
logs.warning(f"Http error fetching metadata: {http_error}")
1232+
1233+
except Exception as ex:
1234+
logs.error(f"Unknown exception fetching metadata: {ex}")
1235+
1236+
return not running_on_batch

0 commit comments

Comments
 (0)