-
Notifications
You must be signed in to change notification settings - Fork 299
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
remove deprecated backend code #2502
Changes from all commits
4af9510
1db4ef3
574829f
5100f98
6b6a009
1705e46
7ed2f68
3e7980a
547a0ff
83df306
22d8be9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 3.2.20 on 2023-07-11 15:32 | ||
|
||
from django.db import migrations, models | ||
import django_migration_linter as linter | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('alerts', '0019_auto_20230705_1619'), | ||
] | ||
|
||
operations = [ | ||
linter.IgnoreMigration(), | ||
migrations.RemoveField( | ||
model_name='alertgroup', | ||
name='active_cache_for_web_calculation_id', | ||
), | ||
migrations.RemoveField( | ||
model_name='alertgroup', | ||
name='estimate_escalation_finish_time', | ||
), | ||
migrations.RemoveField( | ||
model_name='alertgroup', | ||
name='cached_render_for_web', | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
from django.dispatch import receiver | ||
from django.utils import timezone | ||
from django.utils.functional import cached_property | ||
from django_deprecate_fields import deprecate_field | ||
|
||
from apps.alerts.constants import AlertGroupState | ||
from apps.alerts.escalation_snapshot import EscalationSnapshotMixin | ||
|
@@ -163,7 +162,7 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. | |
(USER, "user"), | ||
(NOT_YET, "not yet"), | ||
(LAST_STEP, "last escalation step"), | ||
(ARCHIVED, "archived"), | ||
(ARCHIVED, "archived"), # deprecated. don't use | ||
(WIPED, "wiped"), | ||
(DISABLE_MAINTENANCE, "stop maintenance"), | ||
(NOT_YET_STOP_AUTORESOLVE, "not yet, autoresolve disabled"), | ||
|
@@ -327,10 +326,6 @@ def status(self): | |
related_name="dependent_alert_groups", | ||
) | ||
|
||
# cached_render_for_web and active_cache_for_web_calculation_id are deprecated | ||
cached_render_for_web = models.JSONField(default=dict) | ||
active_cache_for_web_calculation_id = models.CharField(max_length=100, null=True, default=None) | ||
|
||
# NOTE: we should probably migrate this field to models.UUIDField as it's ONLY ever being | ||
# set to the result of uuid.uuid1 | ||
last_unique_unacknowledge_process_id: UUID | None = models.CharField(max_length=100, null=True, default=None) | ||
|
@@ -361,9 +356,6 @@ def status(self): | |
|
||
raw_escalation_snapshot = JSONField(null=True, default=None) | ||
|
||
# THIS FIELD IS DEPRECATED AND SHOULD EVENTUALLY BE REMOVED | ||
estimate_escalation_finish_time = deprecate_field(models.DateTimeField(null=True, default=None)) | ||
|
||
# This field is used for constraints so we can use get_or_create() in concurrent calls | ||
# https://docs.djangoproject.com/en/3.2/ref/models/querysets/#get-or-create | ||
# Combined with unique_together below, it allows only one alert group with | ||
|
@@ -715,38 +707,6 @@ def resolve_by_source(self): | |
for dependent_alert_group in self.dependent_alert_groups.all(): | ||
dependent_alert_group.resolve_by_source() | ||
|
||
# deprecated | ||
def resolve_by_archivation(self): | ||
AlertGroupLogRecord = apps.get_model("alerts", "AlertGroupLogRecord") | ||
# if incident was silenced, unsilence it without starting escalation | ||
if self.silenced: | ||
self.un_silence() | ||
self.log_records.create( | ||
type=AlertGroupLogRecord.TYPE_UN_SILENCE, | ||
silence_delay=None, | ||
reason="Resolve by archivation", | ||
) | ||
self.archive() | ||
self.stop_escalation() | ||
if not self.resolved: | ||
self.resolve(resolved_by=AlertGroup.ARCHIVED) | ||
|
||
log_record = self.log_records.create(type=AlertGroupLogRecord.TYPE_RESOLVED) | ||
|
||
logger.debug( | ||
f"send alert_group_action_triggered_signal for alert_group {self.pk}, " | ||
f"log record {log_record.pk} with type '{log_record.get_type_display()}', action source: archivation" | ||
) | ||
|
||
alert_group_action_triggered_signal.send( | ||
sender=self.resolve_by_archivation, | ||
log_record=log_record.pk, | ||
action_source=None, | ||
) | ||
|
||
for dependent_alert_group in self.dependent_alert_groups.all(): | ||
dependent_alert_group.resolve_by_archivation() | ||
|
||
Comment on lines
-719
to
-749
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
def check_alert_is_unarchived(self, slack_team_identity, payload, alert_group, warning=True):
alert_group_is_unarchived = alert_group.started_at.date() > self.organization.archive_alerts_from
if not alert_group_is_unarchived:
if warning:
warning_text = "Action is impossible: the Alert is archived."
self.open_warning_window(payload, warning_text)
if not alert_group.resolved or not alert_group.is_archived:
alert_group.resolve_by_archivation()
return alert_group_is_unarchived
this celery task was only ever queued by def update(self, instance, validated_data):
current_archive_date = instance.archive_alerts_from
archive_alerts_from = validated_data.get("archive_alerts_from")
result = super().update(instance, validated_data)
if archive_alerts_from is not None and current_archive_date != archive_alerts_from:
if current_archive_date > archive_alerts_from:
unarchive_incidents_for_organization.apply_async(
(instance.pk,),
)
resolve_archived_incidents_for_organization.apply_async(
(instance.pk,),
)
return result
|
||
def resolve_by_last_step(self): | ||
AlertGroupLogRecord = apps.get_model("alerts", "AlertGroupLogRecord") | ||
initial_state = self.state | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def resolve_alert_group_by_source_if_needed(alert_group_pk): | |
alert_group.save(update_fields=["resolved_by"]) | ||
if alert_group.resolved_by == alert_group.NOT_YET_STOP_AUTORESOLVE: | ||
return "alert_group is too big to auto-resolve" | ||
print("YOLO") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry @Konstantinov-Innokentii 😛 |
||
|
||
last_alert = AlertForAlertManager.objects.get(pk=alert_group.alerts.last().pk) | ||
if alert_group.is_alert_a_resolve_signal(last_alert): | ||
alert_group.resolve_by_source() | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,15 @@ | ||
import datetime | ||
from dataclasses import asdict | ||
|
||
import humanize | ||
import pytz | ||
from django.apps import apps | ||
from django.utils import timezone | ||
from rest_framework import fields, serializers | ||
from rest_framework import serializers | ||
|
||
from apps.base.models import LiveSetting | ||
from apps.phone_notifications.phone_provider import get_phone_provider | ||
from apps.slack.models import SlackTeamIdentity | ||
from apps.slack.tasks import resolve_archived_incidents_for_organization, unarchive_incidents_for_organization | ||
from apps.user_management.models import Organization | ||
from common.api_helpers.mixins import EagerLoadingMixin | ||
|
||
|
||
class CustomDateField(fields.TimeField): | ||
def to_internal_value(self, data): | ||
try: | ||
archive_datetime = datetime.datetime.fromisoformat(data).astimezone(pytz.UTC) | ||
except (TypeError, ValueError): | ||
raise serializers.ValidationError({"archive_alerts_from": ["Invalid date format"]}) | ||
if archive_datetime.date() >= timezone.now().date(): | ||
raise serializers.ValidationError({"archive_alerts_from": ["Invalid date. Date must be less than today."]}) | ||
return archive_datetime | ||
Comment on lines
-18
to
-26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not refrenced anywhere |
||
|
||
|
||
class FastSlackTeamIdentitySerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = SlackTeamIdentity | ||
|
@@ -37,7 +21,6 @@ class OrganizationSerializer(EagerLoadingMixin, serializers.ModelSerializer): | |
slack_team_identity = FastSlackTeamIdentitySerializer(read_only=True) | ||
|
||
name = serializers.CharField(required=False, allow_null=True, allow_blank=True, source="org_title") | ||
# name_slug = serializers.CharField(required=False, allow_null=True, allow_blank=False) | ||
maintenance_till = serializers.ReadOnlyField(source="till_maintenance_timestamp") | ||
slack_channel = serializers.SerializerMethodField() | ||
|
||
|
@@ -48,21 +31,15 @@ class Meta: | |
fields = [ | ||
"pk", | ||
"name", | ||
# "name_slug", | ||
# "is_new_version", | ||
"slack_team_identity", | ||
"maintenance_mode", | ||
"maintenance_till", | ||
# "incident_retention_web_report", | ||
# "number_of_employees", | ||
"slack_channel", | ||
] | ||
read_only_fields = [ | ||
"is_new_version", | ||
"slack_team_identity", | ||
"maintenance_mode", | ||
"maintenance_till", | ||
# "incident_retention_web_report", | ||
] | ||
|
||
def get_slack_channel(self, obj): | ||
|
@@ -82,22 +59,18 @@ def get_slack_channel(self, obj): | |
|
||
|
||
class CurrentOrganizationSerializer(OrganizationSerializer): | ||
limits = serializers.SerializerMethodField() | ||
env_status = serializers.SerializerMethodField() | ||
banner = serializers.SerializerMethodField() | ||
|
||
class Meta(OrganizationSerializer.Meta): | ||
fields = [ | ||
*OrganizationSerializer.Meta.fields, | ||
"limits", | ||
"archive_alerts_from", | ||
"is_resolution_note_required", | ||
"env_status", | ||
"banner", | ||
] | ||
read_only_fields = [ | ||
*OrganizationSerializer.Meta.read_only_fields, | ||
"limits", | ||
"banner", | ||
] | ||
|
||
|
@@ -109,10 +82,6 @@ def get_banner(self, obj): | |
)[0] | ||
return banner.json_value | ||
|
||
def get_limits(self, obj): | ||
user = self.context["request"].user | ||
return obj.notifications_limit_web_report(user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def get_env_status(self, obj): | ||
# deprecated in favour of ConfigAPIView. | ||
# All new env statuses should be added there | ||
|
@@ -122,44 +91,9 @@ def get_env_status(self, obj): | |
phone_provider_config = get_phone_provider().flags | ||
return { | ||
"telegram_configured": telegram_configured, | ||
"twilio_configured": phone_provider_config.configured, # keep for backward compatibility | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not referenced anywhere (search) |
||
"phone_provider": asdict(phone_provider_config), | ||
} | ||
|
||
def get_stats(self, obj): | ||
if isinstance(obj.cached_seconds_saved_by_amixr, int): | ||
verbal_time_saved_by_amixr = humanize.naturaldelta( | ||
datetime.timedelta(seconds=obj.cached_seconds_saved_by_amixr) | ||
) | ||
else: | ||
verbal_time_saved_by_amixr = None | ||
|
||
result = { | ||
"grouped_percent": obj.cached_grouped_percent, | ||
"alerts_count": obj.cached_alerts_count, | ||
"noise_reduction": obj.cached_noise_reduction, | ||
"average_response_time": humanize.naturaldelta(obj.cached_average_response_time), | ||
"verbal_time_saved_by_amixr": verbal_time_saved_by_amixr, | ||
} | ||
|
||
return result | ||
Comment on lines
-129
to
-145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not referenced anywhere, or consumed by the web UI |
||
|
||
def update(self, instance, validated_data): | ||
current_archive_date = instance.archive_alerts_from | ||
archive_alerts_from = validated_data.get("archive_alerts_from") | ||
|
||
result = super().update(instance, validated_data) | ||
if archive_alerts_from is not None and current_archive_date != archive_alerts_from: | ||
if current_archive_date > archive_alerts_from: | ||
unarchive_incidents_for_organization.apply_async( | ||
(instance.pk,), | ||
) | ||
resolve_archived_incidents_for_organization.apply_async( | ||
(instance.pk,), | ||
) | ||
|
||
return result | ||
Comment on lines
-147
to
-161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see this comment here for a breakdown of why we can get rid of this |
||
|
||
|
||
class FastOrganizationSerializer(serializers.ModelSerializer): | ||
pk = serializers.CharField(read_only=True, source="public_primary_key") | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
SlackTeamSettingsAPIView, | ||
UnAcknowledgeTimeoutOptionsAPIView, | ||
) | ||
from .views.subscription import SubscriptionView | ||
from .views.team import TeamViewSet | ||
from .views.telegram_channels import TelegramChannelViewSet | ||
from .views.user import CurrentUserView, UserView | ||
|
@@ -83,7 +82,6 @@ | |
GetChannelVerificationCode.as_view(), | ||
name="api-get-channel-verification-code", | ||
), | ||
optional_slash_path("current_subscription", SubscriptionView.as_view(), name="subscription"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this endpoint is not referenced/consumed by the web plugin |
||
optional_slash_path("terraform_file", TerraformGitOpsView.as_view(), name="terraform_file"), | ||
optional_slash_path("terraform_imports", TerraformStateView.as_view(), name="terraform_imports"), | ||
optional_slash_path("maintenance", MaintenanceAPIView.as_view(), name="maintenance"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,9 +364,6 @@ def enrich(self, alert_groups): | |
alert_group_pks = [alert_group.pk for alert_group in alert_groups] | ||
queryset = AlertGroup.all_objects.filter(pk__in=alert_group_pks).order_by("-pk") | ||
|
||
# do not load cached_render_for_web as it's deprecated and can be very large | ||
queryset = queryset.defer("cached_render_for_web") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was the only reference to |
||
|
||
queryset = self.get_serializer_class().setup_eager_loading(queryset) | ||
alert_groups = list(queryset) | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
DROP COLUMN
operation supports the "Instant" algorithm in MySQL v8.0 so this should be a very quick operation (docs)