Skip to content

Commit 35f1265

Browse files
committed
new: Allows to never expire a monitoring
1 parent 54b7467 commit 35f1265

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

webmonitoring/webmonitoring.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class NotificationSettings(TypedDict, total=False):
4444
class MonitorSettings(TypedDict, total=False):
4545
capture_settings: CaptureSettings
4646
frequency: str
47+
never_expire: bool
4748
expire_at: Optional[Union[str, datetime, float]]
4849
collection: Optional[str]
4950
compare_settings: Optional[CompareSettings]
@@ -176,6 +177,8 @@ def get_monitor_settings(self, monitor_uuid: str) -> MonitorSettings:
176177
to_return['expire_at'] = expire_at
177178
if collection := self.redis.get(f'{monitor_uuid}:collection'):
178179
to_return['collection'] = collection
180+
if never_expire := self.redis.exists(f'{monitor_uuid}:ever_expire'):
181+
to_return['never_expire'] = never_expire
179182
if compare_settings := self.get_compare_settings(monitor_uuid):
180183
to_return['compare_settings'] = compare_settings
181184
if notification := self.redis.hgetall(f'{monitor_uuid}:notification'):
@@ -213,7 +216,9 @@ def monitor(self, *, capture_settings: CaptureSettings, frequency: str,
213216
def monitor(self, *, monitor_uuid: str, capture_settings: Optional[CaptureSettings]=None,
214217
frequency: Optional[str]=None,
215218
expire_at: Optional[Union[datetime, str, int, float]]=None,
216-
collection: Optional[str]=None, compare_settings: Optional[CompareSettings]=None,
219+
collection: Optional[str]=None,
220+
never_expire: bool=False,
221+
compare_settings: Optional[CompareSettings]=None,
217222
notification: Optional[NotificationSettings]=None) -> str:
218223
"""Update an existing monitoring with individual parameters"""
219224
...
@@ -222,6 +227,7 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
222227
frequency: Optional[str]=None,
223228
expire_at: Optional[Union[datetime, str, int, float]]=None,
224229
collection: Optional[str]=None,
230+
never_expire: bool=False,
225231
compare_settings: Optional[CompareSettings]=None,
226232
notification: Optional[NotificationSettings]=None,
227233
monitor_settings: Optional[MonitorSettings]=None,
@@ -241,6 +247,7 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
241247
frequency = monitor_settings.get('frequency')
242248
expire_at = monitor_settings.get('expire_at')
243249
collection = monitor_settings.get('collection')
250+
never_expire = monitor_settings.get('never_expire', False)
244251
compare_settings = monitor_settings.get('compare_settings')
245252
notification = monitor_settings.get('notification')
246253

@@ -257,6 +264,9 @@ def monitor(self, *, capture_settings: Optional[CaptureSettings]=None,
257264
if frequency:
258265
p.set(f'{monitor_uuid}:frequency', frequency.lower())
259266

267+
if never_expire:
268+
p.set(f'{monitor_uuid}:never_expire', 1)
269+
260270
if collection:
261271
p.set(f'{monitor_uuid}:collection', collection)
262272
p.sadd('collections', collection)
@@ -386,7 +396,9 @@ def update_monitoring_queue(self):
386396
nb_restarts = 1
387397
else:
388398
nb_restarts = int(_nb_restarts) + 1
389-
if self.redis.zcard(f'{monitor_uuid}:captures') > self.max_captures * nb_restarts:
399+
# if the capture is marked as "never_expire" (admin only), skip that.
400+
if (not self.redis.exists(f'{monitor_uuid}:never_expire')
401+
and self.redis.zcard(f'{monitor_uuid}:captures') > self.max_captures * nb_restarts):
390402
# Force expire monitoring
391403
self.redis.smove('monitored', 'expired', monitor_uuid)
392404
logger.info('Maximum amount of captures reached, expire..')

website/web/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CompareSettingsForm(Form):
143143
ressources_ignore_regexes = FieldList(StringField('Regex'), label="Regexes in URLs to ignore in comparison", min_entries=5)
144144
ignore_ips = BooleanField(label='Ignore IPs in comparison', description='Avoid flagging two captures are different when served on CDNs.')
145145
skip_failed_captures = BooleanField(label='Skip failed captures', description='Avoid attempting to compare two captures when one of them failed.')
146+
never_expire = BooleanField(label='Never expire', description='Do not auto-expire the monitoring.')
146147

147148

148149
class NotificationForm(Form):
@@ -171,7 +172,7 @@ def changes_tracking(monitor_uuid: str):
171172
if values := form.compare_settings.data[k]:
172173
# Empty list is fine, it is how we remove all entries
173174
compare_settings[k] = [x for x in set(values) if x != ''] # type: ignore
174-
elif k in ['ignore_ips', 'skip_failed_captures']:
175+
elif k in ['ignore_ips', 'skip_failed_captures', 'never_expire']:
175176
compare_settings[k] = bool(form.compare_settings.data[k]) # type: ignore
176177

177178
notification: NotificationSettings = {}
@@ -279,7 +280,8 @@ def get(self):
279280
'ressources_ignore_domains': fields.List(fields.String(description="A domain to ignore")),
280281
'ressources_ignore_regexes': fields.List(fields.String(description="A regex to match anything in a URL")),
281282
'ignore_ips': fields.Boolean(False, description='Ignore IPs when comparing nodes. Avoid flagging two captures are different when served on CDNs.'),
282-
'skip_failed_captures': fields.Boolean(False, description='Skip failed captures. Avoid attempting to compare two captures when one of them failed.')
283+
'skip_failed_captures': fields.Boolean(False, description='Skip failed captures. Avoid attempting to compare two captures when one of them failed.'),
284+
'never_expire': fields.Boolean(label='Never expire the monitoring', description='Allows to keep the monitoring going forever.')
283285
})
284286

285287
notification_mapping = api.model('NotificationSettings', {

website/web/templates/changes_tracking.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
{{ monitoring_form.compare_settings.skip_failed_captures.label(class="form-label") }}
7676
{{ monitoring_form.compare_settings.skip_failed_captures(class="form-check-input") }}
7777
</div>
78+
<div class="mb-3">
79+
{{ monitoring_form.compare_settings.never_expire.label(class="form-label") }}
80+
{{ monitoring_form.compare_settings.never_expire(class="form-check-input") }}
81+
</div>
7882

7983
{% if current_user.is_authenticated %}
8084
<div class="mb-3">

0 commit comments

Comments
 (0)