Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable env parser #151

Merged
merged 7 commits into from
Aug 3, 2023
Merged

Configurable env parser #151

merged 7 commits into from
Aug 3, 2023

Conversation

DenysGonchar
Copy link
Collaborator

This PR introduces the following changes:
• Possibility to customise parsing (de-serialisation) logic for env variables.
• small improvements for amoc_config_scenario:update_settings/1 logic.
• extension of the tests.

Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very nice, just minor comments and perhaps a need for documenting the new possibility to configure the parser module

Comment on lines +41 to +45
?LOG_ERROR("cannot parse environment variable, using default value.~n"
" parsing error: '~p'~n"
" variable name: '$~s'~n"
" variable value: '~s'~n"
" default value: '~p'~n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I see these, can we use structured logging? Like, maps with keys and values. Maybe in a separate PR if there's plenty of these things anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth to have a separate dedicated PR with all the logs reworked.

src/amoc_config/amoc_config_env.erl Outdated Show resolved Hide resolved
src/amoc_config/amoc_config_env.erl Outdated Show resolved Hide resolved
Comment on lines +49 to +51
-type mfa(Arity) :: {module(), atom(), Arity}.
-type verification_method() :: none | one_of() | mfa(1) | verification_fun().
-type update_method() :: read_only | none | mfa(2) | update_fun().
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea


-include_lib("kernel/include/logger.hrl").

-define(DEFAULT_PARSER_MODULE, amoc_config_parser).

-callback(parse_value(string()) -> {ok, amoc_config:value()} | {error, any()}).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a perfect idea, but it only requires now documentation on how to do so when you want to add a different parser. So some md file in the guides directory, link it in the rebar config for hex like the others, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a separate dedicated PR with documentation update.

Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌🏽

@NelsonVides NelsonVides merged commit ffff0fe into master Aug 3, 2023
4 checks passed
@NelsonVides NelsonVides deleted the configurable-env-parser branch August 3, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants