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

Implement saphostctrl gatherer #71

Merged
merged 10 commits into from
Dec 23, 2022
Merged

Implement saphostctrl gatherer #71

merged 10 commits into from
Dec 23, 2022

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Aug 5, 2022

saphostctrl gatherer. Simply returns the output of this commands.

Example:

./trento-agent facts gather --gatherer saphostctrl --argument Ping
INFO[2022-08-05 09:12:00] Starting saphostctrl facts gathering process 
INFO[2022-08-05 09:12:00] Requested saphostctrl facts gathered         
INFO[2022-08-05 09:12:00] Gathered fact for "saphostctrl" with argument "Ping": 
INFO[2022-08-05 09:12:00] {
  "name": "Ping",
  "value": "SUCCESS (  548364 usec)\n",
  "check_id": ""
} 

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

Looks good!

Then, sorry if I bother you with DSL examples 😅 yet I it helps me to keep a connection between the different aspects.

In this case a user would write this piece of yaml

facts:
    - name: my_saphostctrl_ping
      gatherer: saphostctrl
      argument: Ping

LGTM

@arbulu89 arbulu89 force-pushed the saphostctrl-gatherer branch 2 times, most recently from d7d95c6 to 7f0308f Compare August 9, 2022 09:35
Copy link
Member

@CDimonaco CDimonaco left a comment

Choose a reason for hiding this comment

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

Just the DI thing, than LGTM

Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

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

Just a comment, then we can merge

internal/factsengine/gatherers/saphostctrl_test.go Outdated Show resolved Hide resolved
@arbulu89 arbulu89 force-pushed the saphostctrl-gatherer branch from f08bd33 to 7f0308f Compare August 9, 2022 12:57
Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

For my side, all relevant things have already been addressed or discussed and agreed to be addressed in next PRs (including the DI).

LGTM

@nelsonkopliku nelsonkopliku self-requested a review August 22, 2022 07:47
@arbulu89 arbulu89 force-pushed the saphostctrl-gatherer branch from 7f0308f to 10b4b15 Compare August 29, 2022 07:32
@arbulu89
Copy link
Contributor Author

@dottorblaster @dottorblaster Finally the requested changes rebased. Could you have a 2nd look?

@rtorrero rtorrero force-pushed the saphostctrl-gatherer branch from 10b4b15 to 74f90c7 Compare December 20, 2022 16:26
@rtorrero
Copy link
Contributor

rtorrero commented Dec 22, 2022

@arbulu89 @dottorblaster @CDimonaco @nelsonkopliku I've updated the gatherer to match the latest change in the fact gathering process and improved a bit how the output looks. Take a look at the tests to see if you agree this is usable, and I'll go ahead and write the docs.

Basically, the changes in the output are that we now use a map with parsed output fields instead of the whole output as a single string.

@rtorrero rtorrero force-pushed the saphostctrl-gatherer branch from 1129bcf to 7720a66 Compare December 22, 2022 09:21
Copy link
Contributor Author

@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.

Hey @rtorrero ,
Some changes requested.
Besides that, I would say some paths of the code are not tested (some parsing errors, command error, etc)

internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl_test.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl_test.go Outdated Show resolved Hide resolved
[]byte("SUCCESS ( 543341 usec)\n"), nil)
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "ListInstances").Return(
[]byte(" Inst Info : PRD - 00 - myhost-vmhana02 - 753, patch 410, changelist 1908545\n"), nil)

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 would add other scenario when there is not any instance, to see that it returns an empty map

Copy link
Member

Choose a reason for hiding this comment

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

And we're probably missing a test for a failed ListInstances as well

@rtorrero rtorrero force-pushed the saphostctrl-gatherer branch 2 times, most recently from 2603ee1 to e9f0e63 Compare December 22, 2022 17:23
@rtorrero
Copy link
Contributor

@arbulu89 I've addressed some of your concerns and marked them as "resolved" for others, I've come with slightly different approaches but those should also cover your concerns. Please take a look at let me know 👍

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

Looks good Ruben, thanks!

I noted down a few minor things and then for me we're good.

internal/factsengine/gatherers/saphostctrl_test.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Show resolved Hide resolved
[]byte("SUCCESS ( 543341 usec)\n"), nil)
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "ListInstances").Return(
[]byte(" Inst Info : PRD - 00 - myhost-vmhana02 - 753, patch 410, changelist 1908545\n"), nil)

Copy link
Member

Choose a reason for hiding this comment

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

And we're probably missing a test for a failed ListInstances as well

Copy link
Contributor Author

@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.

Hey @rtorrero ,
I find the code difficult to follow with so many functions that are not meant to be functions (in my opinion), as they are not reused. And this creates the need to duplicate code many times.
I don't know I have the feeling you aimed to an extreme tailoring for functions. To makes reading difficult, as you need to scroll up and down constantly.

internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/saphostctrl.go Outdated Show resolved Hide resolved
instance["system"] = &entities.FactValueString{Value: fields[1]}
instance["instance"] = &entities.FactValueString{Value: fields[2]}
instance["hostname"] = &entities.FactValueString{Value: fields[3]}
instance["revision"] = &entities.FactValueString{Value: fields[4]}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

shouldn't revision, patch and changelist be integers?

}

pingData["status"] = &entities.FactValueString{Value: matches[1]}
pingData["elapsed"] = &entities.FactValueString{Value: matches[2]}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't elapsed be an integer?

}
SapHostCtrlUnsupportedFunction = entities.FactGatheringError{
Type: "saphostctrl-webmethod-error",
Message: "requested webmethod not whitelisted",
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 would rephrase this to requested webmethod is not supported

func (suite *SapHostCtrlTestSuite) TestSapHostCtrlGatherError() {
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "Ping").Return(
[]byte("FAILURE\n"), nil)
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "Pong").Return(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about an scenario where the command fails.
Here we have a

  • parsing error
  • unsupported command

So we miss the command error test

Copy link
Contributor Author

@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.

@rtorrero
Super perfect from my side! I cannot approve since I opened the PR XD

@arbulu89 arbulu89 dismissed stale reviews from dottorblaster and CDimonaco December 23, 2022 12:23

Old review

@rtorrero rtorrero merged commit 3798072 into main Dec 23, 2022
@rtorrero rtorrero deleted the saphostctrl-gatherer branch December 23, 2022 13:36
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.

5 participants