Skip to content

Commit 6dcb12b

Browse files
committed
feat: metric controller
revamps metrics metric collection can now be enabled/disabled by controller
1 parent 540a79d commit 6dcb12b

14 files changed

+74
-198
lines changed

controller/sentry/admin.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
from django_object_actions import DjangoObjectActions, takes_instance_or_queryset
1313

1414
from controller.sentry.forms import BumpForm
15-
from controller.sentry.inlines import MetricsInline
16-
from controller.sentry.models import App, Metric
15+
from controller.sentry.models import App
1716

1817

1918
@admin.register(App)
@@ -39,6 +38,10 @@ class AppAdmin(
3938
]
4039
ordering = search_fields
4140

41+
formfield_overrides = {
42+
models.JSONField: {"widget": JSONEditorWidget},
43+
}
44+
4245
fieldsets = [
4346
[
4447
None,
@@ -52,19 +55,27 @@ class AppAdmin(
5255
],
5356
[
5457
"WSGI",
55-
{"fields": ("wsgi_ignore_path",)},
58+
{
59+
"classes": ("collapse", "open"),
60+
"fields": ("wsgi_ignore_path", "wsgi_collect_metrics", "wsgi_metrics"),
61+
},
5662
],
5763
[
5864
"Celery",
59-
{"fields": ("celery_ignore_task",)},
65+
{
66+
"classes": ("collapse", "open"),
67+
"fields": (
68+
"celery_ignore_task",
69+
"celery_collect_metrics",
70+
"celery_metrics",
71+
),
72+
},
6073
],
6174
]
6275

6376
changelist_actions = ["bump"]
6477
change_actions = ["bump"]
6578

66-
inlines = [MetricsInline]
67-
6879
@takes_instance_or_queryset
6980
@add_form_to_action(BumpForm)
7081
@confirm_action()
@@ -75,31 +86,3 @@ def bump(self, request, queryset, form: BumpForm = None):
7586
active_sample_rate=form.cleaned_data["new_sample_rate"],
7687
active_window_end=new_date,
7788
)
78-
79-
80-
@admin.register(Metric)
81-
class MetricAdmin(admin.ModelAdmin):
82-
formfield_overrides = {
83-
models.JSONField: {"widget": JSONEditorWidget},
84-
}
85-
86-
list_display = [
87-
"type",
88-
"last_updated",
89-
"app",
90-
]
91-
92-
search_fields = ["type", "last_updated", "app__reference"]
93-
ordering = search_fields
94-
95-
fieldsets = [
96-
[
97-
None,
98-
{
99-
"fields": (
100-
("type", "last_updated", "app"),
101-
"data",
102-
)
103-
},
104-
]
105-
]

controller/sentry/inlines.py

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import Counter
22

33

4-
def celery_merger(old, new):
5-
return dict(Counter(old) + Counter(new))
4+
def celery_merger(app, new):
5+
app.celery_metrics = dict(Counter(app.celery_metrics) + Counter(new))

controller/sentry/metrics/wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import Counter
22

33

4-
def wsgi_merger(old, new):
5-
return dict(Counter(old) + Counter(new))
4+
def wsgi_merger(app, new):
5+
app.wsgi_metrics = dict(Counter(app.wsgi_metrics) + Counter(new))

controller/sentry/migrations/0007_app_celery_ignore_task_alter_metric_type.py renamed to controller/sentry/migrations/0003_app_celery_ignore_task_app_celery_metrics_and_more.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.1.5 on 2023-01-09 08:13
1+
# Generated by Django 4.1.5 on 2023-01-11 08:08
22

33
import django_better_admin_arrayfield.models.fields
44
from django.db import migrations, models
@@ -9,7 +9,7 @@
99
class Migration(migrations.Migration):
1010

1111
dependencies = [
12-
("sentry", "0006_alter_metric_last_updated"),
12+
("sentry", "0002_app_wsgi_ignore_path_alter_app_reference"),
1313
]
1414

1515
operations = [
@@ -23,11 +23,14 @@ class Migration(migrations.Migration):
2323
size=None,
2424
),
2525
),
26-
migrations.AlterField(
27-
model_name="metric",
28-
name="type",
29-
field=models.CharField(
30-
choices=[("WSGI", "WSGI"), ("CELERY", "CELERY")], max_length=10
31-
),
26+
migrations.AddField(
27+
model_name="app",
28+
name="celery_metrics",
29+
field=models.JSONField(null=True),
30+
),
31+
migrations.AddField(
32+
model_name="app",
33+
name="wsgi_metrics",
34+
field=models.JSONField(null=True),
3235
),
3336
]

controller/sentry/migrations/0003_metric.py

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.1.5 on 2023-01-11 08:15
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("sentry", "0003_app_celery_ignore_task_app_celery_metrics_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="app",
15+
name="celery_collect_metrics",
16+
field=models.BooleanField(default=False),
17+
),
18+
migrations.AddField(
19+
model_name="app",
20+
name="wsgi_collect_metrics",
21+
field=models.BooleanField(default=False),
22+
),
23+
]

controller/sentry/migrations/0004_rename_timestamp_metric_last_updated.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

controller/sentry/migrations/0005_alter_metric_data.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

controller/sentry/migrations/0006_alter_metric_last_updated.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)