Browse Source

Partial indexes for api_check.alert_after and api_flip.processed fields.

pull/272/head
Pēteris Caune 5 years ago
parent
commit
033d0ab197
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 60 additions and 1 deletions
  1. +37
    -0
      hc/api/migrations/0062_auto_20190720_1350.py
  2. +23
    -1
      hc/api/models.py

+ 37
- 0
hc/api/migrations/0062_auto_20190720_1350.py View File

@ -0,0 +1,37 @@
# Generated by Django 2.2.3 on 2019-07-20 13:50
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('api', '0061_webhook_values'),
]
operations = [
migrations.AlterField(
model_name='channel',
name='kind',
field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('pagerteam', 'Pager Team'), ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk'), ('trello', 'Trello'), ('matrix', 'Matrix'), ('whatsapp', 'WhatsApp')], max_length=20),
),
migrations.AlterField(
model_name='flip',
name='processed',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name='tokenbucket',
name='updated',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AddIndex(
model_name='check',
index=models.Index(condition=models.Q(_negated=True, status='down'), fields=['alert_after'], name='api_check_aa_not_down'),
),
migrations.AddIndex(
model_name='flip',
index=models.Index(condition=models.Q(processed=None), fields=['processed'], name='api_flip_not_processed'),
),
]

+ 23
- 1
hc/api/models.py View File

@ -74,6 +74,17 @@ class Check(models.Model):
alert_after = models.DateTimeField(null=True, blank=True, editable=False) alert_after = models.DateTimeField(null=True, blank=True, editable=False)
status = models.CharField(max_length=6, choices=STATUSES, default="new") status = models.CharField(max_length=6, choices=STATUSES, default="new")
class Meta:
indexes = [
# Index for the alert_after field. Excludes rows with status=down.
# Used in the sendalerts management command.
models.Index(
fields=["alert_after"],
name="api_check_aa_not_down",
condition=~models.Q(status="down"),
)
]
def __str__(self): def __str__(self):
return "%s (%d)" % (self.name or self.code, self.id) return "%s (%d)" % (self.name or self.code, self.id)
@ -640,10 +651,21 @@ class Notification(models.Model):
class Flip(models.Model): class Flip(models.Model):
owner = models.ForeignKey(Check, models.CASCADE) owner = models.ForeignKey(Check, models.CASCADE)
created = models.DateTimeField() created = models.DateTimeField()
processed = models.DateTimeField(null=True, blank=True, db_index=True)
processed = models.DateTimeField(null=True, blank=True)
old_status = models.CharField(max_length=8, choices=STATUSES) old_status = models.CharField(max_length=8, choices=STATUSES)
new_status = models.CharField(max_length=8, choices=STATUSES) new_status = models.CharField(max_length=8, choices=STATUSES)
class Meta:
indexes = [
# For quickly looking up unprocessed flips.
# Used in the sendalerts management command.
models.Index(
fields=["processed"],
name="api_flip_not_processed",
condition=models.Q(processed=None),
)
]
def send_alerts(self): def send_alerts(self):
if self.new_status == "up" and self.old_status in ("new", "paused"): if self.new_status == "up" and self.old_status in ("new", "paused"):
# Don't send alerts on new->up and paused->up transitions # Don't send alerts on new->up and paused->up transitions


Loading…
Cancel
Save