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

Don't fail on err in exec #259

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions data_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ var suites = []FixtureSuite{
},
},
},
// exec false reports a span
// {
// {
// Name: "#258 Commands that exit with a non-zero exit code should report a span",
// Config: FixtureConfig{
// CliArgs: []string{"exec", "--endpoint", "{{endpoint}}", "--", "false"},
// },
// Expect: Results{
// SpanCount: 1,
// CliOutput: "",
// Diagnostics: otelcli.Diagnostics{
// ExecExitCode: 1,
// },
// 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.

// regression tests
{
{
Expand Down
6 changes: 5 additions & 1 deletion otelcli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

tracev1 "go.opentelemetry.io/proto/otlp/trace/v1"
"github.com/equinix-labs/otel-cli/otlpclient"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -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.

Code: tracev1.Status_STATUS_CODE_ERROR,
}
}
span.EndTimeUnixNano = uint64(time.Now().UnixNano())

Expand Down