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

Sapcontrol gatherer #270

Merged
merged 7 commits into from
Oct 10, 2023
Merged

Sapcontrol gatherer #270

merged 7 commits into from
Oct 10, 2023

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Oct 4, 2023

sapcontrol gatherer.
It supports the GetProcessList, GetSystemInstanceList, GetVersionInfo, HACheckConfig and HAGetFailoverConfig webmethods.
It caches the outputs of the commands so they are executed only once.

I have taken the autogenerated code from sap_host_exporter
Only the strictly required fields. More info about the auto generated code here
Find here the sapcontrol api: https://www.sap.com/documents/2016/09/0a40e60d-8b7c-0010-82c7-eda71af511fa.html

By now, I have not included the CheckHostAgent, as it is not available in the public API. In fact, I think we could leverage the saphostctrl gatherer Ping function. I know it is not 100% the same, but I think it would validate what we need. Wdyt @abravosuse ?
Anyway, if it is 100% needed, i would include it in a future PR.

@arbulu89 arbulu89 added the enhancement New feature or request label Oct 4, 2023
}

// Trick to keep the SIDs as capital letter
result := &entities.FactValueMap{Value: make(map[string]entities.FactValue)}
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 need to apply this "trick" to keep the SIDs as capital letter. All the other gatherers have them with this format.
Other solution (with more code) would be to have internal data structs that are almost identical with the ones coming from sapcontrolapi but with snake_case json output

@arbulu89 arbulu89 marked this pull request as ready for review October 5, 2023 06:35
@abravosuse
Copy link

abravosuse commented Oct 5, 2023

@arbulu89 the Ping function of saphostctrl tell us whether a (installed) SAP host agent is running or not. The CheckHostAgent function of sapcontrol tell us whether a SAP host agent is installed or not. You could have a SAP Host Agent that is installed but not running, so they are different things.

For me, what really matters, is whether is running or not . An SAP Host Agent that is installed but not running is useless. So I agree with you that using the Ping function is more useful than using the CheckHostAgent one. That said I would like to clarify with the checks team why they are interested in that particular function.

I make a note to discuss this with them in our next call.

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.

Good job, nothing to address about the implementation/logic

Just some readability style comments

cachedFact, cacheHit := cachedFacts[factReq.Argument]

switch {
case len(factReq.Argument) == 0:
Copy link
Member

Choose a reason for hiding this comment

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

We can move this case to an if statement on line 119 before initializing the webmethod etc..

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 have moved the conditions to use if/continues instead of the switch, so we don't need to initialize variables needlesly.

webmethod, ok := whitelistedSapControlArguments[factReq.Argument]
cachedFact, cacheHit := cachedFacts[factReq.Argument]

switch {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add {} around the cases? So we don't use only the indent but we have a clear barrier of the case structure, so it's easier to follow and read

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 have removed the switch at the end, so no need for this


if factValue, err := outputToFactValue(sapControlMap); err != nil {
gatheringError := SapcontrolDecodingError.Wrap(err.Error())
log.Error(gatheringError)
Copy link
Member

Choose a reason for hiding this comment

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

Could we add more info here, like the argument

internal/factsengine/gatherers/sapcontrol.go Show resolved Hide resolved
sapControlMap := make(SapControlMap)
for sid, instances := range foundSystems {
sapControlInstance := []SapControlInstance{}
for _, instanceData := range instances {
Copy link
Member

Choose a reason for hiding this comment

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

could we extract instanceData[0] and [1] to variables, it's used in more places, it's easier to read

@arbulu89 arbulu89 requested a review from CDimonaco October 9, 2023 15:29
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.

LGTM

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.

LGTM!

@arbulu89 arbulu89 merged commit f41d120 into main Oct 10, 2023
9 checks passed
@arbulu89 arbulu89 deleted the sapcontrol-gatherer branch October 10, 2023 11:44
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.

4 participants