Skip to content

Commit

Permalink
Port 4484 change ocean sail default log level (#69)
Browse files Browse the repository at this point in the history
* changed default log level and fixed config bug
  • Loading branch information
yairsimantov20 authored Aug 11, 2023
1 parent e5e9a89 commit d4bebea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/1.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue with loading the configuration from the environment variables if the config is a dictionary
1 change: 1 addition & 0 deletions changelog/1.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed default log level to INFO in the cli
4 changes: 2 additions & 2 deletions port_ocean/cli/commands/sail.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"--log-level",
"log_level",
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
default="DEBUG",
default="INFO",
help="""Set the logging level for the integration.
Supported levels are DEBUG, INFO, WARNING, ERROR,
and CRITICAL. If not specified, the default level
is DEBUG.""",
is INFO.""",
)
@click.option(
"-p",
Expand Down
18 changes: 15 additions & 3 deletions port_ocean/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,27 @@ def load_from_config_provider(config_provider: str) -> Any:


def parse_providers(
settings_model: BaseModel | ModelMetaclass,
config: dict[str, Any],
existing_data: dict[str, Any],
) -> dict[str, Any]:
"""
Normalizing the config yaml file to work with snake_case and getting only the data that is missing for the settings
"""
for key, value in config.items():
if isinstance(value, dict):
existing_data[key] = parse_providers(value, existing_data.get(key, {}))
if isinstance(value, dict) and settings_model is not None:
# If the value is of type ModelMetaClass then its a nested model, and we need to parse it
# If the value is of type primitive dict then we need to decamelize the keys and not recurse into the values because its no longer part of the model
_type = settings_model.__annotations__[key]
is_primitive_dict_type = _type is dict or (
isinstance(_type, GenericAlias) and _type.__origin__ is dict
)

if is_primitive_dict_type:
_type = None
existing_data[key] = parse_providers(
_type, value, existing_data.get(key, {})
)

elif isinstance(value, str):
# If the value is a provider, we try to load it from the provider
Expand Down Expand Up @@ -114,7 +126,7 @@ def load_providers(
yaml_content = read_yaml_config_settings_source(settings, base_path)
data = yaml.safe_load(yaml_content)
snake_case_config = decamelize_config(settings, data)
return parse_providers(snake_case_config, existing_values)
return parse_providers(settings, snake_case_config, existing_values)


class BaseOceanSettings(BaseSettings):
Expand Down
2 changes: 1 addition & 1 deletion port_ocean/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _create_default_app(path: str | None = None) -> Ocean:

def run(
path: str = ".",
log_level: LogLevelType = "DEBUG",
log_level: LogLevelType = "INFO",
port: int = 8000,
initialize_port_resources: bool | None = None,
) -> None:
Expand Down

0 comments on commit d4bebea

Please sign in to comment.