Skip to content

Commit 5c85789

Browse files
authored
fix(staging): make GCS 404 less noisy (#3805)
Calling `logging.exception` causes the error reporting dashboard to flag the log, even though 404s are sometimes expected (by e.g. GetByID for an invalid ID)
1 parent 0223374 commit 5c85789

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

gcp/api/server_new.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def async_poll_result():
203203
try:
204204
return f.result()
205205
except exceptions.NotFound:
206-
logging.error('Vulnerability %s not found in GCS', vuln_id)
206+
logging.error('Vulnerability %s matched query but not found in GCS',
207+
vuln_id)
207208
# TODO: send pub/sub message to reimport.
208209
return None
209210

osv/gcs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import os
1818

19+
from google.cloud import exceptions
1920
from google.cloud import storage
2021

2122
from .vulnerability_pb2 import Vulnerability
@@ -52,8 +53,12 @@ def get_by_id(vuln_id: str) -> Vulnerability:
5253
pb_blob = bucket.blob(os.path.join(VULN_PB_PATH, vuln_id + '.pb'))
5354
try:
5455
return Vulnerability.FromString(pb_blob.download_as_bytes())
56+
except exceptions.NotFound:
57+
# It's not necessarily an error if not found.
58+
logging.info('vulnerability %s not found in GCS', vuln_id)
59+
raise
5560
except:
56-
logging.exception('failed to download %s protobuf from GCS', vuln_id)
61+
logging.error('failed to download %s protobuf from GCS', vuln_id)
5762
raise
5863

5964

@@ -69,7 +74,7 @@ def get_by_id_with_generation(vuln_id: str) -> tuple[Vulnerability, int] | None:
6974
vuln = Vulnerability.FromString(pb_blob.download_as_bytes())
7075
return vuln, pb_blob.generation
7176
except:
72-
logging.exception('failed to download %s protobuf from GCS', vuln_id)
77+
logging.error('failed to download %s protobuf from GCS', vuln_id)
7378
raise
7479

7580

0 commit comments

Comments
 (0)