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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sbd loading #145

Merged
merged 2 commits into from
Nov 22, 2022
Merged

Refactor sbd loading #145

merged 2 commits into from
Nov 22, 2022

Conversation

nelsonkopliku
Copy link
Member

@nelsonkopliku nelsonkopliku commented Nov 18, 2022

Description

Sbd configuration gets read in the two major processes of the agent:

  • Discovery (cluster)
  • Facts Gathering (sbd_config gatherer)

This PR reduces some duplication of sbd configuration file loading and in discovery/facts gathering.

Notes:
utils.FindMatches('(?m)^(\w+)=(\S[^#\s]*)', sbdConfigRaw) has been superseded by envparse.Parse(sbdConfigFile).
A subtle difference here is that FindMatches ignores empty values like SBD_OPTS= while envparse decodes to empty string.

This means that the cluster discovery would also have "SBD_OPTS": "" among the other configs.

Would this break something? 馃槄 I tried and it does not break things up.
Should we make sure to skip empty entries when parsing? I believe we should return sbd config entries even if they're empty, see #145 (comment)

Copy link
Member

@fabriziosestito fabriziosestito left a comment

Choose a reason for hiding this comment

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

Would this break something? sweat_smile

@nelsonkopliku I think that before considering changing this, this question should be answered by adding automated tests where needed

return nil, &SBDConfigLoadingError{
Type: SDBConfigDecodingError,
inner: errors.Wrap(err, "could not read sbd config file"),
}
Copy link
Member

Choose a reason for hiding this comment

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

in case we could remove the extra entries so the output is the same to what we had with the regex

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this. I think we should return the empty values if they are configured
Imagine that you want to create a check to see if the configured value has an empty string.
Like Check SBD_OPTS has not additional values and you see that it is not changed.
I don't know, this hides information.

Not having those values in the past shouldn't be a reason not to add them now.

Copy link
Member Author

Choose a reason for hiding this comment

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

At the end I returned to my first proposal of not skipping empty values in config and covered in test.

If this is sorted out we need to agree on trento-project/web#996.

@nelsonkopliku
Copy link
Member Author

adding automated tests where needed

I made this change on trento web trento-project/web#996 and let e2e tests tell us if integration does not break 馃槄

Would that be enough?

@nelsonkopliku
Copy link
Member Author

@fabriziosestito made the change you suggested.
Now if an existing entry in sbd config is an empty string, that entry gets removed from the parsed config.

This also means that if we do something like

facts:
  - name: sbd_opts
    gatherer: sbd_config
    argument: SBD_OPTS # or any other possibly empty entry

We'll get a FactGatheringError saying sbd-config-value-not-found.
We can start like this, it's good enough I believe, anyway I see a little discrepancy with the fact that the config value was actually there, it was just empty.
It depends on what meaning we want to give to the emptiness of a config entry and if that state is an error or something we'd like to know as a fact in our expectations.

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Folks, sorry for arriving late, but I think that the removal of empty values is a bad idea. We are hiding real configuration, that might be useful in the checks for example.
Senging a new field with an empty value shouldn't be a problem for the web, as most probably we don't use that field.

Besides that, I find the error handling way complicated

internal/cluster/sbd.go Outdated Show resolved Hide resolved
return nil, &SBDConfigLoadingError{
Type: SDBConfigDecodingError,
inner: errors.Wrap(err, "could not read sbd config file"),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this. I think we should return the empty values if they are configured
Imagine that you want to create a check to see if the configured value has an empty string.
Like Check SBD_OPTS has not additional values and you see that it is not changed.
I don't know, this hides information.

Not having those values in the past shouldn't be a reason not to add them now.

internal/cluster/sbd.go Show resolved Hide resolved
internal/factsengine/gatherers/sbd.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/sbd.go Outdated Show resolved Hide resolved
@nelsonkopliku nelsonkopliku force-pushed the refactor_sbd_loading branch 4 times, most recently from 434db46 to ea8b0f6 Compare November 22, 2022 09:57
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@nelsonkopliku Green light from my side.
I commented 2 minor things that don't need an extra review.

internal/cluster/sbd.go Outdated Show resolved Hide resolved
internal/cluster/sbd_test.go Outdated Show resolved Hide resolved
@nelsonkopliku nelsonkopliku merged commit f76e000 into main Nov 22, 2022
@nelsonkopliku nelsonkopliku deleted the refactor_sbd_loading branch November 22, 2022 14:32
@arbulu89 arbulu89 added the enhancement New feature or request label Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech debt
Development

Successfully merging this pull request may close these issues.

None yet

3 participants