Skip to content

Conversation

parsonsmatt
Copy link
Contributor

@parsonsmatt parsonsmatt commented Aug 31, 2023

Fixes #258

I'm having a hard time writing a test for this. I have verified that this change makes the code do what I want - spans show up in Honeycomb and otel-cli exec false has a non-0 exit code.

λ otel-cli exec --name "false" false
λ echo $?
1

However, the test does not appear to work? Locally it tells me that no spans were recorded.

Copy link
Collaborator

@tobert tobert left a comment

Choose a reason for hiding this comment

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

If you have time to work on this, I've provided some notes that should help you make progress. If you don't have time, LMK and I'll finish it up.

otelcli/exec.go Outdated
@@ -94,7 +95,10 @@ func doExec(cmd *cobra.Command, args []string) {
}

if err := child.Run(); err != nil {
config.SoftFail("command failed: %s", err)
span.Status = & tracev1.Status {
Message: fmt.Sprintln("exec command failed: ", err),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd just do fmt.Sprintf here, message doesn't need the newline.

data_for_test.go Outdated
// Config: otelcli.DefaultConfig().WithEndpoint("grpc://{{endpoint}}"),
// },
// },
// },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm this test looks right.

Try adding "--fail", "--verbose" to the CliArgs. It looks like config.SoftFail is being called when child.Run() returns an err.

If the command starts but does not complete successfully, the error is of type *ExitError. Other error types may be returned for other situations.

so the if err :- child.Run(); err != nil needs to be expanded to check for ExitError and not SoftFail on that so you can send the error upstream in the span status.

@parsonsmatt
Copy link
Contributor Author

Unfortunately, I don't have further cycles to put towards this. Thanks for the review and the time/effort you've spent on this tool!

@tobert
Copy link
Collaborator

tobert commented Sep 15, 2023

Thanks for the PR! Work is busy right now so it might take me a couple weeks but I'll get this in and release.

Amy Tobey added 2 commits September 21, 2023 11:30
Added ExitCode to the results struct so it's easier to test against. I'm
trying to remove Diagnostics eventually so it should move anyways.

Reworked some failure catching to be more robust for exec.

Tests pass :)
@tobert tobert marked this pull request as ready for review September 21, 2023 16:06
@tobert tobert self-requested a review September 21, 2023 21:32
Copy link
Collaborator

@tobert tobert left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started!

It turned out the test code that examines exit status needed some rework to test this, so I added that to your PR.

@tobert tobert merged commit b389235 into equinix-labs:main Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

otel-cli exec does not report a span if the command failed
2 participants