Skip to content

Commit

Permalink
add test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Dec 8, 2023
1 parent 1c9b992 commit facc481
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 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 an OpenSearch API request but it failed due to authentication issues", err
return "Tracetest tried to execute a Sumo Logic API request but it failed due to authentication issues", err
}

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

Expand Down
40 changes: 40 additions & 0 deletions server/tracedb/sumologic.go → server/tracedb/sumologicdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/kubeshop/tracetest/server/datastore"
"github.com/kubeshop/tracetest/server/model"
"github.com/kubeshop/tracetest/server/pkg/id"
"github.com/kubeshop/tracetest/server/tracedb/connection"
"github.com/kubeshop/tracetest/server/traces"
"go.opentelemetry.io/otel/trace"
Expand All @@ -23,6 +26,24 @@ 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 @@ -64,6 +85,24 @@ func (db *sumologicDB) GetEndpoints() string {
return db.URL
}

func (ttd *tempoTraceDB) 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.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)
}

// GetTraceByID implements TraceDB.
func (db *sumologicDB) GetTraceByID(ctx context.Context, traceID string) (traces.Trace, error) {
summaries, err := db.getTraceSpans(ctx, traceID, "")
Expand Down Expand Up @@ -294,3 +333,4 @@ func (db *sumologicDB) getAugmentedSpan(ctx context.Context, traceID string, spa

var _ TraceDB = &sumologicDB{}
var _ TraceAugmenter = &sumologicDB{}
var _ TestableTraceDB = &sumologicDB{}

0 comments on commit facc481

Please sign in to comment.