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

Add saptune discovery #253

Merged
merged 9 commits into from
Sep 19, 2023
Merged

Add saptune discovery #253

merged 9 commits into from
Sep 19, 2023

Conversation

rtorrero
Copy link
Contributor

Add initial implementation of the saptune --format json status and expose this through the collector

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.

Hey @rtorrero ,
Some initial comments.
Besides that, I wonder how this code could be reusable in a gatherer. I would maybe expect some RunSaptuneCommand(cmd, format), where you pass the command you want to execute and maybe the format.

internal/agent/agent.go Outdated Show resolved Hide resolved
internal/core/saptune/saptune.go Outdated Show resolved Hide resolved
internal/core/saptune/saptune.go Show resolved Hide resolved
internal/core/saptune/saptune.go Outdated Show resolved Hide resolved
internal/core/saptune/saptune.go Show resolved Hide resolved
internal/core/saptune/saptune.go Outdated Show resolved Hide resolved
internal/core/saptune/saptune.go Show resolved Hide resolved
internal/core/saptune/saptune.go Outdated Show resolved Hide resolved
@rtorrero rtorrero marked this pull request as ready for review September 15, 2023 09:12
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.

Hey @rtorrero
Some feedback.
Consider adding a IsJsonSupported field. I think it will come really useful in the gatherers as well, as we can skip running command functions since the beginning

return nil, ErrUnsupportedSaptuneVer
}

log.Info("Requesting Saptune status...")
Copy link
Contributor

Choose a reason for hiding this comment

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

These initial log messages are outdated, right?

internal/core/saptune/saptune.go Show resolved Hide resolved
}

func (s *Saptune) RunCommand(args ...string) ([]byte, error) {
if !isSaptuneVersionSupported(s.Version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we want to run this for every command?
If we had the isJsonSupported field, we could avoid running this.
Actually, the code owner (us) could even avoid using RunCommand, as we know that json is not supported before hand

)

type Saptune struct {
Version string `json:"version"`
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 think we need the json annotation.
This struct is internal, not meant to be marshalled

internal/core/saptune/saptune_test.go Show resolved Hide resolved

func (d SaptuneDiscovery) Discover() (string, error) {
saptuneRetriever, err := saptune.NewSaptune(utils.Executor{})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot do that. Even if we get some error here, we need to send a payload, with the PackageVersion: null/empty string, SaptuneInstalled: false and Status: nil

internal/discovery/saptune.go Outdated Show resolved Hide resolved
internal/discovery/saptune.go Outdated Show resolved Hide resolved
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.

Looking good!
Almost ready to merge, once we fix the linting things mostly

func NewSaptune(commandExecutor utils.CommandExecutor) (Saptune, error) {
saptuneVersion, err := getSaptuneVersion(commandExecutor)
if err != nil {
return Saptune{Version: ""}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could simply return Saptune{}

return Saptune{Version: ""}, err
}

return Saptune{Version: saptuneVersion, executor: commandExecutor, IsJSONSupported: isSaptuneVersionSupported(saptuneVersion)}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to store the result in a variable, just to improve readability

internal/core/saptune/saptune.go Outdated Show resolved Hide resolved

saptuneRetriever, err := NewSaptune(mockCommand)

expectedDetails := Saptune{
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could name this expectedSaptune. Wdyt?

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.

@rtorrero green light from my side.
It would be nice to run some manual integration test between agent and web to see that it works.
(remember that there is a pending PR in web which fixes the policy)

}

prependedArgs := append([]string{"--format", "json"}, args...)
log.Infof("Running saptune command: saptune %v", args)
Copy link
Contributor

@arbulu89 arbulu89 Sep 18, 2023

Choose a reason for hiding this comment

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

We could reuse the main RunCommand once we have the new args.
Not a big deal

return s.RunCommand(prependedArgs)

default:
saptuneData, _ := saptuneRetriever.RunCommandJSON("status")
unmarshalled := make(map[string]interface{})
_ = json.Unmarshal(saptuneData, &unmarshalled)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should capture the error and exit if there is any.
Just for safetiness.
The status should always return a json, but just in case...

@arbulu89 arbulu89 added the enhancement New feature or request label Sep 18, 2023
@rtorrero rtorrero merged commit c802521 into main Sep 19, 2023
10 checks passed
@rtorrero rtorrero deleted the add-saptune-discovery branch September 19, 2023 10:04
@rtorrero rtorrero mentioned this pull request Sep 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
Development

Successfully merging this pull request may close these issues.

2 participants