From c582e37380d39c1ae39ca70386e1d7a1316f7915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20K=C3=B6lker?= Date: Thu, 4 Apr 2019 20:22:39 +0000 Subject: [PATCH] Rebase and Flake8 fixes of #584 (#624) * Fresh copy of https://github.com/mesosphere/marathon-lb/pull/452 * mlb: flake8 fixes --- marathon_lb.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/marathon_lb.py b/marathon_lb.py index 125c3514..30ccad08 100755 --- a/marathon_lb.py +++ b/marathon_lb.py @@ -33,6 +33,7 @@ import threading import time import datetime +import urllib.parse from itertools import cycle from collections import defaultdict from operator import attrgetter @@ -226,11 +227,11 @@ def tasks(self): logger.info('fetching tasks') return self.api_req('GET', ['tasks'])["tasks"] - def get_event_stream(self): - url = self.host + "/v2/events?plan-format=light&" + \ - "event_type=status_update_event&" + \ - "event_type=health_status_changed_event&" + \ - "event_type=api_post_event" + def get_event_stream(self, events): + url = self.host + "/v2/events" + if events: + url += "?" + urllib.parse.urlencode({'event_type': events}, + doseq=True) return CurlHttpEventStream(url, self.__auth, self.__verify) def iter_events(self, stream): @@ -1897,6 +1898,10 @@ def __init__(self, marathon, self.__pending_reload = False self.__haproxy_map = haproxy_map + self.relevant_events = ('api_post_event', + 'health_status_changed_event', + 'status_update_event') + self.__thread = None # Fetch the base data @@ -1998,9 +2003,7 @@ def reload_existing_config(self): self.__condition.release() def handle_event(self, event): - if event['eventType'] == 'status_update_event' or \ - event['eventType'] == 'health_status_changed_event' or \ - event['eventType'] == 'api_post_event': + if event['eventType'] in self.relevant_events: self.reset_from_tasks() def handle_signal(self, sig, stack): @@ -2187,7 +2190,7 @@ def load_json(data_str): while True: stream_started = time.time() currentWaitSeconds = random.random() * waitSeconds - stream = marathon.get_event_stream() + stream = marathon.get_event_stream(processor.relevant_events) try: # processor start is now idempotent and will start at # most one thread