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

feat(jobreceiver): Implement the command package #1240

Merged
merged 11 commits into from
Sep 22, 2023
Merged

Conversation

c-kruse
Copy link
Contributor

@c-kruse c-kruse commented Sep 7, 2023

Implements pkg/receiver/jobreceiver/command/command

I had a hard time with this one. I started by copying the work @portertech did in the PoC that had been adapted from sensu, but I ran into several issues.

First. The sensu command package had lots of opinionated behavior that I felt was not appropriate to copy over. Things like timeout behavior (hard coding exit code 2 and writing a blurb to stderr). More difficult to suss out was the bespoke timeout, process group and cleanup logic that all seemed geared towards the assumption of a shell environment (which is no longer obligated.)

Second. Our usage pattern here is different than Sensu's. Sensu's command interface buffers the entirety of command output before returning it to the caller. Here we need to stream that output to the pipeline to accommodate the log_entries output format. Handling this inner process communication is actually quite nuanced. Go's os/exec package takes a reasonable approach to handling this with exec.Cmd.Std[out|err]Pipe but it wasn't particularly compatible with sensu's command interface or the way it was doing timeouts.

In the end I decided to lean towards default behavior and accept that we may end up needing to re-learn some of lessons in the future.

Adds a new jobreceiver/command package that encapsulates the handling of
executing commands. Mostly borrowed from sensu-go's robust commands
package used by it's multi-platform agents.

Signed-off-by: Christian Kruse <[email protected]>
@github-actions github-actions bot added the go label Sep 7, 2023
@c-kruse c-kruse force-pushed the ck/jobreceiver-command branch from ea23a21 to 7393266 Compare September 7, 2023 18:08
Signed-off-by: Christian Kruse <[email protected]>
@c-kruse c-kruse force-pushed the ck/jobreceiver-command branch from 7393266 to c407b49 Compare September 7, 2023 18:12
@c-kruse c-kruse marked this pull request as ready for review September 7, 2023 18:16
@c-kruse c-kruse requested a review from a team as a code owner September 7, 2023 18:16
@c-kruse c-kruse force-pushed the ck/jobreceiver-command branch from d23dfe8 to 98c5bea Compare September 7, 2023 22:52
Signed-off-by: Christian Kruse <[email protected]>
Copy link
Collaborator

@echlebek echlebek left a comment

Choose a reason for hiding this comment

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

It looks good to me but I suppose we should also wait for review from someone who has been on the OSC team a bit longer. I found a few doc nits.

pkg/receiver/jobreceiver/command/command.go Outdated Show resolved Hide resolved
pkg/receiver/jobreceiver/command/command.go Outdated Show resolved Hide resolved
@fguimond fguimond requested a review from a team September 21, 2023 14:18
Copy link

@swiatekm swiatekm 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 overall, had some questions about tests and the platform-specific bits.

pkg/receiver/jobreceiver/command/command_test.go Outdated Show resolved Hide resolved
pkg/receiver/jobreceiver/command/command_test.go Outdated Show resolved Hide resolved
Signed-off-by: Christian Kruse <[email protected]>
@c-kruse c-kruse enabled auto-merge (squash) September 22, 2023 16:46
@c-kruse c-kruse merged commit 5b028e2 into main Sep 22, 2023
27 checks passed
@c-kruse c-kruse deleted the ck/jobreceiver-command branch September 22, 2023 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants