Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New APIs for Promgen #578

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ django-filter==23.2
# via promgen (pyproject.toml)
djangorestframework==3.14.0
# via promgen (pyproject.toml)
drf-spectacular==0.28.0
# via promgen (pyproject.toml)
gunicorn==22.0.0
# via -r docker/requirements.in
idna==3.7
Expand Down
5 changes: 5 additions & 0 deletions promgen/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,8 @@ def has_add_permission(self, request, obj=None):

def has_change_permission(self, request, obj=None):
return False


@admin.register(models.SiteConfiguration)
class SiteConfigurationAdmin(admin.ModelAdmin):
list_display = ("key", "value")
209 changes: 207 additions & 2 deletions promgen/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import django_filters
from django.contrib.contenttypes.models import ContentType

from promgen import models


class ShardFilter(django_filters.rest_framework.FilterSet):
Expand All @@ -22,5 +25,207 @@ class RuleFilter(django_filters.rest_framework.FilterSet):


class FarmFilter(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(field_name="name", lookup_expr="contains")
source = django_filters.CharFilter(field_name="source", lookup_expr="exact")
name = django_filters.CharFilter(
field_name="name",
lookup_expr="contains",
help_text="Filter by farm name containing a specific substring. Example: name=Example Farm",
)
source = django_filters.ChoiceFilter(
field_name="source",
choices=[(name, name) for name, _ in models.Farm.driver_set()],
lookup_expr="exact",
help_text="Filter by exact source name. Example: source=promgen",
)


class UserFilter(django_filters.rest_framework.FilterSet):
username = django_filters.CharFilter(
field_name="username",
lookup_expr="contains",
help_text="Filter by username containing a specific substring. Example: username=Example Username",
)
email = django_filters.CharFilter(
field_name="email",
lookup_expr="contains",
help_text="Filter by email containing a specific substring. Example: [email protected]",
)


def filter_content_type(queryset, name, value):
try:
content_type_id = ContentType.objects.get(model=value, app_label="promgen").id
return queryset.filter(content_type_id=content_type_id)
except ContentType.DoesNotExist:
return queryset.none()


class AuditFilter(django_filters.rest_framework.FilterSet):
object_id = django_filters.NumberFilter(
field_name="object_id",
lookup_expr="exact",
help_text="Filter by exact object ID. Example: object_id=123",
)
content_type = django_filters.ChoiceFilter(
field_name="content_type",
choices=[
("service", "Service"),
("project", "Project"),
("rule", "Rule"),
("sender", "Notifier"),
("exporter", "Exporter"),
("url", "URL"),
("farm", "Farm"),
("host", "Host"),
],
method=filter_content_type,
help_text="Filter by content type model name. Example: content_type=service",
)
user = django_filters.CharFilter(
field_name="user__username",
lookup_expr="exact",
help_text="Filter by exact owner username. Example: owner=Example Owner",
)


class NotifierFilter(django_filters.rest_framework.FilterSet):
sender = django_filters.ChoiceFilter(
field_name="sender",
choices=[(module_name, module_name) for module_name, _ in models.Sender.driver_set()],
help_text="Filter by sender type. Example: sender=promgen.notification.email",
)
value = django_filters.CharFilter(
field_name="value",
lookup_expr="contains",
help_text="Filter by value containing a specific substring. Example: [email protected]",
)
object_id = django_filters.NumberFilter(
field_name="object_id",
lookup_expr="exact",
help_text="Filter by exact object ID. Example: object_id=123",
)
content_type = django_filters.ChoiceFilter(
field_name="content_type",
choices=[
("service", "Service"),
("project", "Project"),
],
method=filter_content_type,
help_text="Filter by content type model name. Example: content_type=service",
)
owner = django_filters.CharFilter(
field_name="owner__username",
lookup_expr="exact",
help_text="Filter by exact owner username. Example: owner=Example Owner",
)


class RuleFilterV2(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(
field_name="name",
lookup_expr="contains",
help_text="Filter by rule name containing a specific substring. Example: name=Example Rule",
)
parent = django_filters.CharFilter(
field_name="parent__name",
lookup_expr="contains",
help_text="Filter by parent rule name containing a specific substring. Example: parent=Example Parent",
)
enabled = django_filters.BooleanFilter(
field_name="enabled",
help_text="Filter by enabled status (true or false). Example: enabled=true",
)
object_id = django_filters.NumberFilter(
field_name="object_id",
lookup_expr="exact",
help_text="Filter by exact object ID. Example: object_id=123",
)
content_type = django_filters.ChoiceFilter(
field_name="content_type",
choices=[
("service", "Service"),
("project", "Project"),
("site", "Site"),
],
method=filter_content_type,
help_text="Filter by content type model name. Example: content_type=service",
)


class ExporterFilter(django_filters.rest_framework.FilterSet):
project = django_filters.CharFilter(
field_name="project__name",
lookup_expr="contains",
help_text="Filter by project name containing a specific substring. Example: project=Example Project",
)
job = django_filters.CharFilter(
field_name="job",
lookup_expr="contains",
help_text="Filter by job name containing a specific substring. Example: job=prometheus",
)
path = django_filters.CharFilter(
field_name="path",
lookup_expr="contains",
help_text="Filter by path containing a specific substring. Example: path=/metrics",
)
scheme = django_filters.ChoiceFilter(
field_name="scheme",
choices=[
("http", "HTTP"),
("https", "HTTPS"),
],
lookup_expr="exact",
help_text="Filter by exact scheme. Example: scheme=http",
)
enabled = django_filters.BooleanFilter(
field_name="enabled",
help_text="Filter by enabled status (true or false). Example: enabled=true",
)


class URLFilter(django_filters.rest_framework.FilterSet):
project = django_filters.CharFilter(
field_name="project__name",
lookup_expr="contains",
help_text="Filter by project name containing a specific substring. Example: project=Example Project",
)
probe = django_filters.ChoiceFilter(
field_name="probe__module",
choices=models.Probe.objects.values_list("module", "description").distinct(),
help_text="Filter by exact probe scheme. Example: probe=http_2xx",
)


class ProjectFilterV2(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(
field_name="name",
lookup_expr="contains",
help_text="Filter by project name containing a specific substring. Example: name=Example Project",
)
service = django_filters.CharFilter(
field_name="service__name",
lookup_expr="exact",
help_text="Filter by exact service name. Example: service=Example Service",
)
shard = django_filters.CharFilter(
field_name="shard__name",
lookup_expr="exact",
help_text="Filter by exact shard name. Example: shard=Example Shard",
)
owner = django_filters.CharFilter(
field_name="owner__username",
lookup_expr="exact",
help_text="Filter by exact owner username. Example: owner=Example Owner",
)


class ServiceFilterV2(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(
field_name="name",
lookup_expr="contains",
help_text="Filter by service name containing a specific substring. Example: name=Example Service",
)
owner = django_filters.CharFilter(
field_name="owner__username",
lookup_expr="exact",
help_text="Filter by exact owner username. Example: owner=Example Owner",
)
Loading
Loading