From 1279f72c64350edd0b4534601492740325715d99 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 5 Feb 2025 22:57:49 -0800 Subject: [PATCH] history: add comparison support to trace Signed-off-by: Tonis Tiigi --- commands/history/trace.go | 39 ++++++++++++++++---------- docs/reference/buildx_history.md | 15 +++++----- docs/reference/buildx_history_trace.md | 17 +++++++++++ 3 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 docs/reference/buildx_history_trace.md diff --git a/commands/history/trace.go b/commands/history/trace.go index b96ab68f9d1d..f47aa8adc348 100644 --- a/commands/history/trace.go +++ b/commands/history/trace.go @@ -30,10 +30,10 @@ import ( ) type traceOptions struct { - builder string - ref string - containerName string - addr string + builder string + ref string + addr string + compare string } func loadTrace(ctx context.Context, ref string, nodes []builder.Node) (string, []byte, error) { @@ -175,39 +175,48 @@ func runTrace(ctx context.Context, dockerCli command.Cli, opts traceOptions) err } } - traceid, data, err := loadTrace(ctx, opts.ref, nodes) + traceID, data, err := loadTrace(ctx, opts.ref, nodes) if err != nil { return err } + srv := jaegerui.NewServer(jaegerui.Config{}) + if err := srv.AddTrace(traceID, bytes.NewReader(data)); err != nil { + return err + } + url := "/trace/" + traceID + + if opts.compare != "" { + traceIDcomp, data, err := loadTrace(ctx, opts.compare, nodes) + if err != nil { + return errors.Wrapf(err, "failed to load trace for %s", opts.compare) + } + if err := srv.AddTrace(traceIDcomp, bytes.NewReader(data)); err != nil { + return err + } + url = "/trace/" + traceIDcomp + "..." + traceID + } var term bool if _, err := console.ConsoleFromFile(os.Stdout); err == nil { term = true } - if !term { + if !term && opts.compare == "" { fmt.Fprintln(dockerCli.Out(), string(data)) return nil } - srv := jaegerui.NewServer(jaegerui.Config{}) - - if err := srv.AddTrace(traceid, bytes.NewReader(data)); err != nil { - return err - } - ln, err := net.Listen("tcp", opts.addr) if err != nil { return err } - url := "http://" + ln.Addr().String() + "/trace/" + traceid - go func() { time.Sleep(100 * time.Millisecond) browser.OpenURL(url) }() + url = "http://" + ln.Addr().String() + url fmt.Fprintf(dockerCli.Err(), "Trace available at %s\n", url) go func() { @@ -244,8 +253,8 @@ func traceCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command { } flags := cmd.Flags() - flags.StringVar(&options.containerName, "container", "", "Container name") flags.StringVar(&options.addr, "addr", "127.0.0.1:0", "Address to bind the UI server") + flags.StringVar(&options.compare, "compare", "", "Compare with another build reference") return cmd } diff --git a/docs/reference/buildx_history.md b/docs/reference/buildx_history.md index 19f7befe09ad..0935efb7f59a 100644 --- a/docs/reference/buildx_history.md +++ b/docs/reference/buildx_history.md @@ -5,13 +5,14 @@ Commands to work on build records ### Subcommands -| Name | Description | -|:---------------------------------------|:-------------------------------| -| [`inspect`](buildx_history_inspect.md) | Inspect a build | -| [`logs`](buildx_history_logs.md) | Print the logs of a build | -| [`ls`](buildx_history_ls.md) | List build records | -| [`open`](buildx_history_open.md) | Open a build in Docker Desktop | -| [`rm`](buildx_history_rm.md) | Remove build records | +| Name | Description | +|:---------------------------------------|:-----------------------------------------------| +| [`inspect`](buildx_history_inspect.md) | Inspect a build | +| [`logs`](buildx_history_logs.md) | Print the logs of a build | +| [`ls`](buildx_history_ls.md) | List build records | +| [`open`](buildx_history_open.md) | Open a build in Docker Desktop | +| [`rm`](buildx_history_rm.md) | Remove build records | +| [`trace`](buildx_history_trace.md) | Show the OpenTelemetry trace of a build record | ### Options diff --git a/docs/reference/buildx_history_trace.md b/docs/reference/buildx_history_trace.md new file mode 100644 index 000000000000..54362b1ac853 --- /dev/null +++ b/docs/reference/buildx_history_trace.md @@ -0,0 +1,17 @@ +# docker buildx history trace + + +Show the OpenTelemetry trace of a build record + +### Options + +| Name | Type | Default | Description | +|:----------------|:---------|:--------------|:-----------------------------------------| +| `--addr` | `string` | `127.0.0.1:0` | Address to bind the UI server | +| `--builder` | `string` | | Override the configured builder instance | +| `--compare` | `string` | | Compare with another build reference | +| `-D`, `--debug` | `bool` | | Enable debug logging | + + + +