Skip to content

feat: FilestoreNodeStorage #82125

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/sentry/nodestore/filestore/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .backend import FilestoreNodeStorage # NOQA
62 changes: 62 additions & 0 deletions src/sentry/nodestore/filestore/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import datetime
import logging
from io import BytesIO

from django.conf import settings

from sentry import options as options_store
from sentry.models.file import get_storage
from sentry.nodestore.base import NodeStorage

logger = logging.getLogger("sentry.nodestore")

class FilestoreNodeStorage(NodeStorage):
"""
A backend that persist nodes to configured File Store.
Intended for "s3" or "gcs", which performnace may not be ideal.
config.yml Configuration reference:
>>> filestore.backend: "s3"
... filestore.options:
... access_key: "xxx"
... secret_key: "xxx"
... endpoint_url: "https://s3.us-east-1.amazonaws.com"
... bucket_name: "sentry"
... location: "/sentry"
"""

def __init__(self, prefix_path=None):
self.prefix_path: str = "nodestore/"
backend = options_store.get("filestore.backend")
if backend not in ["s3", "gcs"]:
logger.warning("FilestoreNodeStorage was intended for s3 or gcs, currently using: %s", backend)
if prefix_path:
self.prefix_path = prefix_path

def _get_bytes(self, id: str):
storage = get_storage()
path = self.node_path(id)
return storage.open(path).read()

def _set_bytes(self, id: str, data: bytes, ttl=0):
storage = get_storage()
path = self.node_path(id)
storage.save(path, BytesIO(data))

def delete(self, id):
storage = get_storage()
path = self.node_path(id)
storage.delete(path)

def cleanup(self, cutoff: datetime.datetime):
"""
This driver does not have managed TTLs. To enable TTLs you will need to enable it on your
bucket.
"""
raise NotImplementedError

def bootstrap(self):
# Nothing for this backend to do during bootstrap
pass

def node_path(self, id: str):
return f"{self.prefix_path}{id}.json"
Loading