-
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 4 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,26 @@ | ||
# Generated by Django 3.2.20 on 2023-07-11 15:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('alerts', '0019_auto_20230705_1619'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='alertgroup', | ||
name='active_cache_for_web_calculation_id', | ||
), | ||
migrations.RemoveField( | ||
model_name='alertgroup', | ||
name='estimate_escalation_finish_time', | ||
), | ||
migrations.AlterField( | ||
model_name='alertgroup', | ||
name='cached_render_for_web', | ||
field=models.JSONField(default=dict, null=True), | ||
), | ||
] |
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() | ||
|
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"), | ||
|
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.
resolve_by_archivation
was only ever invoked in the following two spots:CheckAlertIsUnarchivedMixin.check_alert_is_unarchived
: this method seemed to be deprecated because the logic inside the method was as such:organization.archive_alerts_from
is always set to1970-01-01
(only value that exists in our production database) so therefore the above logic will never invokeAlertGroup.resolve_by_archivation
resolve_archived_incidents_for_organization
Celery taskthis celery task was only ever queued by
CurrentOrganizationSerializer.update
:archive_alerts_from
will always beNone
here