Skip to content

Commit

Permalink
Revert "replace connection test result with structure from model pack…
Browse files Browse the repository at this point in the history
…age"

This reverts commit 8a820f9.
  • Loading branch information
mathnogueira committed Mar 28, 2023
1 parent 8a820f9 commit 98d258c
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 208 deletions.
4 changes: 2 additions & 2 deletions server/executor/poller_executor_test.go
Expand Up @@ -585,8 +585,8 @@ func (db *traceDBMock) GetTraceID() trace.TraceID {
func (db *traceDBMock) Connect(ctx context.Context) error { return nil }
func (db *traceDBMock) Close() error { return nil }
func (db *traceDBMock) Ready() bool { return true }
func (db *traceDBMock) TestConnection(ctx context.Context) model.ConnectionResult {
return model.ConnectionResult{}
func (db *traceDBMock) TestConnection(ctx context.Context) connection.ConnectionTestResult {
return connection.ConnectionTestResult{}
}

type traceDBState struct {
Expand Down
26 changes: 13 additions & 13 deletions server/http/mappings/datastore.go
@@ -1,41 +1,41 @@
package mappings

import (
"github.com/kubeshop/tracetest/server/model"
"github.com/kubeshop/tracetest/server/openapi"
"github.com/kubeshop/tracetest/server/tracedb/connection"
)

func (m *OpenAPI) ConnectionTestResult(in model.ConnectionResult) openapi.ConnectionResult {
func (m *OpenAPI) ConnectionTestResult(in connection.ConnectionTestResult) openapi.ConnectionResult {
result := openapi.ConnectionResult{}

if in.PortCheck.IsSet() {
result.PortCheck = m.ConnectionTestStep(in.PortCheck)
if in.EndpointLintTestResult.IsSet() {
result.PortCheck = m.ConnectionTestStep(in.EndpointLintTestResult)
}

if in.Connectivity.IsSet() {
result.Connectivity = m.ConnectionTestStep(in.Connectivity)
if in.ConnectivityTestResult.IsSet() {
result.Connectivity = m.ConnectionTestStep(in.ConnectivityTestResult)
}

if in.Authentication.IsSet() {
result.Authentication = m.ConnectionTestStep(in.Authentication)
if in.AuthenticationTestResult.IsSet() {
result.Authentication = m.ConnectionTestStep(in.AuthenticationTestResult)
}

if in.FetchTraces.IsSet() {
result.FetchTraces = m.ConnectionTestStep(in.FetchTraces)
if in.TraceRetrievalTestResult.IsSet() {
result.FetchTraces = m.ConnectionTestStep(in.TraceRetrievalTestResult)
}

return result
}

func (m *OpenAPI) ConnectionTestStep(in model.ConnectionTestStep) openapi.ConnectionTestStep {
func (m *OpenAPI) ConnectionTestStep(in connection.ConnectionTestStepResult) openapi.ConnectionTestStep {
errMessage := ""
if in.Error != nil {
errMessage = in.Error.Error()
}

return openapi.ConnectionTestStep{
Passed: in.Status != model.StatusFailed,
Message: in.Message,
Passed: in.Status != connection.StatusFailed,
Message: in.OperationDescription,
Status: string(in.Status),
Error: errMessage,
}
Expand Down
35 changes: 0 additions & 35 deletions server/model/connection_test_result.go

This file was deleted.

49 changes: 0 additions & 49 deletions server/model/test_run_event.go

This file was deleted.

4 changes: 2 additions & 2 deletions server/tracedb/awsxray.go
Expand Up @@ -87,10 +87,10 @@ func (db *awsxrayDB) Close() error {
return nil
}

func (db *awsxrayDB) TestConnection(ctx context.Context) model.ConnectionResult {
func (db *awsxrayDB) TestConnection(ctx context.Context) connection.ConnectionTestResult {
url := fmt.Sprintf("xray.%s.amazonaws.com:443", db.region)
tester := connection.NewTester(
connection.WithConnectivityTest(connection.ConnectivityStep(model.ProtocolHTTP, url)),
connection.WithConnectivityTest(connection.ConnectivityStep(connection.ProtocolHTTP, url)),
connection.WithPollingTest(connection.TracePollingTestStep(db)),
connection.WithAuthenticationTest(connection.NewTestStep(func(ctx context.Context) (string, error) {
_, err := db.GetTraceByID(ctx, db.GetTraceID().String())
Expand Down
47 changes: 43 additions & 4 deletions server/tracedb/connection/connection.go
Expand Up @@ -7,20 +7,59 @@ import (
"net/url"
"strings"
"time"

"github.com/kubeshop/tracetest/server/model"
)

const reachabilityTimeout = 5 * time.Second

type (
Protocol string
Status string
)

var (
ProtocolHTTP Protocol = "http"
ProtocolGRPC Protocol = "grpc"
)

var (
StatusPassed Status = "passed"
StatusWarning Status = "warning"
StatusFailed Status = "failed"
)

type ConnectionTestResult struct {
EndpointLintTestResult ConnectionTestStepResult
ConnectivityTestResult ConnectionTestStepResult
AuthenticationTestResult ConnectionTestStepResult
TraceRetrievalTestResult ConnectionTestStepResult
}

var (
ErrTraceNotFound = errors.New("trace not found")
ErrInvalidConfiguration = errors.New("invalid data store configuration")
ErrConnectionFailed = errors.New("could not connect to data store")
)

func CheckReachability(endpoint string, protocol model.Protocol) error {
if protocol == model.ProtocolHTTP {
func (c ConnectionTestResult) HasSucceed() bool {
return c.AuthenticationTestResult.HasSucceed() && c.ConnectivityTestResult.HasSucceed() && c.TraceRetrievalTestResult.HasSucceed()
}

type ConnectionTestStepResult struct {
OperationDescription string
Status Status
Error error
}

func (r ConnectionTestStepResult) HasSucceed() bool {
return r.Error == nil
}

func (r ConnectionTestStepResult) IsSet() bool {
return r.OperationDescription != ""
}

func CheckReachability(endpoint string, protocol Protocol) error {
if protocol == ProtocolHTTP {
address, err := url.Parse(endpoint)
if err != nil {
return err
Expand Down
27 changes: 13 additions & 14 deletions server/tracedb/connection/connectivity_step.go
Expand Up @@ -6,17 +6,16 @@ import (
"strings"

"github.com/hashicorp/go-multierror"
"github.com/kubeshop/tracetest/server/model"
)

type connectivityTestStep struct {
endpoints []string
protocol model.Protocol
protocol Protocol
}

var _ TestStep = &connectivityTestStep{}

func (s *connectivityTestStep) TestConnection(_ context.Context) model.ConnectionTestStep {
func (s *connectivityTestStep) TestConnection(_ context.Context) ConnectionTestStepResult {
unreachableEndpoints := make([]string, 0)
var connectionErr error
for _, endpoint := range s.endpoints {
Expand All @@ -31,29 +30,29 @@ func (s *connectivityTestStep) TestConnection(_ context.Context) model.Connectio
}

if len(s.endpoints) == 0 {
return model.ConnectionTestStep{
Message: "Tracetest tried to connect but no endpoints were provided",
Error: fmt.Errorf("no endpoints provided"),
return ConnectionTestStepResult{
OperationDescription: "Tracetest tried to connect but no endpoints were provided",
Error: fmt.Errorf("no endpoints provided"),
}
}

if connectionErr != nil {
endpoints := strings.Join(unreachableEndpoints, ", ")
return model.ConnectionTestStep{
Message: fmt.Sprintf("Tracetest tried to connect to the following endpoints and failed: %s", endpoints),
Status: model.StatusFailed,
Error: connectionErr,
return ConnectionTestStepResult{
OperationDescription: fmt.Sprintf("Tracetest tried to connect to the following endpoints and failed: %s", endpoints),
Status: StatusFailed,
Error: connectionErr,
}
}

endpoints := strings.Join(s.endpoints, ", ")
return model.ConnectionTestStep{
Message: fmt.Sprintf(`Tracetest connected to %s`, endpoints),
Status: model.StatusPassed,
return ConnectionTestStepResult{
OperationDescription: fmt.Sprintf(`Tracetest connected to %s`, endpoints),
Status: StatusPassed,
}
}

func ConnectivityStep(protocol model.Protocol, endpoints ...string) TestStep {
func ConnectivityStep(protocol Protocol, endpoints ...string) TestStep {
return &connectivityTestStep{
endpoints: endpoints,
protocol: protocol,
Expand Down
14 changes: 5 additions & 9 deletions server/tracedb/connection/options.go
@@ -1,10 +1,6 @@
package connection

import (
"context"

"github.com/kubeshop/tracetest/server/model"
)
import "context"

func WithPortLintingTest(step TestStep) TesterOption {
return func(t *Tester) {
Expand Down Expand Up @@ -34,11 +30,11 @@ type functionTestStep struct {
fn func(ctx context.Context) (string, error)
}

func (s *functionTestStep) TestConnection(ctx context.Context) model.ConnectionTestStep {
func (s *functionTestStep) TestConnection(ctx context.Context) ConnectionTestStepResult {
str, err := s.fn(ctx)
return model.ConnectionTestStep{
Message: str,
Error: err,
return ConnectionTestStepResult{
OperationDescription: str,
Error: err,
}
}

Expand Down
16 changes: 7 additions & 9 deletions server/tracedb/connection/port_linting.go
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"regexp"
"strings"

"github.com/kubeshop/tracetest/server/model"
)

type portLinter struct {
Expand All @@ -25,22 +23,22 @@ func PortLinter(dataStoreName string, expectedPorts []string, endpoints ...strin
}
}

func (s *portLinter) TestConnection(ctx context.Context) model.ConnectionTestStep {
func (s *portLinter) TestConnection(ctx context.Context) ConnectionTestStepResult {
for _, endpoint := range s.endpoints {
port := parsePort(endpoint)

if !sliceContains(s.expectedPorts, port) {
suggestedPorts := formatAvailablePortsMessage(s.expectedPorts)
return model.ConnectionTestStep{
Message: fmt.Sprintf(`For %s, port "%s" is not the default port for accessing traces programmatically. Typically, %s uses port %s. If you continue experiencing issues, you may want to verify the correct port to specify.`, s.dataStoreName, port, s.dataStoreName, suggestedPorts),
Status: model.StatusWarning,
return ConnectionTestStepResult{
OperationDescription: fmt.Sprintf(`For %s, port "%s" is not the default port for accessing traces programmatically. Typically, %s uses port %s. If you continue experiencing issues, you may want to verify the correct port to specify.`, s.dataStoreName, port, s.dataStoreName, suggestedPorts),
Status: StatusWarning,
}
}
}

return model.ConnectionTestStep{
Message: `You are using a commonly used port`,
Status: model.StatusPassed,
return ConnectionTestStepResult{
OperationDescription: `You are using a commonly used port`,
Status: StatusPassed,
}
}

Expand Down

0 comments on commit 98d258c

Please sign in to comment.