Greg Padgett has uploaded a new change for review. Change subject: agent: configurable host score factors ......................................................................
agent: configurable host score factors Allow configuration of host score factors in (usually) /etc/ovirt-hosted-engine-ha/agent.conf Change-Id: If485283c133eb517c9a3036ff42d1cd962a1697d Bug-Url: https://bugzilla.redhat.com/1037654 Signed-off-by: Greg Padgett <[email protected]> --- M ovirt-hosted-engine-ha.spec.in M ovirt_hosted_engine_ha/agent/Makefile.am A ovirt_hosted_engine_ha/agent/agent.conf M ovirt_hosted_engine_ha/agent/constants.py.in M ovirt_hosted_engine_ha/agent/hosted_engine.py 5 files changed, 65 insertions(+), 17 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-ha refs/changes/56/22056/1 diff --git a/ovirt-hosted-engine-ha.spec.in b/ovirt-hosted-engine-ha.spec.in index 96fd9c5..6844619 100644 --- a/ovirt-hosted-engine-ha.spec.in +++ b/ovirt-hosted-engine-ha.spec.in @@ -107,6 +107,7 @@ %dir %{engine_ha_confdir} %config(noreplace) %{engine_ha_confdir}/agent-log.conf +%config(noreplace) %{engine_ha_confdir}/agent.conf %config(noreplace) %{engine_ha_confdir}/broker-log.conf %config(noreplace) %{engine_ha_confdir}/broker.conf diff --git a/ovirt_hosted_engine_ha/agent/Makefile.am b/ovirt_hosted_engine_ha/agent/Makefile.am index eab0c1d..61ec354 100644 --- a/ovirt_hosted_engine_ha/agent/Makefile.am +++ b/ovirt_hosted_engine_ha/agent/Makefile.am @@ -49,10 +49,12 @@ agentconfdir = $(engine_ha_confdir) agentconf_DATA = \ + agent.conf \ agent-log.conf \ $(NULL) EXTRA_DIST = \ + agent.conf \ agent-log.conf.in \ constants.py.in \ $(NULL) diff --git a/ovirt_hosted_engine_ha/agent/agent.conf b/ovirt_hosted_engine_ha/agent/agent.conf new file mode 100644 index 0000000..0c9bf46 --- /dev/null +++ b/ovirt_hosted_engine_ha/agent/agent.conf @@ -0,0 +1,10 @@ +[score] +# NOTE: These values must be the same for all hosts in the HA cluster! +base-score=2400 +gateway-score-penalty=1600 +mgmt-bridge-score-penalty=600 +free-memory-score-penalty=400 +cpu-load-score-penalty=1000 +engine-retry-score-penalty=50 +cpu-load-penalty-min=0.4 +cpu-load-penalty-max=0.9 diff --git a/ovirt_hosted_engine_ha/agent/constants.py.in b/ovirt_hosted_engine_ha/agent/constants.py.in index 82cc07a..cf2dba3 100644 --- a/ovirt_hosted_engine_ha/agent/constants.py.in +++ b/ovirt_hosted_engine_ha/agent/constants.py.in @@ -55,7 +55,7 @@ BASE_SCORE = 2400 GATEWAY_SCORE_PENALTY = 1600 MGMT_BRIDGE_SCORE_PENALTY = 600 -FREE_VM_MEMORY_SCORE_PENALTY = 400 +FREE_MEMORY_SCORE_PENALTY = 400 CPU_LOAD_SCORE_PENALTY = 1000 ENGINE_RETRY_SCORE_PENALTY = 50 @@ -70,6 +70,7 @@ LOG_FILE = '@ENGINE_HA_LOGDIR@/agent.log' PID_FILE = '@ENGINE_HA_RUNDIR@/agent.pid' +AGENT_CONF_FILE = '@ENGINE_HA_CONFDIR@/agent.conf' ENGINE_SETUP_CONF_FILE = '/etc/ovirt-hosted-engine/hosted-engine.conf' VM_CONF_FILE = '/etc/ovirt-hosted-engine/vm.conf' diff --git a/ovirt_hosted_engine_ha/agent/hosted_engine.py b/ovirt_hosted_engine_ha/agent/hosted_engine.py index f79c258..317c602 100644 --- a/ovirt_hosted_engine_ha/agent/hosted_engine.py +++ b/ovirt_hosted_engine_ha/agent/hosted_engine.py @@ -17,6 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # +import ConfigParser import copy import errno import json @@ -111,6 +112,8 @@ self._shutdown_requested_callback = shutdown_requested_callback self._config = config.Config() + self._score_cfg = self._get_score_config() + self._broker = None self._required_monitors = self._get_required_monitors() self._local_monitors = {} @@ -137,6 +140,34 @@ # TODO local maintenance state # TODO unexpected crash state } + + def _get_score_config(self): + score = { + 'base-score': constants.BASE_SCORE, + 'gateway-score-penalty': constants.GATEWAY_SCORE_PENALTY, + 'mgmt-bridge-score-penalty': constants.MGMT_BRIDGE_SCORE_PENALTY, + 'free-memory-score-penalty': constants.FREE_MEMORY_SCORE_PENALTY, + 'cpu-load-score-penalty': constants.CPU_LOAD_SCORE_PENALTY, + 'engine-retry-score-penalty': constants.ENGINE_RETRY_SCORE_PENALTY, + 'cpu-load-penalty-min': constants.CPU_LOAD_PENALTY_MIN, + 'cpu-load-penalty-max': constants.CPU_LOAD_PENALTY_MAX, + } + + cfg = ConfigParser.SafeConfigParser() + cfg.read(constants.AGENT_CONF_FILE) + try: + score.update(cfg.items('score')) + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + pass + + # When these are used they're expected to be numeric types + for k, v in score.iteritems(): + if k.startswith('cpu-load-penalty-'): + score[k] = float(v) + else: + score[k] = int(v) + + return score def _get_required_monitors(self): """ @@ -573,23 +604,23 @@ lm = self._local_monitors ts = int(time.time()) - score = constants.BASE_SCORE + score = self._score_cfg['base-score'] # FIXME score needed for vdsm storage pool connection? # (depending on storage integration, may not be able to report...) if lm['gateway']['status'] == 'False': self._log.info("Penalizing score by %d due to gateway status", - constants.GATEWAY_SCORE_PENALTY, + self._score_cfg['gateway-score-penalty'], extra=log_filter.lf_args('score-gateway', self.LF_PENALTY_INT)) - score -= constants.GATEWAY_SCORE_PENALTY + score -= self._score_cfg['gateway-score-penalty'] if lm['bridge']['status'] == 'False': self._log.info("Penalizing score by %d due to mgmt bridge status", - constants.MGMT_BRIDGE_SCORE_PENALTY, + self._score_cfg['mgmt-bridge-score-penalty'], extra=log_filter.lf_args('score-mgmtbridge', self.LF_PENALTY_INT)) - score -= constants.MGMT_BRIDGE_SCORE_PENALTY + score -= self._score_cfg['mgmt-bridge-score-penalty'] # Record 15 minute cpu load history (not counting load caused by # the engine vm. The default load penalty is: @@ -606,20 +637,23 @@ self._rinfo['last-load-update-time'] = ts load_factor = sum(self._rinfo['cpu-load-history']) / 15 - if constants.CPU_LOAD_PENALTY_MAX == constants.CPU_LOAD_PENALTY_MIN: + if self._score_cfg['cpu-load-penalty-max'] \ + == self._score_cfg['cpu-load-penalty-min']: # Avoid divide by 0 in penalty calculation below - if load_factor < constants.CPU_LOAD_PENALTY_MIN: + if load_factor < self._score_cfg['cpu-load-penalty-min']: penalty = 0 else: - penalty = constants.CPU_LOAD_SCORE_PENALTY + penalty = self._score_cfg['cpu-load-score-penalty'] else: # Penalty is normalized to [0, max penalty] and is linear based on # (magnitude of value within penalty range) / (size of range) - penalty = int((load_factor - constants.CPU_LOAD_PENALTY_MIN) - / (constants.CPU_LOAD_PENALTY_MAX - - constants.CPU_LOAD_PENALTY_MIN) - * constants.CPU_LOAD_SCORE_PENALTY) - penalty = max(0, min(constants.CPU_LOAD_SCORE_PENALTY, penalty)) + penalty = int((load_factor + - self._score_cfg['cpu-load-penalty-min']) + / (self._score_cfg['cpu-load-penalty-max'] + - self._score_cfg['cpu-load-penalty-min']) + * self._score_cfg['cpu-load-score-penalty']) + penalty = max(0, min(self._score_cfg['cpu-load-score-penalty'], + penalty)) if penalty > 0: self._log.info("Penalizing score by %d due to cpu load", @@ -633,10 +667,10 @@ if self._rinfo['current-state'] != self.States.ON \ and float_or_default(lm['mem-free']['status'], 0) < vm_mem: self._log.info('Penalizing score by %d due to low free memory', - constants.FREE_VM_MEMORY_SCORE_PENALTY, + self._score_cfg['free-memory-score-penalty'], extra=log_filter.lf_args('score-memory', self.LF_PENALTY_INT)) - score -= constants.FREE_VM_MEMORY_SCORE_PENALTY + score -= self._score_cfg['free-memory-score-penalty'] # If too many retries occur, give a less-suited host a chance if (self._rinfo['engine-vm-retry-count'] @@ -649,7 +683,7 @@ elif self._rinfo['engine-vm-retry-count'] > 0: # Subtracting a small amount each time causes round-robin attempts # between hosts that are otherwise equally suited to run the engine - penalty = constants.ENGINE_RETRY_SCORE_PENALTY \ + penalty = self._score_cfg['engine-retry-score-penalty'] \ * self._rinfo['engine-vm-retry-count'] self._log.info('Penalizing score by %d' ' due to %d engine vm retry attempts', -- To view, visit http://gerrit.ovirt.org/22056 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If485283c133eb517c9a3036ff42d1cd962a1697d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-ha Gerrit-Branch: master Gerrit-Owner: Greg Padgett <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
