mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
history: add comparison support to trace
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
7433d37183
commit
1089ff7341
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
17
docs/reference/buildx_history_trace.md
Normal file
17
docs/reference/buildx_history_trace.md
Normal file
@ -0,0 +1,17 @@
|
||||
# docker buildx history trace
|
||||
|
||||
<!---MARKER_GEN_START-->
|
||||
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 |
|
||||
|
||||
|
||||
<!---MARKER_GEN_END-->
|
||||
|
Loading…
x
Reference in New Issue
Block a user