mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
First jab at ingesting loads of example data
This commit is contained in:
0
ingest/management/__init__.py
Normal file
0
ingest/management/__init__.py
Normal file
0
ingest/management/commands/__init__.py
Normal file
0
ingest/management/commands/__init__.py
Normal file
35
ingest/management/commands/send_json.py
Normal file
35
ingest/management/commands/send_json.py
Normal 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))
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user