Skip to content

Commit

Permalink
fix(settings_file): logging for invalid settings file when fetched fr…
Browse files Browse the repository at this point in the history
…om server
  • Loading branch information
softvar committed Jun 8, 2023
1 parent caba67c commit e37ef04
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.46.1] - 2023-06-08

### Changed

- Print `settings-file` in the error log in case of `get_and_update_settings_file` API fails to fetch correct settings

## [1.46.0] - 2023-06-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_mutually_exclusive_newimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_traffic_weightage_campaigns(self):

# remove priority from settings file and initialize local vwo instance (so that logic flows to traffic weightage)
new_meg_settings_without_p = new_meg_settings
del new_meg_settings_without_p["groups"]["1"]["p"]
new_meg_settings_without_p["groups"]["1"].pop("p", None)
vwo_instance = vwo.launch(
json.dumps(new_meg_settings_without_p),
log_level=TEST_LOG_LEVEL,
Expand Down
4 changes: 1 addition & 3 deletions vwo/enums/log_message_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ class ERROR_MESSAGES:
CONNECTION_ERROR = "({file}): HTTP Connection - {reason}. Error - {err}"

BATCH_EVENT_LIMIT_EXCEEDED = "({file}): Impression event - {end_point} failed due to exceeding payload size. Parameter events_per_request in batch_events config in launch API has value:{events_per_request} for accountId:{account_id}. Please read the official documentation for knowing the size limits."
INVALID_SETTINGS_FILE = (
"({file}): [API_NAME] settings_file fetched is not proper for the account_id: {account_id}."
)
INVALID_SETTINGS_FILE = "({file}): [API_NAME] settings_file fetched is not proper for the account_id: {account_id}, settings_file: {settings_file}"

EVENT_BATCHING_NOT_OBJECT = "({file}): Batch event settings are not of type object"
EVENT_BATCHING_INSUFFICIENT = (
Expand Down
16 changes: 9 additions & 7 deletions vwo/services/settings_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@


class SettingsFileManager(object):
""" VWO settings_file manager """
"""VWO settings_file manager"""

def __init__(self, settings_file):
""" Init method to load and set vwo object with settings_file data.
"""Init method to load and set vwo object with settings_file data.
Args:
settings_file (json_string): stringified json representing the vwo settings_file.
Expand All @@ -38,20 +38,20 @@ def __init__(self, settings_file):

# PUBLIC METHODS
def process_settings_file(self):
""" Processes the settings_file, assigns variation allocation range """
"""Processes the settings_file, assigns variation allocation range"""

settings_file = self.settings_file
for campaign in settings_file.get("campaigns"):
campaign_util.set_variation_allocation(campaign)
self.logger.log(LogLevelEnum.DEBUG, LogMessageEnum.DEBUG_MESSAGES.SETTINGS_FILE_PROCESSED.format(file=FILE))

def get_settings_file(self):
""" Retrieves settings file """
"""Retrieves settings file"""

return self.settings_file

def get_settings_file_string(self):
""" Retrieves stringified json representing the settings_file """
"""Retrieves stringified json representing the settings_file"""

return self.settings_file_string

Expand All @@ -74,7 +74,9 @@ def get_and_update_settings_file(self, account_id, sdk_key, is_via_webhook):
if not validate_util.is_valid_settings_file(latest_settings_file):
self.logger.log(
LogLevelEnum.ERROR,
LogMessageEnum.ERROR_MESSAGES.INVALID_SETTINGS_FILE.format(file=FILE, account_id=account_id),
LogMessageEnum.ERROR_MESSAGES.INVALID_SETTINGS_FILE.format(
file=FILE, account_id=account_id, settings_file=latest_settings_file
),
)
return False

Expand All @@ -86,7 +88,7 @@ def get_and_update_settings_file(self, account_id, sdk_key, is_via_webhook):
return True

def update_settings_file(self, settings_file):
""" Update the settings_file on the instance so that latest settings could be used
"""Update the settings_file on the instance so that latest settings could be used
from next hit onwards
Args:
Expand Down

0 comments on commit e37ef04

Please sign in to comment.