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

Fix bug #1103 in setting TELEGRAM_WEBHOOK_HOST causing Flood control exceeded error #1934

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Fix bug [#1103](https://github.com/grafana/oncall/issues/1103) in setting `TELEGRAM_WEBHOOK_HOST` causing
`Flood control exceeded` error by @alexintech ([#1934](https://github.com/grafana/oncall/pull/1934))

## v1.2.33 (2023-05-30)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/api/views/live_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def perform_update(self, serializer):

if new_value != old_value:
self._post_update_hook(name, old_value)
LiveSetting.validate_settings()
LiveSetting.validate_dependent_settings((name,))

def perform_destroy(self, instance):
name = instance.name
Expand Down
25 changes: 20 additions & 5 deletions engine/apps/base/models/live_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class LiveSetting(models.Model):
"GRAFANA_CLOUD_ONCALL_TOKEN",
)

DEPENDENT_SETTINGS_PREFIXES = ("TWILIO",)

def __str__(self):
return self.name

Expand Down Expand Up @@ -206,13 +208,26 @@ def populate_settings_if_needed(cls):
for setting_name in setting_names_to_populate:
cls.objects.create(name=setting_name, value=cls._get_setting_from_setting_file(setting_name))

cls.validate_settings()
cls.validate_dependent_settings(setting_names_to_populate)

@classmethod
def validate_dependent_settings(cls, updated_settings):
validate_prefixes = cls._get_dependent_prefixes(updated_settings)

for prefix in validate_prefixes:
settings_to_validate = cls.objects.filter(name__startswith=prefix)
for setting in settings_to_validate:
setting.save(update_fields=["error"])

@classmethod
def validate_settings(cls):
settings_to_validate = cls.objects.all()
for setting in settings_to_validate:
setting.save(update_fields=["error"])
def _get_dependent_prefixes(cls, updated_settings):
prefixes = []
for dependent_prefix in cls.DEPENDENT_SETTINGS_PREFIXES:
for setting_name in updated_settings:
if setting_name.startswith(dependent_prefix):
prefixes.append(dependent_prefix)
break
return prefixes

@staticmethod
def _get_setting_from_setting_file(setting_name):
Expand Down