Add project.ingested_event_count (input for performance-experiment)

This commit is contained in:
Klaas van Schelven
2024-07-16 15:48:16 +02:00
parent c01d332e18
commit 0c964cfcc8
4 changed files with 58 additions and 5 deletions
+11 -4
View File
@@ -356,10 +356,17 @@ class IngestEnvelopeAPIView(BaseIngestAPIView):
MaxDataReader("MAX_ENVELOPE_COMPRESSED_SIZE", request))))
envelope_headers = parser.get_envelope_headers()
if "dsn" in envelope_headers:
project = self.get_project(project_pk, get_sentry_key(envelope_headers["dsn"]))
else:
project = self.get_project_for_request(project_pk, request)
with immediate_atomic():
# the transaction goes around the whole of the Project.get-then-update, to ensure ingested_event_count is
# correctly updated. We release the transaction right after that (keep it as short as possible); the value
# is still used after that, but it is with a correct-in-time (i.e. time of ingestion) value.
if "dsn" in envelope_headers:
project = self.get_project(project_pk, get_sentry_key(envelope_headers["dsn"]))
else:
project = self.get_project_for_request(project_pk, request)
project.ingested_event_count += 1
print("Happens", project.ingested_event_count)
project.save()
if project.quota_exceeded_until is not None and now < project.quota_exceeded_until:
# Sentry has x-sentry-rate-limits, but for now 429 is just fine. Client-side this is implemented as a 60s
@@ -0,0 +1,18 @@
# Generated by Django 4.2.13 on 2024-07-16 13:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0004_project_quota_exceeded_until'),
]
operations = [
migrations.AddField(
model_name='project',
name='ingested_event_count',
field=models.PositiveIntegerField(default=0, editable=False),
),
]
@@ -0,0 +1,27 @@
# Generated by Django 4.2.13 on 2024-07-16 13:43
from django.db import migrations
def initial_ingested_count_value(apps, schema_editor):
Project = apps.get_model('projects', 'Project')
for project in Project.objects.all():
# this is the best guess we have; which should be good enough to avoid surprises on the small installed base.
project.ingested_event_count = project.event_set.count()
project.save()
class Migration(migrations.Migration):
dependencies = [
('events', '0010_rename_ingest_order_event_digest_order_and_more'),
('ingest', '0001_set_sqlite_wal'),
('issues', '0005_rename_ingest_order_issue_digest_order_and_more'),
('projects', '0005_project_ingested_event_count'),
('releases', '0001_initial'),
('teams', '0002_initial'),
]
operations = [
migrations.RunPython(initial_ingested_count_value),
]
+2 -1
View File
@@ -49,8 +49,9 @@ class Project(models.Model):
# > supplied, future versions of Sentry will entirely ignore it.
# private_key = ...
# denormalized/cached fields below
# denormalized/cached/counted fields below
has_releases = models.BooleanField(editable=False, default=False)
ingested_event_count = models.PositiveIntegerField(null=False, blank=False, default=0, editable=False)
# alerting conditions
alert_on_new_issue = models.BooleanField(default=True)