-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add scheduling for config hash verficiation #203
Changes from 25 commits
d886e49
c4a9f20
2c9d8a9
10504d9
8a84ca4
905015e
d32b7fc
459b33f
71f0697
829421d
4df5dad
b0b8940
43c1b55
670eb94
8a0ec03
846a554
d01f5fb
6e3d45e
267a9f8
231b829
bdc75e1
04aff69
d35f482
7d557d4
09140c1
87c23ec
27c2570
70f69d1
e227df6
eab9235
99633cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
_FAUCET_PROM_PORT_DEFAULT = 9302 | ||
_GAUGE_PROM_HOST = '127.0.0.1' | ||
_GAUGE_PROM_PORT_DEFAULT = 9303 | ||
_CONFIG_HASH_CLASH_TIMEOUT_SEC_DEFAULT = '60' | ||
|
||
_TARGET_FAUCET_METRICS = ( | ||
'port_status', | ||
|
@@ -113,6 +114,14 @@ def __init__(self, config): | |
self._metrics = None | ||
self._varz_proxy = None | ||
|
||
self._config_hash_clash_timer = None | ||
self._config_hash_clashed = False | ||
self._config_hash_clash_timeout_sec = ( | ||
self._config.event_client.config_hash_clash_timeout_sec or | ||
int(os.getenv( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why env variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed.. |
||
'_CONFIG_HASH_CLASH_TIMEOUT_SEC', _CONFIG_HASH_CLASH_TIMEOUT_SEC_DEFAULT)) | ||
) | ||
|
||
self._lock = threading.Lock() | ||
|
||
def initialize(self): | ||
|
@@ -377,7 +386,7 @@ def _process_device_placement(self, eth_src, device_placement, static=False, exp | |
self._authenticator.process_device_placement(eth_src, device_placement) | ||
else: | ||
LOGGER.info( | ||
'Ignored vlan expiration for device %s with expired vlan %d', eth_src, expired_vlan) | ||
'Ignored vlan expiration for device %s with expired vlan %s', eth_src, expired_vlan) | ||
|
||
def handle_auth_result(self, mac, access, segment, role): | ||
"""Method passed as callback to authenticator to forward auth results""" | ||
|
@@ -436,9 +445,43 @@ def _restore_states(self): | |
def _restore_faucet_config(self, timestamp, config_hash): | ||
config_info, faucet_dps, _ = self._get_faucet_config() | ||
self._update_config_warning_varz() | ||
assert config_hash == config_info['hashes'], 'config hash info does not match' | ||
|
||
if config_hash == config_info['hashes']: | ||
self._attempt_cancel_config_hash_clash_timer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in these cases I'd leave out the "attempt" -- it's not semantically meaningful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not using a seprate timer now. |
||
else: | ||
LOGGER.warning('Config hash does not match') | ||
self._attempt_start_config_hash_clash_timer() | ||
|
||
self._faucet_collector.process_dataplane_config_change(timestamp, faucet_dps) | ||
|
||
def _attempt_start_config_hash_clash_timer(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't be "start a timer" -- but rather just a mark of when the last config hash clash was |
||
if self._config_hash_clash_timer and self._config_hash_clash_timer.is_alive(): | ||
return | ||
self._config_hash_clash_timer = threading.Timer( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should reuse one of the existing heartbeat schedulers for this -- creating lots of little threads ends up being very messy in the long run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using _faucet_state_scheduler now.. |
||
interval=self._config_hash_clash_timeout_sec, | ||
function=self._check_config_hash_clashed) | ||
self._config_hash_clash_timer.start() | ||
LOGGER.info( | ||
'Config hash clash timer started with %s seconds', self._config_hash_clash_timeout_sec) | ||
|
||
def _attempt_cancel_config_hash_clash_timer(self): | ||
if not self._config_hash_clash_timer or not self._config_hash_clash_timer.is_alive(): | ||
return | ||
self._config_hash_clash_timer.cancel() | ||
LOGGER.info('Config hash clash timer cancelled') | ||
|
||
def _check_config_hash_clashed(self): | ||
_, varz_config_hashes = self._get_varz_config() | ||
config_info, _, _ = self._get_faucet_config() | ||
|
||
if varz_config_hashes != config_info['hashes']: | ||
LOGGER.error( | ||
'Config hash does not match after %s seconds', self._config_hash_clash_timeout_sec) | ||
self._config_hash_clashed = True | ||
|
||
def _get_config_hash_clashed(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private getter is redundant -- just use the variable directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
return self._config_hash_clashed | ||
|
||
def _process_config_change(self, event): | ||
self._faucet_collector.process_dp_config_change( | ||
event.timestamp, event.dp_name, event.restart_type, event.dp_id) | ||
|
@@ -465,7 +508,7 @@ def main_loop(self): | |
self._faucet_events_connect() | ||
|
||
try: | ||
self._faucet_events.next_event(blocking=True) | ||
self._faucet_events.next_event(self._get_config_hash_clashed, blocking=True) | ||
except FaucetEventOrderError as e: | ||
LOGGER.error("Faucet event order error: %s", e) | ||
if self._metrics: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not right -- the concept of a config hash shouldn't bleed down into the event client itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed