go.temporal.io/server/tools/tdbg/app.go
156 LOC · 103 covered · 53 uncovered · 5 ranges · 101 concepts · 2 introducers · 42 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package tdbg
import (
"fmt"
"io"
"os"
"runtime/debug"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"go.temporal.io/server/common/headers"
"go.temporal.io/server/service/history/tasks"
)
type (
// Params which are customizable for the CLI application.
Params struct {
// ClientFactory creates Temporal service clients for tdbg to use.
ClientFactory ClientFactory
// TaskCategoryRegistry is used to determine which task categories are available for tdbg to use.
TaskCategoryRegistry tasks.TaskCategoryRegistry
// Writer is used to write output from tdbg. The default is os.Stdout.
Writer io.Writer
// ErrWriter is used to write errors from tdbg. The default is os.Stderr.
ErrWriter io.Writer
// TaskBlobEncoder is needed for custom task serialization. The default uses PredefinedTaskBlobDeserializer.
TaskBlobEncoder TaskBlobEncoder
}
// Option modifies the Params for tdbg.
Option func(params *Params)
)
// NewCliApp instantiates a new instance of the CLI application.
params := Params{
ClientFactory: NewClientFactory(),
TaskCategoryRegistry: tasks.NewDefaultTaskCategoryRegistry(),
Writer: os.Stdout,
ErrWriter: os.Stderr,
TaskBlobEncoder: NewProtoTaskBlobEncoder(NewPredefinedTaskBlobDeserializer()),
}
for _, opt := range opts {
opt(¶ms)
}
app := cli.NewApp()
app.Name = "tdbg"
app.Usage = "A command-line tool for Temporal server debugging"
app.Version = headers.ServerVersion
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: FlagAddress,
Value: "",
Usage: "host:port for Temporal frontend service",
EnvVars: []string{"TEMPORAL_CLI_ADDRESS"},
},
&cli.StringFlag{
Name: FlagNamespace,
Aliases: FlagNamespaceAlias,
Value: "default",
Usage: "Temporal workflow namespace",
EnvVars: []string{"TEMPORAL_CLI_NAMESPACE"},
},
&cli.IntFlag{
Name: FlagContextTimeout,
Aliases: FlagContextTimeoutAlias,
Value: defaultContextTimeoutInSeconds,
Usage: "Optional timeout for context of RPC call in seconds",
EnvVars: []string{"TEMPORAL_CONTEXT_TIMEOUT"},
},
&cli.BoolFlag{
Name: FlagYes,
Usage: "Automatically confirm all prompts",
},
&cli.StringFlag{
Name: FlagTLSCertPath,
Value: "",
Usage: "Path to x509 certificate",
EnvVars: []string{"TEMPORAL_CLI_TLS_CERT"},
},
&cli.StringFlag{
Name: FlagTLSKeyPath,
Value: "",
Usage: "Path to private key",
EnvVars: []string{"TEMPORAL_CLI_TLS_KEY"},
},
&cli.StringFlag{
Name: FlagTLSCaPath,
Value: "",
Usage: "Path to server CA certificate",
EnvVars: []string{"TEMPORAL_CLI_TLS_CA"},
},
&cli.BoolFlag{
Name: FlagTLSDisableHostVerification,
Usage: "Disable tls host name verification (tls must be enabled)",
EnvVars: []string{"TEMPORAL_CLI_TLS_DISABLE_HOST_VERIFICATION"},
},
&cli.StringFlag{
Name: FlagTLSServerName,
Value: "",
Usage: "Override for target server name",
EnvVars: []string{"TEMPORAL_CLI_TLS_SERVER_NAME"},
},
&cli.StringFlag{
Name: "color",
Usage: fmt.Sprintf("When to use color: %v, %v, %v.", "auto", "always", "never"),
Value: "auto",
},
}
prompterFactory := NewPrompterFactory()
app.Before = func(ctx *cli.Context) error {
colorFlag := ctx.String("color")
switch colorFlag {
case "always":
color.NoColor = false
case "never":
color.NoColor = true
// fatih/color will inspect the enviroment and terminal and set a reasonable default.
}
}
params.ClientFactory,
NewDLQServiceProvider(
params.ClientFactory,
params.TaskBlobEncoder,
params.TaskCategoryRegistry,
params.Writer,
prompterFactory,
),
params.TaskCategoryRegistry,
prompterFactory,
params.TaskBlobEncoder,
)
app.ExitErrHandler = handleError
app.Writer = params.Writer
app.ErrWriter = params.ErrWriter
return app
}
if err == nil {
return
}
_, _ = fmt.Fprintf(c.App.ErrWriter, "%s %+v\n", color.RedString("Error:"), err)
if os.Getenv(showErrorStackEnv) != `` {
_, _ = fmt.Fprintln(c.App.ErrWriter, color.MagentaString("Stack trace:"))
debug.PrintStack()
} else {
_, _ = fmt.Fprintf(c.App.ErrWriter, "('export %s=1' to see stack traces)\n", showErrorStackEnv)
}
cli.OsExiter(1)
}