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

core: Add basic system-config support #8572

Merged
merged 3 commits into from
Mar 3, 2023
Merged

core: Add basic system-config support #8572

merged 3 commits into from
Mar 3, 2023

Conversation

ooststep
Copy link
Contributor

Add support for reading environment variables from a config file on the system. The config file supports a single definition per line, defined as KEY=VALUE any whitespaces (other than '\n') will be preserved.

When loading environment variables, check this file for definitions as a fallback

Runtime definitions will overwrite system definitions

This targets an initial solution for #8308

Copy link
Contributor Author

@ooststep ooststep left a comment

Choose a reason for hiding this comment

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

adding some notes to take care of before merge - avoiding cycling CI before further review

src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
@ooststep
Copy link
Contributor Author

oops, need to use some OS abstraction to open/read the file.

src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
@ooststep
Copy link
Contributor Author

oops, need to use some OS abstraction to open/read the file.

I misunderstood the CI error at first. I think how I access the file should work, but the SYSCONFDIR preprocessor define seems undefined for Windows build.

src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
@shefty
Copy link
Member

shefty commented Feb 28, 2023

Please update the commit message title to something like "core: Add support for system-config files". I'm mostly focused on the 'core' part, so I can identify what component the patch applies to when running git log --oneline 6 months from now.

Copy link
Member

@shefty shefty left a comment

Choose a reason for hiding this comment

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

I'm thinking we may want to add an option to the config file to force it to override the system values in case of a conflict.

src/var.c Outdated Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
src/var.c Show resolved Hide resolved
src/var.c Outdated Show resolved Hide resolved
@ooststep
Copy link
Contributor Author

I'm thinking we may want to add an option to the config file to force it to override the system values in case of a conflict.

what system values? environment defined values will override config defined values

@ooststep ooststep changed the title Add basic system-config support core: Add basic system-config support Feb 28, 2023
@shefty
Copy link
Member

shefty commented Feb 28, 2023

I'm suggesting a separate change that allows the config file to override environment variables

src/var.c Outdated
Comment on lines 357 to 367
if (ofi_prefer_sysconfig) {
conf = find_conf_entry(param->env_var_name);
if (!conf) {
FI_INFO(provider, FI_LOG_CORE,
"variable %s=<not set>\n", param_name);
ret = -FI_ENODATA;
goto out;
FI_DBG(provider, FI_LOG_CORE,
"variable %s=<not set>, checking environment\n",
param_name);
str_value = getenv(param->env_var_name);
if (!str_value) {
FI_INFO(provider, FI_LOG_CORE,
"variable %s=<not set>\n", param_name);
ret = -FI_ENODATA;
goto out;
}
} else {
str_value = conf->value;
}
} else {
str_value = getenv(param->env_var_name);
if (!str_value) {
FI_DBG(provider, FI_LOG_CORE,
"variable %s=<not set>, checking system\n",
param_name);
conf = find_conf_entry(param->env_var_name);
if (!conf) {
FI_INFO(provider, FI_LOG_CORE,
"variable %s=<not set>\n", param_name);
ret = -FI_ENODATA;
goto out;
}
str_value = conf->value;
}
str_value = conf->value;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To reduce code duplication, you can read both conf and env first, and choose the right one based on preference. Something like:

if (ofi_prefer_sysconfig)
    str_value = conf->value ? conf->value : env_value;
else
    str_value = env_value ? env_value : conf->value;

if (!str_value)
    FI_DBG(.....);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did think about this and can move to this if preferred. my concern was adding extra calls to query the environment or looping through the config cache. I suppose the expectation is the cache should be pretty small so querying the environment would be the bigger concern, but we're doing that anyway today so maybe my concern was misplaced...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to remove duplication!

break;
}

dlist_insert_tail(&conf->entry, &conf_list);
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add FI_INFO() here using the core to print all read name-value pairs. This can be added as a separate change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the logging interface requires an instance of a provider, so we can either dump this late (maybe during getinfo?) or we need to add a logging function with that requirement removed.

Copy link
Member

Choose a reason for hiding this comment

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

Use 'core_prov', which is for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, tmyk...

Other issue is that this takes place prior to fi_log_init, so the logging system hasn't been initialized. The logging system relies on these variables, so it seems a catch 22

Copy link
Member

Choose a reason for hiding this comment

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

bah, i guess we'll figure it out when the variables are assigned.

Add support for reading environment variables from
a config file on the system.  The config file supports
a single definition per line, defined as KEY=VALUE
any whitespaces (other than '\n') will be preserved.

When loading environment variables, check this file
for definitions as a fallback

Runtime definitions will overwrite system definitions

Signed-off-by: Stephen Oost <stephen.oost@intel.com>
There are some situations where the user or administrator
will want to force system-configured values for certain
variables.  This switch enables the config file to
select such an option.

Signed-off-by: Stephen Oost <stephen.oost@intel.com>
@ooststep ooststep force-pushed the main branch 2 times, most recently from a683510 to b9c6b7c Compare March 2, 2023 14:58
Signed-off-by: Stephen Oost <stephen.oost@intel.com>
@shefty shefty merged commit 2355120 into ofiwg:main Mar 3, 2023
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.

None yet

3 participants