Skip to content

Commit d8a5cf8

Browse files
committed
history: add comparison support to trace
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent 7f3d6cd commit d8a5cf8

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

commands/history/trace.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type traceOptions struct {
3434
ref string
3535
containerName string
3636
addr string
37+
compare string
3738
}
3839

3940
func loadTrace(ctx context.Context, ref string, nodes []builder.Node) (string, []byte, error) {
@@ -175,39 +176,48 @@ func runTrace(ctx context.Context, dockerCli command.Cli, opts traceOptions) err
175176
}
176177
}
177178

178-
traceid, data, err := loadTrace(ctx, opts.ref, nodes)
179+
traceID, data, err := loadTrace(ctx, opts.ref, nodes)
179180
if err != nil {
180181
return err
181182
}
183+
srv := jaegerui.NewServer(jaegerui.Config{})
184+
if err := srv.AddTrace(traceID, bytes.NewReader(data)); err != nil {
185+
return err
186+
}
187+
url := "/trace/" + traceID
188+
189+
if opts.compare != "" {
190+
traceIDcomp, data, err := loadTrace(ctx, opts.compare, nodes)
191+
if err != nil {
192+
return errors.Wrapf(err, "failed to load trace for %s", opts.compare)
193+
}
194+
if err := srv.AddTrace(traceIDcomp, bytes.NewReader(data)); err != nil {
195+
return err
196+
}
197+
url = "/trace/" + traceIDcomp + "..." + traceID
198+
}
182199

183200
var term bool
184201
if _, err := console.ConsoleFromFile(os.Stdout); err == nil {
185202
term = true
186203
}
187204

188-
if !term {
205+
if !term && opts.compare == "" {
189206
fmt.Fprintln(dockerCli.Out(), string(data))
190207
return nil
191208
}
192209

193-
srv := jaegerui.NewServer(jaegerui.Config{})
194-
195-
if err := srv.AddTrace(traceid, bytes.NewReader(data)); err != nil {
196-
return err
197-
}
198-
199210
ln, err := net.Listen("tcp", opts.addr)
200211
if err != nil {
201212
return err
202213
}
203214

204-
url := "http://" + ln.Addr().String() + "/trace/" + traceid
205-
206215
go func() {
207216
time.Sleep(100 * time.Millisecond)
208217
browser.OpenURL(url)
209218
}()
210219

220+
url = "http://" + ln.Addr().String() + url
211221
fmt.Fprintf(dockerCli.Err(), "Trace available at %s\n", url)
212222

213223
go func() {
@@ -246,6 +256,7 @@ func traceCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
246256
flags := cmd.Flags()
247257
flags.StringVar(&options.containerName, "container", "", "Container name")
248258
flags.StringVar(&options.addr, "addr", "127.0.0.1:0", "Address to bind the UI server")
259+
flags.StringVar(&options.compare, "compare", "", "Compare with another build reference")
249260

250261
return cmd
251262
}

docs/reference/buildx_history.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ Commands to work on build records
55

66
### Subcommands
77

8-
| Name | Description |
9-
|:---------------------------------------|:-------------------------------|
10-
| [`inspect`](buildx_history_inspect.md) | Inspect a build |
11-
| [`logs`](buildx_history_logs.md) | Print the logs of a build |
12-
| [`ls`](buildx_history_ls.md) | List build records |
13-
| [`open`](buildx_history_open.md) | Open a build in Docker Desktop |
14-
| [`rm`](buildx_history_rm.md) | Remove build records |
8+
| Name | Description |
9+
|:---------------------------------------|:-----------------------------------------------|
10+
| [`inspect`](buildx_history_inspect.md) | Inspect a build |
11+
| [`logs`](buildx_history_logs.md) | Print the logs of a build |
12+
| [`ls`](buildx_history_ls.md) | List build records |
13+
| [`open`](buildx_history_open.md) | Open a build in Docker Desktop |
14+
| [`rm`](buildx_history_rm.md) | Remove build records |
15+
| [`trace`](buildx_history_trace.md) | Show the OpenTelemetry trace of a build record |
1516

1617

1718
### Options
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# docker buildx history trace
2+
3+
<!---MARKER_GEN_START-->
4+
Show the OpenTelemetry trace of a build record
5+
6+
### Options
7+
8+
| Name | Type | Default | Description |
9+
|:----------------|:---------|:--------------|:-----------------------------------------|
10+
| `--addr` | `string` | `127.0.0.1:0` | Address to bind the UI server |
11+
| `--builder` | `string` | | Override the configured builder instance |
12+
| `--compare` | `string` | | Compare with another build reference |
13+
| `--container` | `string` | | Container name |
14+
| `-D`, `--debug` | `bool` | | Enable debug logging |
15+
16+
17+
<!---MARKER_GEN_END-->
18+

0 commit comments

Comments
 (0)