Skip to content

Commit

Permalink
invalidate cache if connection test fails on tracing step
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed May 2, 2024
1 parent e3d1f65 commit 44e081f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion agent/tracedb/connection/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func WithAuthenticationTest(step TestStep) TesterOption {
}
}

func WithPollingTest(step TestStep) TesterOption {
func WithPollingTest(step CloseableTestStep) TesterOption {
return func(t *Tester) {
t.pollingTestStep = step
}
Expand Down
8 changes: 7 additions & 1 deletion agent/tracedb/connection/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ type TestStep interface {
TestConnection(ctx context.Context) model.ConnectionTestStep
}

type CloseableTestStep interface {
TestStep
CloseConnection() error
}

type TesterOption func(*Tester)

type Tester struct {
portLinterStep TestStep
connectivityTestStep TestStep
authenticationTestStep TestStep
pollingTestStep TestStep
pollingTestStep CloseableTestStep
}

func NewTester(opts ...TesterOption) Tester {
Expand Down Expand Up @@ -53,6 +58,7 @@ func (t *Tester) TestConnection(ctx context.Context) (res model.ConnectionResult
res.FetchTraces = t.pollingTestStep.TestConnection(ctx)
if res.FetchTraces.Error != nil {
res.FetchTraces.Status = model.StatusFailed
t.pollingTestStep.CloseConnection()
}

return
Expand Down
7 changes: 6 additions & 1 deletion agent/tracedb/connection/trace_polling_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type DataStore interface {
GetTraceByID(context.Context, string) (traces.Trace, error)
GetTraceID() trace.TraceID
Close() error
}

type tracePollingTestStep struct {
Expand All @@ -35,6 +36,10 @@ func (s *tracePollingTestStep) TestConnection(ctx context.Context) model.Connect
}
}

func TracePollingTestStep(ds DataStore) TestStep {
func (s *tracePollingTestStep) CloseConnection() error {
return s.dataStore.Close()
}

func TracePollingTestStep(ds DataStore) CloseableTestStep {
return &tracePollingTestStep{ds}
}
8 changes: 8 additions & 0 deletions agent/tracedb/jaegerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func saveConnectionToCache(grpcConfig *datastore.GRPCClientSettings, traceDB Tra
connectionPool[grpcConfig.Endpoint] = traceDB
}

func invalidateConnectionCache(endpoint string) {
connectionPoolMutex.Lock()
defer connectionPoolMutex.Unlock()

delete(connectionPool, endpoint)
}

type jaegerTraceDB struct {
realTraceDB
dataSource datasource.DataSource
Expand Down Expand Up @@ -107,6 +114,7 @@ func (jtd *jaegerTraceDB) Ready() bool {
}

func (jtd *jaegerTraceDB) Close() error {
invalidateConnectionCache(jtd.dataSource.Endpoint())
return jtd.dataSource.Close()
}

Expand Down

0 comments on commit 44e081f

Please sign in to comment.