Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
cleanup entities task (#388)
Browse files Browse the repository at this point in the history
* cleanup entities task

see also zalando-zmon/zmon-scheduler#89

* finish span...

* fix span?

* fix span?

* log_kv requires dict
  • Loading branch information
vetinari authored and mohabusama committed Apr 5, 2019
1 parent 518df2e commit 6efff55
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion zmon_worker_monitor/zmon_worker/tasks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,9 @@ def trial_run(self, req, alerts, task_context=None, **kwargs):
else:
self.notify_for_trial_run(val, req, alerts)

@trace()
@trace(pass_span=True)
def cleanup(self, *args, **kwargs):
current_span = extract_span_from_kwargs(**kwargs)
self.task_context = kwargs.get('task_context')
p = self.con.pipeline()
p.smembers('zmon:checks')
Expand Down Expand Up @@ -1158,6 +1159,23 @@ def cleanup(self, *args, **kwargs):
else:
self._cleanup_alert(p, alert_id)

current_span.log_kv({'cleanup_entities': kwargs.get('cleanup_entities', [])})
for entity_id in kwargs.get('cleanup_entities', []):
alert_ids = [a.replace('zmon:alerts:', '').replace(':{}'.format(entity_id), '')
for a in self.con.keys('zmon:alerts:*:{}'.format(entity_id))]
for alert_id in alert_ids:
self._cleanup_common(p, 'alerts', alert_id, set(entity_id))
# All entities matching given alert definition.
self.logger.info('Removing entity %s from hash %s', entity_id,
'zmon:alerts:{}:entities'.format(alert_id))
p.hdel('zmon:alerts:{}:entities'.format(alert_id), entity_id)
p.delete('zmon:notifications:{}:{}'.format(alert_id, entity_id))

check_ids = [c.replace('zmon:checks:', '').replace(':{}'.format(entity_id), '')
for c in self.con.keys('zmon:checks:*:{}'.format(entity_id))]
for check_id in check_ids:
self._cleanup_common(p, 'checks', check_id, set(entity_id))

p.execute()

def _cleanup_check(self, pipeline, check_id):
Expand Down

0 comments on commit 6efff55

Please sign in to comment.