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

sysctl gatherer #268

Merged
merged 7 commits into from
Oct 9, 2023
Merged

sysctl gatherer #268

merged 7 commits into from
Oct 9, 2023

Conversation

rtorrero
Copy link
Contributor

@rtorrero rtorrero commented Sep 29, 2023

This PR adds a sysctl. Note: Right now, it will fail if no argument is provided but if we want, we could allow zero arguments to return the whole sysctl map.

@rtorrero rtorrero marked this pull request as ready for review September 29, 2023 14:28
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.

We need to add the gatherer to the list of standard gatherers
The envparse usage comment is a personal opinion. I think that it would simplify the code. Specially, because i don't expect the gatherer being called with "intermediate" values

PD: Please, test things manually as well, to see that it does what we expect


func (s *SysctlGatherer) Gather(factsRequests []entities.FactRequest) ([]entities.Fact, error) {
facts := []entities.Fact{}
log.Infof("Starting sysctl facts gathering process")
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use the string interpolation with SysctlGathererName as we do with many others.
Small change, but it would help us if we for some reason change the gatherer name, to not forget this details

facts = append(facts, fact)
}

log.Infof("Requested %s facts gathered", CorosyncCmapCtlGathererName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to change this I guess hehe

return facts, nil
}

func sysctlOutputToMap(output []byte) *entities.FactValueMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we try to use envparse.Parse(output) maybe?
At the end the output looks like an .env file format.
I know that this wouldn't create a map of maps, but I don't think we would need such a thing in this case. I expect the user putting the whole needed line to get individual values

I would try to change, you have the tests there to confirm that everything went right

PD: I know that this is based in the corosynccmapctl gatherer, but i think we could make it simpler this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it's based on the corosync one, I saw a comment in confluence mentioning that we might want to expose sysctl -a (with no arguments) as a map, so I used the same approach. In the end apparently we don't need this but if we do in the future, the current approach would be more powerful. In any case, no hard opinions on this.

Copy link
Contributor

@arbulu89 arbulu89 Oct 2, 2023

Choose a reason for hiding this comment

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

Anyway, do we need all of this switch code with the SplitN?
I think the corosynccmapctl code is cleaner, and does exactly the same (99% the same)

parts := strings.Split(line, " =")
key := parts[0]
value := parts[1]

internal/factsengine/gatherers/sysctl_test.go Outdated Show resolved Hide resolved
@rtorrero rtorrero force-pushed the add-sysctl-gatherer branch from f58b533 to 121affa Compare October 2, 2023 11:10
@rtorrero rtorrero requested a review from arbulu89 October 2, 2023 11:21
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.

Green light from my side.
Added some comments, but judge yourself :D

cursor := outputMap
pathComponents := strings.Split(key, ".")

for i, component := range pathComponents {
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think that the code in corosynccmapctl is simpler, with less if/else branching.
Anyway, I guess it works fine

internal/factsengine/gatherers/sysctl_test.go Show resolved Hide resolved
for _, line := range strings.Split(string(output), "\n") {
parts := strings.SplitN(line, "=", 2)
if len(line) == 0 || len(parts) != 2 {
continue
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 know if we shouldn't raise an error in this case, as we would get a malformed output

Copy link
Contributor

Choose a reason for hiding this comment

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

Some sort of decoding error as we do in other gatherers

@rtorrero rtorrero merged commit 0a5bf24 into main Oct 9, 2023
9 checks passed
@rtorrero rtorrero deleted the add-sysctl-gatherer branch October 9, 2023 13:04
@CDimonaco CDimonaco added the enhancement New feature or request label Nov 14, 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
Development

Successfully merging this pull request may close these issues.

3 participants