Skip to content

Conversation

@JoshStern
Copy link
Contributor

@JoshStern JoshStern commented Jun 14, 2022

Writes command output directly to std IO and no longer returns a buffer.

https://www.loom.com/share/fc29e6dce02e43059e495169468caf0e

@JoshStern JoshStern requested a review from a team as a code owner June 14, 2022 12:27
@JoshStern JoshStern force-pushed the jpas/cronjob-io-passthrough branch from 7a104a0 to a1b859e Compare June 14, 2022 12:31
@JoshStern JoshStern requested a review from lingrino June 14, 2022 12:41
@ejeun
Copy link

ejeun commented Jun 14, 2022

👀

just curious what you'll expect to happen with cron logs when this goes to prod. got any prediction?

lock/run.go Outdated
Comment on lines 28 to 38
cmd := exec.CommandContext(ctx, fields[0], fields[1:]...) //nolint:gosec

// Write to std outputs + combined buffer
var outbuf bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &outbuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &outbuf)

cmderr := cmd.Run()
cmdout := outbuf.Bytes()

return strings.TrimSpace(string(cmdout)), cmderr
Copy link
Contributor

Choose a reason for hiding this comment

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

Just confirming I think this means that we're going to write output directly to stdout and return it in this function where it will be logged again by the lock-exec CLI?

I think that might be fine... What do you think about creating a new function like RunDirectOutput (not sure of a good name) that has your change here and then does not return the output. So instead of returning the output it just sends it directly to stdout and then returns only the command exit code.

Copy link
Contributor Author

@JoshStern JoshStern Jun 14, 2022

Choose a reason for hiding this comment

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

I didn't want to change this function's interface so I set it up to do both.

This line logs it and adds the output as metadata to the log sent to dd. I was worried someone might have alerts or other things connected to that field.

I'm down to pick one or the other and drop that metadata if we think it's redundant though. Which would you prefer?

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 could also update that log to avoid the double-print

@JoshStern
Copy link
Contributor Author

@ejeun this should get us to a place where calling kubectl logs -f <job-pod> isn't empty if a job is hanging.

Haven't confirmed if these logs will make it to DD correctly but I was going to check it on staging/prod. I didn't see any special connections set up in lock-exec to connect to DD so I think it's at the stdout level, @lingrino can probably confirm.

@JoshStern JoshStern requested a review from lingrino June 15, 2022 14:20
@JoshStern JoshStern force-pushed the jpas/cronjob-io-passthrough branch from a1b859e to 86b7a57 Compare June 15, 2022 22:16
Creates multiwriter with a single buffer (combined output) and
std IO file descriptors
@JoshStern JoshStern force-pushed the jpas/cronjob-io-passthrough branch from 86b7a57 to 2abd386 Compare June 15, 2022 22:22
Copy link
Contributor

@lingrino lingrino left a comment

Choose a reason for hiding this comment

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

Yay! Thank you!

@lingrino
Copy link
Contributor

I will merge this and tag a new version

@lingrino lingrino merged commit a695f30 into main Jun 15, 2022
@lingrino lingrino deleted the jpas/cronjob-io-passthrough branch June 15, 2022 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants