-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ignore user_agent ability
- Loading branch information
Showing
12 changed files
with
297 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
"""Celery Metrics.""" | ||
from collections import Counter | ||
from typing import TYPE_CHECKING | ||
from typing import TYPE_CHECKING, Union | ||
|
||
from controller.sentry.utils import depth | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from controller.sentry.models import App | ||
|
||
|
||
def celery_merger(app: "App", new: dict[str, int]) -> None: | ||
def celery_merger(app: "App", new: Union[dict[str, int], dict[str, dict[str, int]]]) -> None: | ||
"""celery_merger function is used to merge :attr:`Celery <controller.sentry.choices.MetricType.CELERY>` metrics. | ||
Args: | ||
app (App): The app associated to the metric | ||
new (dict[str, int]): The new metric dict | ||
""" | ||
app.celery_metrics = dict(Counter(app.celery_metrics) + Counter(new)) | ||
# Code for Migration | ||
if depth(app.celery_metrics) == 1: | ||
app.celery_metrics = {"task": app.celery_metrics} | ||
|
||
if depth(new) == 1: | ||
new = {"task": new} | ||
# End of migration code | ||
|
||
if app.celery_metrics is None: | ||
app.celery_metrics = {} | ||
|
||
tmp = {} | ||
for key in set(list(app.celery_metrics.keys()) + list(new.keys())): | ||
old_value = app.celery_metrics.get(key) | ||
new_value = new.get(key) | ||
tmp[key] = dict(Counter(old_value) + Counter(new_value)) | ||
|
||
app.celery_metrics = tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
"""Wsgi Metrics.""" | ||
from collections import Counter | ||
from typing import TYPE_CHECKING | ||
from typing import TYPE_CHECKING, Union | ||
|
||
from controller.sentry.utils import depth | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from controller.sentry.models import App | ||
|
||
|
||
def wsgi_merger(app: "App", new: dict[str, int]) -> None: | ||
def wsgi_merger(app: "App", new: Union[dict[str, int], dict[str, dict[str, int]]]) -> None: | ||
"""wsgi_merger function is used to merge :attr:`WSGI <controller.sentry.choices.MetricType.WSGI>` metrics. | ||
Args: | ||
app (App): The app associated to the metric | ||
new (dict[str, int]): The new metric dict | ||
""" | ||
app.wsgi_metrics = dict(Counter(app.wsgi_metrics) + Counter(new)) | ||
# Code for Migration | ||
if depth(app.wsgi_metrics) == 1: | ||
app.wsgi_metrics = {"path": app.wsgi_metrics} | ||
|
||
if depth(new) == 1: | ||
new = {"path": new} | ||
# End of migration code | ||
|
||
if app.wsgi_metrics is None: | ||
app.wsgi_metrics = {} | ||
|
||
tmp = {} | ||
for key in set(list(app.wsgi_metrics.keys()) + list(new.keys())): | ||
old_value = app.wsgi_metrics.get(key) | ||
new_value = new.get(key) | ||
tmp[key] = dict(Counter(old_value) + Counter(new_value)) | ||
|
||
app.wsgi_metrics = tmp |
43 changes: 43 additions & 0 deletions
43
controller/sentry/migrations/0015_app_wsgi_ignore_user_agent_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.2 on 2023-05-28 14:20 | ||
|
||
import functools | ||
|
||
import django_better_admin_arrayfield.models.fields | ||
from django.db import migrations, models | ||
|
||
import controller.sentry.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("sentry", "0014_alter_app_celery_collect_metrics_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="app", | ||
name="wsgi_ignore_user_agent", | ||
field=django_better_admin_arrayfield.models.fields.ArrayField( | ||
base_field=models.CharField(blank=True, max_length=50), | ||
blank=True, | ||
default=functools.partial( | ||
controller.sentry.models.settings_default_value, *("DEFAULT_WSGI_IGNORE_USER_AGENT",), **{} | ||
), | ||
help_text="A list of user agent to ignore, matched with startswith", | ||
size=None, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="app", | ||
name="wsgi_ignore_path", | ||
field=django_better_admin_arrayfield.models.fields.ArrayField( | ||
base_field=models.CharField(blank=True, max_length=50), | ||
blank=True, | ||
default=functools.partial( | ||
controller.sentry.models.settings_default_value, *("DEFAULT_WSGI_IGNORE_PATHS",), **{} | ||
), | ||
help_text="A list of path to ignore, matched using fill match ==", | ||
size=None, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,8 @@ | |
|
||
DEFAULT_WSGI_IGNORE_PATHS = os.getenv("DEFAULT_WSGI_IGNORE_PATHS", "/health,/healthz,/health/,/healthz/").split(",") | ||
|
||
DEFAULT_WSGI_IGNORE_USER_AGENT = os.getenv("DEFAULT_WSGI_IGNORE_USER_AGENT", "kube-probe/").split(",") | ||
|
||
|
||
DEFAULT_CELERY_IGNORE_TASKS = [] | ||
|
||
|
@@ -338,7 +340,7 @@ | |
|
||
ENVIRONMENT = os.getenv("ENV", "production") | ||
sentry_sdk.init( | ||
dsn="https://[email protected]/4504617124888576", | ||
dsn=SENTRY_DSN, | ||
environment=ENVIRONMENT, | ||
) | ||
|
||
|
Oops, something went wrong.