Skip to content

Commit

Permalink
Only raise catalog not healthy alert for preferred trains
Browse files Browse the repository at this point in the history
This commit adds changes to only raise an alert that a catalog is not healthy if the affected train is set as a preferred train by the user. Motivation for this change is that a catalog might be maintained by lots of devs and each person can be working on their own train for purposes like development, now in the UI users only interact with preferred trains, so it makes sense that we only let the user know that a catalog is not healthy if one of the affected trains is what the user has set his preferred train.
  • Loading branch information
sonicaj committed May 9, 2021
1 parent 15b56ac commit 70a966f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/middlewared/middlewared/plugins/catalogs_linux/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def get_trains(self, location, options=None):
options = options or {}
questions_context = self.middleware.call_sync('catalog.get_normalised_questions_context')
unhealthy_apps = set()
if options.get('alert') and options.get('label'):
preferred_trains = self.middleware.call_sync('catalog.get_instance', options['label'])['preferred_trains']
else:
preferred_trains = []

for train in os.listdir(location):
if (
not os.path.isdir(os.path.join(location, train)) or train.startswith('.') or
Expand Down Expand Up @@ -98,7 +103,8 @@ def get_trains(self, location, options=None):
for verror in verrors:
item_data['healthy_error'] += f'{verror[0]}: {verror[1]}'

unhealthy_apps.add(f'{item} ({train} train)')
if train in preferred_trains:
unhealthy_apps.add(f'{item} ({train} train)')
# If the item format is not valid - there is no point descending any further into versions
continue

Expand All @@ -111,12 +117,13 @@ def get_trains(self, location, options=None):
unhealthy_versions.append(k)

if unhealthy_versions:
unhealthy_apps.add(f'{item} ({train} train)')
if train in preferred_trains:
unhealthy_apps.add(f'{item} ({train} train)')
item_data['healthy_error'] = f'Errors were found with {", ".join(unhealthy_versions)} version(s)'
else:
item_data['healthy'] = True

if options.get('alert') and options.get('label') and unhealthy_apps:
if unhealthy_apps:
self.middleware.call_sync(
'alert.oneshot_create', 'CatalogNotHealthy', {
'catalog': options['label'], 'apps': ', '.join(unhealthy_apps)
Expand Down

0 comments on commit 70a966f

Please sign in to comment.