diff --git a/agent/workers/poller.go b/agent/workers/poller.go index e215534fb5..769825630b 100644 --- a/agent/workers/poller.go +++ b/agent/workers/poller.go @@ -50,7 +50,6 @@ func NewPollerWorker(client *client.Client, opts ...PollerOption) *PollerWorker } func (w *PollerWorker) Poll(ctx context.Context, request *proto.PollingRequest) error { - fmt.Println("Poll handled by agent") datastoreConfig, err := convertProtoToDataStore(request.Datastore) if err != nil { return err diff --git a/agent/workers/trigger.go b/agent/workers/trigger.go index 66eefb2717..9ecac8af94 100644 --- a/agent/workers/trigger.go +++ b/agent/workers/trigger.go @@ -51,7 +51,6 @@ func NewTriggerWorker(client *client.Client, opts ...TriggerOption) *TriggerWork } func (w *TriggerWorker) Trigger(ctx context.Context, triggerRequest *proto.TriggerRequest) error { - fmt.Println("Trigger handled by agent") triggerConfig := convertProtoToTrigger(triggerRequest.Trigger) triggerer, err := w.registry.Get(triggerConfig.Type) if err != nil { diff --git a/cli/cmd/start_cmd.go b/cli/cmd/start_cmd.go index 40d8277ff7..f83e7ccb3e 100644 --- a/cli/cmd/start_cmd.go +++ b/cli/cmd/start_cmd.go @@ -19,7 +19,7 @@ var startCmd = &cobra.Command{ Use: "start", Short: "Start Tracetest", Long: "Start using Tracetest", - PreRun: setupCommand(SkipVersionMismatchCheck()), + PreRun: setupCommand(SkipConfigValidation()), Run: WithResultHandler((func(_ *cobra.Command, _ []string) (string, error) { ctx := context.Background() diff --git a/cli/config/configurator.go b/cli/config/configurator.go index 2c327df489..ea9b8ff8b1 100644 --- a/cli/config/configurator.go +++ b/cli/config/configurator.go @@ -113,6 +113,12 @@ func (c Configurator) Start(ctx context.Context, prev Config, flags ConfigFlags) return nil } + confirmed := c.ui.Enter("Lets get to it! Press enter to launch a browser and authenticate:") + if !confirmed { + c.ui.Finish() + return nil + } + oauthServer := oauth.NewOAuthServer(fmt.Sprintf("%s%s", cfg.URL(), cfg.Path()), cfg.UIEndpoint) err = oauthServer.WithOnSuccess(c.onOAuthSuccess(ctx, cfg)). WithOnFailure(c.onOAuthFailure). diff --git a/cli/config/selector.go b/cli/config/selector.go index c6bc771adf..efedfaae22 100644 --- a/cli/config/selector.go +++ b/cli/config/selector.go @@ -26,7 +26,8 @@ func (c Configurator) organizationSelector(ctx context.Context, cfg Config) (str } if len(elements) == 1 { - c.ui.Println(fmt.Sprintf("Defaulting to only available Organization: %s", elements[0].Name)) + c.ui.Println(fmt.Sprintf(` +Defaulting to only available Organization: %s`, elements[0].Name)) return elements[0].ID, nil } @@ -43,7 +44,8 @@ func (c Configurator) organizationSelector(ctx context.Context, cfg Config) (str } } - option := c.ui.Select("What Organization do you want to use?", options, 0) + option := c.ui.Select(` +What Organization do you want to use?`, options, 0) option.Fn(c.ui) return orgID, nil diff --git a/cli/pkg/starter/starter.go b/cli/pkg/starter/starter.go index 9745ae89eb..dd8bef56d6 100644 --- a/cli/pkg/starter/starter.go +++ b/cli/pkg/starter/starter.go @@ -27,6 +27,8 @@ func NewStarter(configurator config.Configurator, resources *resourcemanager.Reg func (s *Starter) Run(ctx context.Context, cfg config.Config, flags config.ConfigFlags) error { s.ui.Banner(config.Version) + s.ui.Println(`Tracetest start launches a lightweight agent. It enables you to run tests and collect traces with Tracetest. +Once started, Tracetest Agent exposes OTLP ports 4317 and 4318 to ingest traces via gRCP and HTTP.`) return s.configurator.WithOnFinish(s.onStartAgent).Start(ctx, cfg, flags) } @@ -46,10 +48,6 @@ func (s *Starter) onStartAgent(ctx context.Context, cfg config.Config) { s.ui.Error(err.Error()) } - s.ui.Info(fmt.Sprintf(` -Connecting Agent with name %s to Organization %s and Environment %s -`, "local", cfg.OrganizationID, env.Name)) - err = s.StartAgent(ctx, cfg.AgentEndpoint, env.AgentApiKey, cfg.UIEndpoint) if err != nil { s.ui.Error(err.Error()) @@ -108,7 +106,8 @@ func (s *Starter) StartAgent(ctx context.Context, endpoint, agentApiKey, uiEndpo cfg.APIKey = agentApiKey } - s.ui.Info(fmt.Sprintf("Starting Agent with name %s...", cfg.Name)) + s.ui.Println(fmt.Sprintf(` +Starting Agent with name %s...`, cfg.Name)) session, err := initialization.Start(ctx, cfg) if err != nil { return err @@ -120,21 +119,23 @@ func (s *Starter) StartAgent(ctx context.Context, endpoint, agentApiKey, uiEndpo } isOpen := true - message := fmt.Sprintf("Agent is started! Leave the terminal open so tests can be run and traces gathered from this environment (%s). You can:", claims["environment_id"]) - for isOpen { - options := []ui.Option{{ - Text: "Open Tracetest in a browser to this environment", - Fn: func(_ ui.UI) { - s.ui.OpenBrowser(fmt.Sprintf("%sorganizations/%s/environments/%s/dashboard", uiEndpoint, claims["organization_id"], claims["environment_id"])) - }, - }, { - Text: "Stop this agent", - Fn: func(_ ui.UI) { - isOpen = false - session.Close() - }, - }} + message := `Agent is started! Leave the terminal open so tests can be run and traces gathered from this environment. +You can` + options := []ui.Option{{ + Text: "Open Tracetest in a browser to this environment", + Fn: func(_ ui.UI) { + s.ui.OpenBrowser(fmt.Sprintf("%sorganizations/%s/environments/%s/dashboard", uiEndpoint, claims["organization_id"], claims["environment_id"])) + }, + }, { + Text: "Stop this agent", + Fn: func(_ ui.UI) { + isOpen = false + session.Close() + s.ui.Finish() + }, + }} + for isOpen { selected := s.ui.Select(message, options, 0) selected.Fn(s.ui) } diff --git a/cli/ui/ui.go b/cli/ui/ui.go index c42b71cfbe..d1febec201 100644 --- a/cli/ui/ui.go +++ b/cli/ui/ui.go @@ -32,6 +32,7 @@ type UI interface { Red(string) string Confirm(prompt string, defaultValue bool) bool + Enter(msg string) bool Select(prompt string, options []Option, defaultIndex int) (selected Option) TextInput(msg, defaultValue string) string } @@ -120,6 +121,25 @@ func (ui ptermUI) Confirm(msg string, defaultValue bool) bool { return confirm } +func (ui ptermUI) Enter(msg string) bool { + confirm, err := (&pterm.InteractiveConfirmPrinter{ + DefaultText: msg, + DefaultValue: true, + TextStyle: &pterm.ThemeDefault.DefaultText, + ConfirmText: "Enter", + RejectText: "Cancel", + RejectStyle: &pterm.ThemeDefault.ErrorMessageStyle, + ConfirmStyle: &pterm.ThemeDefault.SuccessMessageStyle, + SuffixStyle: &pterm.ThemeDefault.SecondaryStyle, + }). + Show() + if err != nil { + ui.Panic(err) + } + + return confirm +} + func (ui ptermUI) TextInput(msg, defaultValue string) string { text := msg if defaultValue != "" {