Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): set up google cloud profiler #2936

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 88 additions & 13 deletions gcp/api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gcp/api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ requests = "==2.32.3"
grpcio = "==1.64.1"
grpcio-reflection = "==1.62.2"
grpcio-health-checking = "==1.62.2"
google-cloud-profiler = "==4.1.0"

osv = { path = "../../", develop = true }

Expand Down
9 changes: 9 additions & 0 deletions gcp/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

from gcp.api.cursor import QueryCursor

import googlecloudprofiler

_SHUTDOWN_GRACE_DURATION = 5

_MAX_SINGLE_QUERY_TIME = timedelta(seconds=20)
Expand Down Expand Up @@ -1395,6 +1397,13 @@ def main():
setup_gcp_logging('api-backend')
logging.getLogger().addFilter(trace_filter)

# Profiler initialization. It starts a daemon thread which continuously
# collects and uploads profiles. Best done as early as possible.
try:
googlecloudprofiler.start(service="osv-api-profiler")
cuixq marked this conversation as resolved.
Show resolved Hide resolved
except (ValueError, NotImplementedError) as e:
logging.error(e)

logging.getLogger().setLevel(logging.INFO)

parser = argparse.ArgumentParser(
Expand Down
Loading