Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): Adding otlp server error handling #3252

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion agent/initialization/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package initialization

import (
"context"
"errors"
"fmt"

"github.com/kubeshop/tracetest/agent/client"
Expand All @@ -13,6 +14,8 @@ import (
"go.opentelemetry.io/otel/trace"
)

var ErrOtlpServerStart = errors.New("OTLP server start error")

func NewClient(ctx context.Context, config config.Config, traceCache collector.TraceCache) (*client.Client, error) {
client, err := client.Connect(ctx, config.ServerURL,
client.WithAPIKey(config.APIKey),
Expand Down Expand Up @@ -72,7 +75,7 @@ func StartCollector(ctx context.Context, config config.Config, traceCache collec

_, err := collector.Start(ctx, collectorConfig, noopTracer, collector.WithTraceCache(traceCache), collector.WithStartRemoteServer(false))
if err != nil {
return err
return ErrOtlpServerStart
}

return nil
Expand Down
29 changes: 24 additions & 5 deletions cli/pkg/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package starter
import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/golang-jwt/jwt/v4"
Expand Down Expand Up @@ -106,11 +107,29 @@ func (s *Starter) StartAgent(ctx context.Context, endpoint, agentApiKey, uiEndpo
cfg.APIKey = agentApiKey
}

s.ui.Println(fmt.Sprintf(`
Starting Agent with name %s...`, cfg.Name))
session, err := initialization.Start(ctx, cfg)
if err != nil {
return err
s.ui.Info(fmt.Sprintf("Starting Agent with name %s...", cfg.Name))

isStarted := false
session := &initialization.Session{}
for !isStarted {
session, err = initialization.Start(ctx, cfg)
if err != nil && errors.Is(err, initialization.ErrOtlpServerStart) {
s.ui.Error("Tracetest Agent binds to the OpenTelemetry ports 4317 and 4318 which are used to receive trace information from your system. The agent tried to bind to these ports, but failed.")
shouldRetry := s.ui.Enter("Please stop the process currently listening on these ports and enter to try again.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can improve the message: ...and press enter to try again


if !shouldRetry {
s.ui.Finish()
return err
}

continue
}

if err != nil {
return err
}

isStarted = true
}

claims, err := s.getTokenClaims(session.Token)
Expand Down