Skip to content

Commit

Permalink
fix(executor): Capture emissary main-logs. Fixes argoproj#6145
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <[email protected]>
  • Loading branch information
alexec committed Jun 14, 2021
1 parent 8059932 commit b8a5c2e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/argoexec/commands/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewEmissaryCommand() *cobra.Command {
command.Stderr = os.Stderr

// this may not be that important an optimisation, except for very long logs we don't want to capture
if includeScriptOutput {
if includeScriptOutput || template.SaveLogsAsArtifact() {
logger.Info("capturing logs")
stdout, err := os.Create(varRunArgo + "/ctr/" + containerName + "/stdout")
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ func (s *ArtifactsSuite) TestOutputResult() {
})
}

func (s *ArtifactsSuite) TestMainLog() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded).
Then().
ExpectArtifact("-", "main-logs", func(t *testing.T, data []byte) {
println(string(data))
assert.NotEmpty(t, data)
})
}

func TestArtifactsSuite(t *testing.T) {
suite.Run(t, new(ArtifactsSuite))
}
30 changes: 30 additions & 0 deletions test/e2e/fixtures/then.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package fixtures
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -173,6 +175,34 @@ func (t *Then) ExpectAuditEvents(filter func(event apiv1.Event) bool, num int, b
return t
}

func (t *Then) ExpectArtifact(nodeName, artifactName string, f func(t *testing.T, data []byte)) {
t.t.Helper()
nodeId := nodeIdForName(nodeName, t.wf)
url := "http://localhost:2746/artifacts/" + Namespace + "/" + t.wf.Name + "/" + nodeId + "/" + artifactName
println(url)
r, err := http.Get(url)
if err != nil {
t.t.Fatal(err)
}
defer r.Body.Close()
data, err := ioutil.ReadAll(r.Body)
if err != nil {
t.t.Fatal(err)
}
if r.StatusCode != 200 {
t.t.Fatal(fmt.Errorf("HTTP request not OK: %s: %q", r.Status, data))
}
f(t.t, data)
}

func nodeIdForName(nodeName string, wf *wfv1.Workflow) string {
if nodeName == "-" {
return wf.NodeID(wf.Name)
} else {
return wf.NodeID(nodeName)
}
}

func (t *Then) RunCli(args []string, block func(t *testing.T, output string, err error)) *Then {
t.t.Helper()
output, err := Exec("../../dist/argo", append([]string{"-n", Namespace}, args...)...)
Expand Down

0 comments on commit b8a5c2e

Please sign in to comment.