Skip to content

Commit 8fc0b3f

Browse files
authored
Revisit elastic-package test command output (#2756)
This PR reviews the output shown by the elastic-package test command. It was mainly focused on test system in Pull Requests builds as well as Serverless builds.
1 parent c67f9ef commit 8fc0b3f

File tree

12 files changed

+47
-41
lines changed

12 files changed

+47
-41
lines changed

internal/builder/external_fields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func resolveExternalFields(packageRoot, destinationDir string) error {
7878
return err
7979
}
8080
} else {
81-
logger.Debugf("%s: source file hasn't been changed", rel)
81+
logger.Tracef("%s: source file hasn't been changed", rel)
8282
}
8383
}
8484

internal/compose/compose.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func NewProject(name string, paths ...string) (*Project, error) {
204204
if ver.Major() < 2 {
205205
return nil, fmt.Errorf("required Docker Compose v2, found %s", ver.String())
206206
}
207-
logger.Debugf("Determined Docker Compose version: %v", ver)
207+
logger.Tracef("Determined Docker Compose version: %v", ver)
208208

209209
v, ok = os.LookupEnv(DisableVerboseOutputComposeEnv)
210210
if ok && strings.ToLower(v) != "false" {
@@ -348,7 +348,7 @@ func (p *Project) Logs(ctx context.Context, opts CommandOptions) ([]byte, error)
348348
func (p *Project) WaitForHealthy(ctx context.Context, opts CommandOptions) error {
349349
// Read container IDs
350350
args := p.baseArgs()
351-
args = append(args, "ps", "-a", "-q")
351+
args = append(args, "ps", "-a", "--format", "{{.ID}}")
352352

353353
var b bytes.Buffer
354354
if err := p.runDockerComposeCmd(ctx, dockerComposeOptions{args: args, env: opts.Env, stdout: &b}); err != nil {
@@ -359,34 +359,35 @@ func (p *Project) WaitForHealthy(ctx context.Context, opts CommandOptions) error
359359
defer stop()
360360

361361
containerIDs := strings.Fields(b.String())
362+
logger.Debugf("Wait for healthy containers: %s", strings.Join(containerIDs, ","))
362363
for {
363364
// NOTE: healthy must be reinitialized at each iteration
364365
healthy := true
365366

366-
logger.Debugf("Wait for healthy containers: %s", strings.Join(containerIDs, ","))
367367
descriptions, err := docker.InspectContainers(containerIDs...)
368368
if err != nil {
369369
return err
370370
}
371371

372372
for _, d := range descriptions {
373+
dockerID := fmt.Sprintf("%.*s", 12, d.ID) // Ensure it is always 12 characters long
373374
switch {
374375
// No healthcheck defined for service
375376
case d.State.Status == "running" && d.State.Health == nil:
376-
logger.Debugf("Container %s (%s) status: %s (no health status)", d.Config.Labels.ComposeService, d.ID, d.State.Status)
377+
logger.Debugf("Container %s (%s) status: %s (no health status)", d.Config.Labels.ComposeService, dockerID, d.State.Status)
377378
// Service is up and running and it's healthy
378379
case d.State.Status == "running" && d.State.Health.Status == "healthy":
379-
logger.Debugf("Container %s (%s) status: %s (health: %s)", d.Config.Labels.ComposeService, d.ID, d.State.Status, d.State.Health.Status)
380+
logger.Debugf("Container %s (%s) status: %s (health: %s)", d.Config.Labels.ComposeService, dockerID, d.State.Status, d.State.Health.Status)
380381
// Container started and finished with exit code 0
381382
case d.State.Status == "exited" && d.State.ExitCode == 0:
382-
logger.Debugf("Container %s (%s) status: %s (exit code: %d)", d.Config.Labels.ComposeService, d.ID, d.State.Status, d.State.ExitCode)
383+
logger.Debugf("Container %s (%s) status: %s (exit code: %d)", d.Config.Labels.ComposeService, dockerID, d.State.Status, d.State.ExitCode)
383384
// Container exited with code > 0
384385
case d.State.Status == "exited" && d.State.ExitCode > 0:
385-
logger.Debugf("Container %s (%s) status: %s (exit code: %d)", d.Config.Labels.ComposeService, d.ID, d.State.Status, d.State.ExitCode)
386-
return fmt.Errorf("container (ID: %s) exited with code %d", d.ID, d.State.ExitCode)
386+
logger.Debugf("Container %s (%s) status: %s (exit code: %d)", d.Config.Labels.ComposeService, dockerID, d.State.Status, d.State.ExitCode)
387+
return fmt.Errorf("container (ID: %s) exited with code %d", dockerID, d.State.ExitCode)
387388
// Any different status is considered unhealthy
388389
default:
389-
logger.Debugf("Container %s (%s) status: unhealthy", d.Config.Labels.ComposeService, d.ID)
390+
logger.Debugf("Container %s (%s) status: unhealthy", d.Config.Labels.ComposeService, dockerID)
390391
healthy = false
391392
}
392393
}

internal/compose/compose_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (p *Project) runDockerComposeCmd(ctx context.Context, opts dockerComposeOpt
4545
return fmt.Errorf("failed to start command with pseudo-tty: %w", err)
4646
}
4747
defer ptty.Close()
48-
logger.Debugf("running command: %s", cmd)
48+
logger.Tracef("running command: %s", cmd)
4949

5050
io.Copy(stderr, ptty)
5151

internal/docker/docker.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func Pull(image string) error {
6969
cmd.Stderr = os.Stderr
7070
}
7171

72-
logger.Debugf("run command: %s", cmd)
72+
logger.Tracef("run command: %s", cmd)
7373
err := cmd.Run()
7474
if err != nil {
7575
return fmt.Errorf("running docker command failed: %w", err)
@@ -83,7 +83,7 @@ func ContainerID(containerName string) (string, error) {
8383
errOutput := new(bytes.Buffer)
8484
cmd.Stderr = errOutput
8585

86-
logger.Debugf("output command: %s", cmd)
86+
logger.Tracef("output command: %s", cmd)
8787
output, err := cmd.Output()
8888
if err != nil {
8989
return "", fmt.Errorf("could not find \"%s\" container (stderr=%q): %w", containerName, errOutput.String(), err)
@@ -102,7 +102,7 @@ func ContainerIDsWithLabel(key, value string) ([]string, error) {
102102
errOutput := new(bytes.Buffer)
103103
cmd.Stderr = errOutput
104104

105-
logger.Debugf("output command: %s", cmd)
105+
logger.Tracef("output command: %s", cmd)
106106
output, err := cmd.Output()
107107
if err != nil {
108108
return []string{}, fmt.Errorf("error getting containers with label \"%s\" (stderr=%q): %w", label, errOutput.String(), err)
@@ -117,7 +117,7 @@ func InspectNetwork(network string) ([]NetworkDescription, error) {
117117
errOutput := new(bytes.Buffer)
118118
cmd.Stderr = errOutput
119119

120-
logger.Debugf("output command: %s", cmd)
120+
logger.Tracef("output command: %s", cmd)
121121
output, err := cmd.Output()
122122
if err != nil {
123123
return nil, fmt.Errorf("could not inspect the network (stderr=%q): %w", errOutput.String(), err)
@@ -148,7 +148,7 @@ func ConnectToNetworkWithAlias(containerID, network string, aliases []string) er
148148
errOutput := new(bytes.Buffer)
149149
cmd.Stderr = errOutput
150150

151-
logger.Debugf("run command: %s", cmd)
151+
logger.Tracef("run command: %s", cmd)
152152
if err := cmd.Run(); err != nil {
153153
return fmt.Errorf("could not attach container to the stack network (stderr=%q): %w", errOutput.String(), err)
154154
}
@@ -164,7 +164,7 @@ func InspectContainers(containerIDs ...string) ([]ContainerDescription, error) {
164164
errOutput := new(bytes.Buffer)
165165
cmd.Stderr = errOutput
166166

167-
logger.Debugf("output command: %s", cmd)
167+
logger.Tracef("output command: %s", cmd)
168168
output, err := cmd.Output()
169169
if err != nil {
170170
return nil, fmt.Errorf("could not inspect containers (stderr=%q): %w", errOutput.String(), err)
@@ -184,7 +184,7 @@ func Copy(containerName, containerPath, localPath string) error {
184184
errOutput := new(bytes.Buffer)
185185
cmd.Stderr = errOutput
186186

187-
logger.Debugf("run command: %s", cmd)
187+
logger.Tracef("run command: %s", cmd)
188188
if err := cmd.Run(); err != nil {
189189
return fmt.Errorf("could not copy files from the container (stderr=%q): %w", errOutput.String(), err)
190190
}

internal/fleetserver/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (c *Client) httpRequest(ctx context.Context, method, resourcePath string, r
113113
u := base.JoinPath(rel.EscapedPath())
114114
u.RawQuery = rel.RawQuery
115115

116-
logger.Debugf("%s %s", method, u)
116+
logger.Tracef("%s %s", method, u)
117117

118118
req, err := http.NewRequestWithContext(ctx, method, u.String(), reqBody)
119119
if err != nil {

internal/fleetserver/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (c *Client) Status(ctx context.Context) (*Status, error) {
2929
if err != nil {
3030
return nil, fmt.Errorf("could not build URL: %w", err)
3131
}
32-
logger.Debugf("GET %s", statusURL)
32+
logger.Tracef("GET %s", statusURL)
3333
req, err := c.httpRequest(ctx, "GET", statusURL, nil)
3434
if err != nil {
3535
return nil, err

internal/kibana/agents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func (c *Client) waitUntilPolicyAssigned(ctx context.Context, a Agent, p Policy)
139139
ticker := time.NewTicker(waitForPolicyAssignedRetryPeriod)
140140
defer ticker.Stop()
141141

142+
logger.Debugf("Wait until the policy (ID: %s, revision: %d) is assigned to the agent (ID: %s)...", p.ID, p.Revision, a.ID)
142143
for {
143144
agent, err := c.getAgent(ctx, a.ID)
144145
if err != nil {
@@ -152,7 +153,6 @@ func (c *Client) waitUntilPolicyAssigned(ctx context.Context, a Agent, p Policy)
152153
break
153154
}
154155

155-
logger.Debugf("Wait until the policy (ID: %s, revision: %d) is assigned to the agent (ID: %s)...", p.ID, p.Revision, a.ID)
156156
select {
157157
case <-ctx.Done():
158158
if errors.Is(ctx.Err(), context.DeadlineExceeded) {

internal/kibana/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (c *Client) newRequest(ctx context.Context, method, resourcePath string, re
189189
u := base.JoinPath(rel.EscapedPath())
190190
u.RawQuery = rel.RawQuery
191191

192-
logger.Debugf("%s %s", method, u)
192+
logger.Tracef("%s %s", method, u)
193193

194194
req, err := http.NewRequestWithContext(ctx, method, u.String(), reqBody)
195195
if err != nil {

internal/serverless/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func NewClient(opts ...ClientOption) (*Client, error) {
5757
if host != "" {
5858
c.host = host
5959
}
60-
logger.Debugf("Using Elastic Cloud URL: %s", c.host)
6160
return c, nil
6261
}
6362

@@ -110,7 +109,7 @@ func (c *Client) newRequest(ctx context.Context, method, resourcePath string, re
110109
u := base.JoinPath(rel.EscapedPath())
111110
u.RawQuery = rel.RawQuery
112111

113-
logger.Debugf("%s %s", method, u)
112+
logger.Tracef("%s %s", method, u)
114113

115114
req, err := http.NewRequestWithContext(ctx, method, u.String(), reqBody)
116115
if err != nil {
@@ -191,11 +190,11 @@ func (c *Client) EnsureProjectInitialized(ctx context.Context, project *Project)
191190
}
192191

193192
if status != "initialized" {
194-
logger.Debugf("project not initialized, status: %s", status)
193+
logger.Debugf("project %s not initialized (status: %s)", project.ID, status)
195194
timer.Reset(time.Second * 5)
196195
continue
197196
}
198-
197+
logger.Debugf("project %s initialized", project.ID)
199198
return nil
200199
}
201200
}

internal/stack/dump.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ type DumpResult struct {
4646

4747
// Dump function exports stack data and dumps them as local artifacts, which can be used for debug purposes.
4848
func Dump(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
49-
logger.Debugf("Dump Elastic stack data")
49+
targetPathLogMessage := ""
50+
if options.Output != "" {
51+
targetPathLogMessage = fmt.Sprintf(" (location: %s)", options.Output)
52+
}
53+
logger.Debugf("Dump Elastic stack data%s", targetPathLogMessage)
5054

5155
results, err := dumpStackLogs(ctx, options)
5256
if err != nil {
@@ -56,12 +60,6 @@ func Dump(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
5660
}
5761

5862
func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
59-
logger.Debugf("Dump stack logs (location: %s)", options.Output)
60-
err := os.RemoveAll(options.Output)
61-
if err != nil {
62-
return nil, fmt.Errorf("can't remove output location: %w", err)
63-
}
64-
6563
localServices := &localServicesManager{
6664
profile: options.Profile,
6765
}
@@ -78,6 +76,11 @@ func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, erro
7876

7977
var logsPath string
8078
if options.Output != "" {
79+
err := os.RemoveAll(options.Output)
80+
if err != nil {
81+
return nil, fmt.Errorf("can't remove output location: %w", err)
82+
}
83+
8184
logsPath = filepath.Join(options.Output, "logs")
8285
err = os.MkdirAll(logsPath, 0755)
8386
if err != nil {
@@ -91,7 +94,6 @@ func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, erro
9194
if len(options.Services) > 0 && !slices.Contains(options.Services, serviceName) {
9295
continue
9396
}
94-
9597
logger.Debugf("Dump stack logs for %s", serviceName)
9698

9799
content, err := dockerComposeLogsSince(ctx, serviceName, options.Profile, options.Since)

0 commit comments

Comments
 (0)