First jab at ingesting loads of example data

This commit is contained in:
Klaas van Schelven
2023-11-10 19:50:42 +01:00
parent 3b5d50603e
commit 3ca27a43d5
7 changed files with 58 additions and 2 deletions

View File

View File

View File

@@ -0,0 +1,35 @@
import json
import requests
from django.core.management.base import BaseCommand
from compat.dsn import get_store_url, get_header_value
class Command(BaseCommand):
help = "..."
def add_arguments(self, parser):
parser.add_argument("--dsn")
parser.add_argument("json_files", nargs="+")
def handle(self, *args, **options):
dsn = options['dsn']
for json_filename in options["json_files"]:
with open(json_filename) as f:
print("HIER", json_filename)
try:
data = json.loads(f.read())
except Exception as e:
self.stderr.write("%s %s %s" % ("Not JSON", json_filename, str(e)))
try:
response = requests.post(
get_store_url(dsn),
headers={"X-Sentry-Auth": get_header_value(dsn)},
json=data,
)
response.raise_for_status()
except Exception as e:
self.stderr.write("%s %s" % ("foo", e))

View File

@@ -60,6 +60,7 @@ class BaseIngestAPIView(APIView):
hash_ = get_hash_for_data(event_data)
issue, _ = Issue.objects.get_or_create(
project=project,
hash=hash_,
)
issue.events.add(event)

View File

@@ -6,9 +6,15 @@ from .models import Issue
@admin.register(Issue)
class IssueAdmin(admin.ModelAdmin):
list_display = [
"title",
"hash",
"project",
"event_count", # expensive operation as written now (query in loop)
]
list_filter = [
"project",
]
exclude = ["events"]
readonly_fields = [

View File

@@ -22,5 +22,15 @@ class Issue(models.Model):
def title(self):
# TODO: refactor to a (filled-on-create) field
parsed_data = json.loads(self.events.first().data)
foo = parsed_data["exception"]["values"][0]
return foo["type"] + ": " + foo["value"]
exc = parsed_data.get("exception", {})
if "values" in exc:
values = exc["values"]
else:
values = exc
if isinstance(values, list):
first_value = values[0] if values else {}
else:
first_value = values
return first_value.get("type", "none") + ": " + first_value.get("value", "none")

View File

@@ -30,3 +30,7 @@ class Project(models.Model):
def __str__(self):
return self.name
def get_dsn(self):
# TODO, because the server needs to know its own address
return get_dsn()