Skip to content

Commit

Permalink
Add missing period to logger.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald W. Lester authored and Gerald W. Lester committed Oct 1, 2021
1 parent 29633dc commit 1233966
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
30 changes: 15 additions & 15 deletions aws_lambda_powertools/utilities/feature_flags/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _match_by_action(self, action: str, condition_value: Any, context_value: Any
func = mapping_by_action.get(action, lambda a, b: False)
return func(context_value, condition_value)
except Exception as exc:
self.loggerdebug(f"caught exception while matching action: action={action}, exception={str(exc)}")
self.logger.debug(f"caught exception while matching action: action={action}, exception={str(exc)}")
return False

def _evaluate_conditions(
Expand All @@ -68,7 +68,7 @@ def _evaluate_conditions(
conditions = cast(List[Dict], rule.get(schema.CONDITIONS_KEY))

if not conditions:
self.loggerdebug(
self.logger.debug(
f"rule did not match, no conditions to match, rule_name={rule_name}, rule_value={rule_match_value}, "
f"name={feature_name} "
)
Expand All @@ -80,13 +80,13 @@ def _evaluate_conditions(
cond_value = condition.get(schema.CONDITION_VALUE)

if not self._match_by_action(action=cond_action, condition_value=cond_value, context_value=context_value):
self.loggerdebug(
self.logger.debug(
f"rule did not match action, rule_name={rule_name}, rule_value={rule_match_value}, "
f"name={feature_name}, context_value={str(context_value)} "
)
return False # context doesn't match condition

self.loggerdebug(f"rule matched, rule_name={rule_name}, rule_value={rule_match_value}, name={feature_name}")
self.logger.debug(f"rule matched, rule_name={rule_name}, rule_value={rule_match_value}, name={feature_name}")
return True

def _evaluate_rules(
Expand All @@ -97,12 +97,12 @@ def _evaluate_rules(
rule_match_value = rule.get(schema.RULE_MATCH_VALUE)

# Context might contain PII data; do not log its value
self.loggerdebug(f"Evaluating rule matching, rule={rule_name}, feature={feature_name}, default={feat_default}")
self.logger.debug(f"Evaluating rule matching, rule={rule_name}, feature={feature_name}, default={feat_default}")
if self._evaluate_conditions(rule_name=rule_name, feature_name=feature_name, rule=rule, context=context):
return bool(rule_match_value)

# no rule matched, return default value of feature
self.loggerdebug(f"no rule matched, returning feature default, default={feat_default}, name={feature_name}")
self.logger.debug(f"no rule matched, returning feature default, default={feat_default}, name={feature_name}")
return feat_default
return False

Expand Down Expand Up @@ -149,7 +149,7 @@ def get_configuration(self) -> Union[Dict[str, Dict], Dict]:
```
"""
# parse result conf as JSON, keep in cache for max age defined in store
self.loggerdebug(f"Fetching schema from registered store, store={self._store}")
self.logger.debug(f"Fetching schema from registered store, store={self._store}")
config = self._store.get_configuration()
validator = schema.SchemaValidator(schema=config)
validator.validate()
Expand Down Expand Up @@ -193,21 +193,21 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
try:
features = self.get_configuration()
except ConfigurationStoreError as err:
self.loggerdebug(f"Failed to fetch feature flags from store, returning default provided, reason={err}")
self.logger.debug(f"Failed to fetch feature flags from store, returning default provided, reason={err}")
return default

feature = features.get(name)
if feature is None:
self.loggerdebug(f"Feature not found; returning default provided, name={name}, default={default}")
self.logger.debug(f"Feature not found; returning default provided, name={name}, default={default}")
return default

rules = feature.get(schema.RULES_KEY)
feat_default = feature.get(schema.FEATURE_DEFAULT_VAL_KEY)
if not rules:
self.loggerdebug(f"no rules found, returning feature default, name={name}, default={feat_default}")
self.logger.debug(f"no rules found, returning feature default, name={name}, default={feat_default}")
return bool(feat_default)

self.loggerdebug(f"looking for rule match, name={name}, default={feat_default}")
self.logger.debug(f"looking for rule match, name={name}, default={feat_default}")
return self._evaluate_rules(feature_name=name, context=context, feat_default=bool(feat_default), rules=rules)

def get_enabled_features(self, *, context: Optional[Dict[str, Any]] = None) -> List[str]:
Expand Down Expand Up @@ -244,20 +244,20 @@ def get_enabled_features(self, *, context: Optional[Dict[str, Any]] = None) -> L
try:
features: Dict[str, Any] = self.get_configuration()
except ConfigurationStoreError as err:
self.loggerdebug(f"Failed to fetch feature flags from store, returning empty list, reason={err}")
self.logger.debug(f"Failed to fetch feature flags from store, returning empty list, reason={err}")
return features_enabled

self.loggerdebug("Evaluating all features")
self.logger.debug("Evaluating all features")
for name, feature in features.items():
rules = feature.get(schema.RULES_KEY, {})
feature_default_value = feature.get(schema.FEATURE_DEFAULT_VAL_KEY)
if feature_default_value and not rules:
self.loggerdebug(f"feature is enabled by default and has no defined rules, name={name}")
self.logger.debug(f"feature is enabled by default and has no defined rules, name={name}")
features_enabled.append(name)
elif self._evaluate_rules(
feature_name=name, context=context, feat_default=feature_default_value, rules=rules
):
self.loggerdebug(f"feature's calculated value is True, name={name}")
self.logger.debug(f"feature's calculated value is True, name={name}")
features_enabled.append(name)

return features_enabled
10 changes: 5 additions & 5 deletions aws_lambda_powertools/utilities/feature_flags/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, schema: Dict[str, Any], logger=None):
self.logger = logger

def validate(self) -> None:
self.loggerdebug("Validating schema")
self.logger.debug("Validating schema")
if not isinstance(self.schema, dict):
raise SchemaValidationError(f"Features must be a dictionary, schema={str(self.schema)}")

Expand All @@ -127,7 +127,7 @@ def __init__(self, schema: Dict):

def validate(self):
for name, feature in self.schema.items():
self.loggerdebug(f"Attempting to validate feature '{name}'")
self.logger.debug(f"Attempting to validate feature '{name}'")
self.validate_feature(name, feature)
rules = RulesValidator(feature=feature)
rules.validate()
Expand All @@ -152,14 +152,14 @@ def __init__(self, feature: Dict[str, Any]):

def validate(self):
if not self.rules:
self.loggerdebug("Rules are empty, ignoring validation")
self.logger.debug("Rules are empty, ignoring validation")
return

if not isinstance(self.rules, dict):
raise SchemaValidationError(f"Feature rules must be a dictionary, feature={self.feature_name}")

for rule_name, rule in self.rules.items():
self.loggerdebug(f"Attempting to validate rule '{rule_name}'")
self.logger.debug(f"Attempting to validate rule '{rule_name}'")
self.validate_rule(rule=rule, rule_name=rule_name, feature_name=self.feature_name)
conditions = ConditionsValidator(rule=rule, rule_name=rule_name)
conditions.validate()
Expand Down Expand Up @@ -201,7 +201,7 @@ def validate_condition(self,rule_name: str, condition: Dict[str, str]) -> None:
raise SchemaValidationError(f"Feature rule condition must be a dictionary, rule={rule_name}")

# Condition can contain PII data; do not log condition value
self.loggerdebug(f"Attempting to validate condition for '{rule_name}'")
self.logger.debug(f"Attempting to validate condition for '{rule_name}'")
ConditionsValidator.validate_condition_action(condition=condition, rule_name=rule_name)
ConditionsValidator.validate_condition_key(condition=condition, rule_name=rule_name)
ConditionsValidator.validate_condition_value(condition=condition, rule_name=rule_name)
Expand Down

0 comments on commit 1233966

Please sign in to comment.