Skip to content

Commit

Permalink
slightly adapted telemetry printing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Sep 24, 2020
1 parent 957c4b7 commit f72da5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 11 additions & 7 deletions rasa/telemetry.py
Expand Up @@ -118,13 +118,16 @@ def _default_telemetry_configuration(is_enabled: bool) -> Dict[Text, Any]:

def _write_default_telemetry_configuration(
is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT,
) -> None:
if is_enabled and os.environ.get(TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE) is None:
print_telemetry_reporting_info()

) -> bool:
new_config = _default_telemetry_configuration(is_enabled)

rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config)
success = rasa_utils.write_global_config_value(
CONFIG_FILE_TELEMETRY_KEY, new_config
)

if is_enabled and success:
print_telemetry_reporting_info()
return success


def _is_telemetry_enabled_in_configuration() -> bool:
Expand All @@ -145,8 +148,9 @@ def _is_telemetry_enabled_in_configuration() -> bool:
logger.debug(f"Could not read telemetry settings from configuration file: {e}")

# seems like there is no config, we'll create on and enable telemetry
_write_default_telemetry_configuration()
return TELEMETRY_ENABLED_BY_DEFAULT
success = _write_default_telemetry_configuration()
# if writing the configuration failed, telemetry will be disabled
return TELEMETRY_ENABLED_BY_DEFAULT and success


def is_telemetry_enabled() -> bool:
Expand Down
13 changes: 11 additions & 2 deletions rasa/utils/common.py
Expand Up @@ -186,9 +186,16 @@ def sort_list_of_dicts_by_first_key(dicts: List[Dict]) -> List[Dict]:
return sorted(dicts, key=lambda d: list(d.keys())[0])


def write_global_config_value(name: Text, value: Any) -> None:
"""Read global Rasa configuration."""
def write_global_config_value(name: Text, value: Any) -> bool:
"""Read global Rasa configuration.
Args:
name: Name of the configuration key
value: Value the configuration key should be set to
Returns:
`True` if the operation was successful.
"""
# need to use `rasa.constants.GLOBAL_USER_CONFIG_PATH` to allow patching
# in tests
config_path = rasa.constants.GLOBAL_USER_CONFIG_PATH
Expand All @@ -198,8 +205,10 @@ def write_global_config_value(name: Text, value: Any) -> None:
c = read_global_config(config_path)
c[name] = value
rasa.shared.utils.io.write_yaml(c, rasa.constants.GLOBAL_USER_CONFIG_PATH)
return True
except Exception as e:
logger.warning(f"Failed to write global config. Error: {e}. Skipping.")
return False


def read_global_config_value(name: Text, unavailable_ok: bool = True) -> Any:
Expand Down

0 comments on commit f72da5f

Please sign in to comment.