Skip to content

Commit

Permalink
history: add comparison support to trace
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Feb 6, 2025
1 parent 7f3d6cd commit 78f22de
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions commands/history/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type traceOptions struct {
ref string
containerName string
addr string
compare string
}

func loadTrace(ctx context.Context, ref string, nodes []builder.Node) (string, []byte, error) {
Expand Down Expand Up @@ -175,39 +176,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() {
Expand Down Expand Up @@ -246,6 +256,7 @@ 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
}

0 comments on commit 78f22de

Please sign in to comment.