Skip to content

Commit

Permalink
fix test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Dec 8, 2023
1 parent facc481 commit 299ce85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
4 changes: 2 additions & 2 deletions server/tracedb/opensearchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (db *opensearchDB) TestConnection(ctx context.Context) model.ConnectionResu
connection.WithAuthenticationTest(connection.NewTestStep(func(ctx context.Context) (string, error) {
_, err := db.GetTraceByID(ctx, trace.TraceID{}.String())
if strings.Contains(strings.ToLower(err.Error()), "unauthorized") {
return "Tracetest tried to execute a Sumo Logic API request but it failed due to authentication issues", err
return "Tracetest tried to execute an OpenSearch API request but it failed due to authentication issues", err
}

return "Tracetest managed to authenticate with Sumo Logic", nil
return "Tracetest managed to authenticate with OpenSearch", nil
})),
)

Expand Down
33 changes: 7 additions & 26 deletions server/tracedb/sumologicdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,6 @@ type sumologicDB struct {
AccessKey string
}

// TestConnection implements TestableTraceDB.
func (db *sumologicDB) TestConnection(ctx context.Context) model.ConnectionResult {
tester := connection.NewTester(
connection.WithConnectivityTest(connection.ConnectivityStep(model.ProtocolHTTP, db.GetEndpoints())),
connection.WithPollingTest(connection.TracePollingTestStep(ttd)),
connection.WithAuthenticationTest(connection.NewTestStep(func(ctx context.Context) (string, error) {
_, err := ttd.GetTraceByID(ctx, id.NewRandGenerator().TraceID().String())
if strings.Contains(err.Error(), "authentication handshake failed") {
return "Tracetest tried to execute a request but it failed due to authentication issues", err
}

return "Tracetest managed to authenticate with Tempo", nil
})),
)

return tester.TestConnection(ctx)
}

type sumologicSpanSummary struct {
ID string `json:"id"`
Name string `json:"operationName"`
Expand Down Expand Up @@ -85,18 +67,17 @@ func (db *sumologicDB) GetEndpoints() string {
return db.URL
}

func (ttd *tempoTraceDB) TestConnection(ctx context.Context) model.ConnectionResult {
func (db *sumologicDB) TestConnection(ctx context.Context) model.ConnectionResult {
tester := connection.NewTester(
connection.WithPortLintingTest(connection.PortLinter("Tempo", tempoDefaultPorts(), ttd.dataSource.Endpoint())),
connection.WithConnectivityTest(ttd.dataSource),
connection.WithPollingTest(connection.TracePollingTestStep(ttd)),
connection.WithConnectivityTest(connection.ConnectivityStep(model.ProtocolHTTP, db.GetEndpoints())),
connection.WithPollingTest(connection.TracePollingTestStep(db)),
connection.WithAuthenticationTest(connection.NewTestStep(func(ctx context.Context) (string, error) {
_, err := ttd.GetTraceByID(ctx, id.NewRandGenerator().TraceID().String())
if strings.Contains(err.Error(), "authentication handshake failed") {
_, err := db.GetTraceByID(ctx, id.NewRandGenerator().TraceID().String())
if strings.Contains(err.Error(), "Expected 200, got 401") {
return "Tracetest tried to execute a request but it failed due to authentication issues", err
}

return "Tracetest managed to authenticate with Tempo", nil
return "Tracetest managed to authenticate with Sumo Logic", nil
})),
)

Expand Down Expand Up @@ -156,7 +137,7 @@ func (db *sumologicDB) getSpansPage(ctx context.Context, traceID string, token s
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code. Expected 200, got %d: %w", resp.StatusCode, err)
return nil, fmt.Errorf("unexpected status code. Expected 200, got %d", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 299ce85

Please sign in to comment.