Skip to content

Commit

Permalink
[INTERNAL] Use Black to format #416
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Dec 14, 2022
2 parents 8873bd0 + 9425c16 commit 7b9dfa4
Show file tree
Hide file tree
Showing 52 changed files with 1,130 additions and 1,112 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# pyupgrade --py36-plus promgen/**/*.py
4d53038426aedf2abf337a2876d0d6ceccefc09b
# black
a81731039c118543398c90869e608dde0acaf32c
1 change: 0 additions & 1 deletion promgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@
)
except ImportError:
pass

78 changes: 39 additions & 39 deletions promgen/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FilterInline(admin.TabularInline):

@admin.register(models.Host)
class HostAdmin(admin.ModelAdmin):
list_display = ('name', 'farm')
list_display = ("name", "farm")


@admin.register(models.Shard)
Expand All @@ -36,54 +36,54 @@ class ShardAdmin(admin.ModelAdmin):

@admin.register(models.Service)
class ServiceAdmin(admin.ModelAdmin):
list_display = ('name', 'owner')
list_filter = (('owner', admin.RelatedOnlyFieldListFilter),)
list_select_related = ('owner',)
list_display = ("name", "owner")
list_filter = (("owner", admin.RelatedOnlyFieldListFilter),)
list_select_related = ("owner",)


@admin.register(models.Project)
class ProjectAdmin(admin.ModelAdmin):
list_display = ('name', 'shard', 'service', 'farm', 'owner')
list_select_related = ('service', 'farm', 'shard', 'owner')
list_filter = ('shard', ('owner', admin.RelatedOnlyFieldListFilter),)
list_display = ("name", "shard", "service", "farm", "owner")
list_select_related = ("service", "farm", "shard", "owner")
list_filter = ("shard", ("owner", admin.RelatedOnlyFieldListFilter))


class SenderForm(forms.ModelForm):
sender = forms.ChoiceField(choices=[
(entry.module_name, entry.module_name) for entry in plugins.notifications()
])
sender = forms.ChoiceField(
choices=[(entry.module_name, entry.module_name) for entry in plugins.notifications()]
)

class Meta:
model = models.Sender
exclude = ['content_object']
exclude = ["content_object"]


@admin.register(models.Sender)
class SenderAdmin(admin.ModelAdmin):
list_display = ('content_object', 'content_type', 'sender', 'show_value', 'owner')
list_display = ("content_object", "content_type", "sender", "show_value", "owner")
form = SenderForm
list_filter = ('sender', 'content_type')
list_select_related = ('content_type',)
list_filter = ("sender", "content_type")
list_select_related = ("content_type",)
inlines = [FilterInline]


@admin.register(models.Farm)
class FarmAdmin(admin.ModelAdmin):
list_display = ('name', 'source')
list_filter = ('source',)
list_display = ("name", "source")
list_filter = ("source",)


@admin.register(models.Exporter)
class ExporterAdmin(admin.ModelAdmin):
list_display = ('job', 'port', 'path', 'project', 'enabled')
list_filter = ('job', 'port',)
readonly_fields = ('project',)
list_display = ("job", "port", "path", "project", "enabled")
list_filter = ("job", "port")
readonly_fields = ("project",)


@admin.register(models.DefaultExporter)
class DefaultExporterAdmin(admin.ModelAdmin):
list_display = ('job', 'port', 'path')
list_filter = ('job', 'port')
list_display = ("job", "port", "path")
list_filter = ("job", "port")


@admin.register(models.Probe)
Expand Down Expand Up @@ -114,14 +114,14 @@ class RuleAnnotationInline(admin.TabularInline):

@admin.register(models.Rule)
class RuleAdmin(admin.ModelAdmin):
list_display = ('name', 'clause', 'duration', 'content_object')
list_filter = ('duration',)
list_select_related = ('content_type',)
list_display = ("name", "clause", "duration", "content_object")
list_filter = ("duration",)
list_select_related = ("content_type",)
inlines = [RuleLabelInline, RuleAnnotationInline]

def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.prefetch_related('content_object',)
return qs.prefetch_related("content_object")


@admin.register(models.Prometheus)
Expand All @@ -145,9 +145,9 @@ def __getattr__(self, name):
def __get_label(label):
def __wrapped(instance):
try:
return instance.json['commonLabels'][label]
return instance.json["commonLabels"][label]
except KeyError:
return ''
return ""

# We give the wrapped function the same description as
# our label so that it shows up right in the admin panel
Expand All @@ -157,24 +157,24 @@ def __wrapped(instance):
if name in self.list_display:
return __get_label(name)

date_hierarchy = 'created'
date_hierarchy = "created"
list_display = (
'created',
'datasource',
'alertname',
'service',
'project',
'severity',
'job',
"created",
"datasource",
"alertname",
"service",
"project",
"severity",
"job",
)

fields = ('created', '_json')
readonly_fields = ('created', '_json')
ordering = ('-created',)
fields = ("created", "_json")
readonly_fields = ("created", "_json")
ordering = ("-created",)

@admin.display(description="json")
def _json(self, instance):
return format_html('<pre>{}</pre>', json.dumps(instance.json, indent=2))
return format_html("<pre>{}</pre>", json.dumps(instance.json, indent=2))

def has_add_permission(self, request, obj=None):
return False
Expand Down
17 changes: 9 additions & 8 deletions promgen/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ def default_admin(sender, interactive, **kwargs):
# Have to import here to ensure that the apps are already registered and
# we get a real model instead of __fake__.User
from django.contrib.auth.models import User

if User.objects.filter(is_superuser=True).count() == 0:
if interactive:
print(' Adding default admin user')
print(" Adding default admin user")
User.objects.create_user(
username='admin',
password='admin',
username="admin",
password="admin",
is_staff=True,
is_active=True,
is_superuser=True,
)
if interactive:
print('BE SURE TO UPDATE THE PASSWORD!!!')
print("BE SURE TO UPDATE THE PASSWORD!!!")


def default_shard(sender, apps, interactive, **kwargs):
Shard = apps.get_model('promgen.Shard')
Shard = apps.get_model("promgen.Shard")
if Shard.objects.count() == 0:
if interactive:
print(' Adding default shard')
print(" Adding default shard")
Shard.objects.create(
name='Default',
url='http://prometheus.example.com',
name="Default",
url="http://prometheus.example.com",
proxy=True,
enabled=True,
)
Expand Down
15 changes: 8 additions & 7 deletions promgen/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
# These sources are released under the terms of the MIT license: see LICENSE


FARM_DEFAULT = 'promgen'
FARM_DEFAULT = "promgen"


class DiscoveryBase:
remote = True

'''
"""
Basic discovery plugin base
Child classes should implement both fetch and farm methods
'''
"""

def fetch(self, farm):
'''
"""
Return list of hosts for farm
'''
"""
raise NotImplemented()

def farms(self):
'''
"""
Return a list of farm names
'''
"""
raise NotImplemented()
8 changes: 4 additions & 4 deletions promgen/discovery/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@


class DiscoveryPromgen(discovery.DiscoveryBase):
'''Promgen local database discovery plugin
"""Promgen local database discovery plugin
This is the default discovery plugin for farms and hosts stored locally in
promgen's database. They are queried directly from Django's ORM
'''
"""

remote = False

def fetch(self, farm_name):
'''Fetch list of hosts for a farm from the local database'''
"""Fetch list of hosts for a farm from the local database"""
farm = get_object_or_404(models.Farm, name=farm_name)
for host in models.Host.objects.filter(farm=farm):
yield host.name

def farms(self):
'''Fetch farms from local database'''
"""Fetch farms from local database"""
for farm in models.Farm.objects.filter(source=discovery.FARM_DEFAULT):
yield farm.name
12 changes: 3 additions & 9 deletions promgen/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ class ServiceFilter(django_filters.rest_framework.FilterSet):

class ProjectFilter(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(field_name="name", lookup_expr="contains")
service = django_filters.CharFilter(
field_name="service__name", lookup_expr="contains"
)
shard = django_filters.CharFilter(
field_name="shard__name", lookup_expr="contains"
)
service = django_filters.CharFilter(field_name="service__name", lookup_expr="contains")
shard = django_filters.CharFilter(field_name="shard__name", lookup_expr="contains")


class RuleFilter(django_filters.rest_framework.FilterSet):
name = django_filters.CharFilter(field_name="name", lookup_expr="contains")
parent = django_filters.CharFilter(
field_name="parent__name", lookup_expr="contains"
)
parent = django_filters.CharFilter(field_name="parent__name", lookup_expr="contains")
enabled = django_filters.BooleanFilter(field_name="enabled")
Loading

0 comments on commit 7b9dfa4

Please sign in to comment.