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

VAULT-19681 allow users to specify files for agent child process stdout/stderr #22812

Merged
merged 22 commits into from
Sep 12, 2023

Conversation

dhuckins
Copy link
Contributor

@dhuckins dhuckins commented Sep 6, 2023

Adds ability for the user to send stderr and stdout of the child process to files

@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Sep 6, 2023
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

CI Results:
All Go tests succeeded! ✅

@dhuckins dhuckins added this to the 1.15 milestone Sep 8, 2023
AgentConfig: c.config,
Namespace: templateNamespace,
Logger: c.logger.Named("exec.server"),
LogLevel: c.logger.GetLevel(),
LogWriter: c.logWriter,
})
if err != nil {
c.logger.Error("could not create exec server", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

@@ -800,6 +804,7 @@ func (c *AgentCommand) Run(args []string) int {
leaseCache.SetShuttingDown(true)
}
cancelFunc()
es.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need an if es != nil or would that be overly defensive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think it would be overly defensive, es would only be nil if there was an error opening one of the log files and in that case would exit early

or should we check anyway b/c its in a closure?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll leave it up to you -- I think it wouldn't hurt, but like you said, I can't really see how we'd get to that point

command/agent/exec/exec.go Outdated Show resolved Hide resolved
@@ -380,3 +385,164 @@ func TestExecServer_Run(t *testing.T) {
})
}
}

func TestExecServer_LogFiles(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can tell, this only tests the stderr case -- we should add a test for stdout too.

changelog/22812.txt Outdated Show resolved Hide resolved
command/agent/exec/exec_test.go Show resolved Hide resolved
@github-actions
Copy link

Build Results:
All builds succeeded! ✅

Copy link
Contributor

@averche averche left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. Could you please add "agent" to the title/description.

command/agent/config/config.go Show resolved Hide resolved
command/agent/exec/exec.go Outdated Show resolved Hide resolved
command/agent/exec/exec_test.go Outdated Show resolved Hide resolved
@anwittin anwittin modified the milestones: 1.15.0-rc1, 1.15.0 Sep 11, 2023
@dhuckins dhuckins changed the title VAULT-19681 allow users to specify files for child process stdout/stderr VAULT-19681 allow users to specify files for agent child process stdout/stderr Sep 12, 2023
Copy link
Contributor

@VioletHynes VioletHynes 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! Thanks for this! Feel free to tag me on the docs PR, too!

Comment on lines 370 to 371
_ = s.childProcessStdout.Close()
_ = s.childProcessStderr.Close()
Copy link
Contributor

@averche averche Sep 12, 2023

Choose a reason for hiding this comment

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

Would this potentially close the global os.Stdout and os.Stderr? https://go.dev/play/p/ksHYajR4CVU

Perhaps you can check if s.childProcessStdout != os.Stdout { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! why I had it in the first place.
will add back the bools
(think its messing with tests anyway)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the if != os.Stdout approach a little more, if we're guarding against this -- the bools are a little confusing, I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

^^ fair, will do that

Copy link
Contributor

@averche averche left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@dhuckins dhuckins merged commit d1e1abd into main Sep 12, 2023
106 checks passed
@dhuckins dhuckins deleted the dh/VAULT-19681 branch September 12, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants