def auditable_share(self): """Return current share adjustment factor. """ if self.status in HEALTHY_STATUSES: return 1.0, AuditItem('health', '1.0') else: return 0.0, AuditItem('health', '0.0')
def _normalize_endpoint_weights(self, endpoints, normalization_factor): """ Applies a normalization factor to a list of endpoints. Args: endpoints - list(aurproxy.config.SourceEndpoints) normalization_factor - float between 0.0 and 1.0 Returns: list(aurproxy.config.ProxyEndpoint) """ norm_factor = normalization_factor significance = SIGNIFICANCE proxy_endpoints = [] for endpoint in endpoints: norm_weight = float(endpoint.share) * float(norm_factor) norm_audit_val = '{0} * {1} => {2}'.format(endpoint.share, norm_factor, norm_weight) norm_audit = AuditItem('nrm_wgt', norm_audit_val) norm_adj_weight = int(norm_weight * significance) norm_audit_val = '{0} * {1} => {2}'.format(norm_weight, significance, norm_adj_weight) norm_adj_audit = AuditItem('nrm_adj_wgt', norm_audit_val) audit = AuditItem('audit', [endpoint.audit, norm_audit, norm_adj_audit]) proxy_endpoint = ProxyEndpoint(host=endpoint.host, port=endpoint.port, weight=norm_adj_weight, audit=audit) proxy_endpoints.append(proxy_endpoint) return proxy_endpoints
def _get_unadjusted_endpoints(self): """ Get endpoints without applying weight adjustment logic. Primary endpoints get weight 1. Overflow endpoints get weight 0. Returns: list(aurproxy.config.ProxyEndpoint) """ eps = [] audit_msg = 'Weight adjustment delayed.' if self._weight_adjustment_start: delay_time = self._weight_adjustment_start.isoformat() delay_msg = 'Starting: {0}.'.format(delay_time) audit_msg = '{0} {1}'.format(audit_msg, delay_msg) audit = AuditItem('audit', audit_msg) for source in self._sources: eps.extend([ ProxyEndpoint(host=ep.host, port=ep.port, weight=SIGNIFICANCE, audit=audit) for ep in source.endpoints ]) oweight = 0 if eps else 1 oaudit = AuditItem('audit', 'Overflow endpoint.') for overflow_source in self._overflow_sources: for oep in overflow_source.endpoints: eps.append( ProxyEndpoint(host=oep.host, port=oep.port, weight=oweight, audit=oaudit)) return eps
def auditable_share(self): """Return current share adjustment factor. """ if self._start_time is None: raise Exception('DelayStartShareAdjuster: No start time.') if datetime.now() > self._activation_time: return 1.0, AuditItem('delay', '1.0') else: return 0.0, AuditItem('delay', '0.0')
def auditable_share(self): """ Get a (float(share), AuditItem)). """ share_comps = [1.0] share_comp_audits = [AuditItem('base', '1.0')] for share_adjuster in self._share_adjusters: share_comp, share_comp_audit = share_adjuster.auditable_share share_comps.append(float(share_comp)) share_comp_audits.append(share_comp_audit) share = reduce(operator.mul, share_comps) audit = AuditItem('share', [share, share_comp_audits]) return share, audit
def auditable_share(self): """Return current share adjustment factor. """ as_of = datetime.now() share = self._curve_fn(self._start_time, self._end_time, as_of) return share, AuditItem('ramp', str(share))
def auditable_share(self): """Return current share adjustment factor. """ return self._share, AuditItem('delay', '1.0')