Skip to content

Commit

Permalink
feat(api): log queries for test instance (#2796)
Browse files Browse the repository at this point in the history
We're seeing some 502 and 504 errors reported from API queries. Without
the details of each query, it's hard to reproduce and find the root
causes.
Adds logs for the test instance. It does not record actual user queries,
only queries from our load tests.
  • Loading branch information
hogo6002 authored Oct 28, 2024
1 parent 3d3b021 commit aa90a59
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gcp/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
# Prefix for the
_TAG_PREFIX = "refs/tags/"

_TEST_INSTANCE = 'oss-vdb-test'

# ----
# Type Aliases:

Expand Down Expand Up @@ -200,6 +202,10 @@ def QueryAffected(self, request, context: grpc.ServicerContext):
else:
logging.info('QueryAffected for %s', qtype)

# Log queries for test instance.
# This is for debugging purposes. Production queries will not be recorded.
if get_gcp_project() == _TEST_INSTANCE:
logging.info('Query: %s', request.query)
try:
page_token = QueryCursor.from_page_token(request.query.page_token)
except ValueError as e:
Expand Down Expand Up @@ -284,6 +290,10 @@ def QueryAffectedBatch(self, request, context: grpc.ServicerContext):
extra={'json_fields': {
'details': query_details
}})
# Log queries for test instance.
# This is for debugging purposes. Production queries will not be recorded.
if get_gcp_project() == _TEST_INSTANCE:
logging.info('Batch query: %s', request.query)

if len(request.query.queries) > _MAX_BATCH_QUERY:
context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Too many queries.')
Expand Down

0 comments on commit aa90a59

Please sign in to comment.