Skip to content

Commit

Permalink
feat: close jaeger connection (#3839)
Browse files Browse the repository at this point in the history
* feat: reuse jaeger connection

* invalidate cache if connection test fails on tracing step

* remove cache and close datastore after poll

* clean up

* check for error before closing conn

---------

Co-authored-by: Oscar Reyes <[email protected]>
  • Loading branch information
mathnogueira and xoscar authored May 3, 2024
1 parent 4a85d9d commit 9c3bbb0
Show file tree
Hide file tree
Showing 4 changed files with 15 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}
}
1 change: 1 addition & 0 deletions agent/workers/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (w *PollerWorker) poll(ctx context.Context, request *proto.PollingRequest)
log.Printf("Invalid datastore: %s", err.Error())
return err
}
defer ds.Close()
w.logger.Debug("Created datastore", zap.Any("datastore", ds), zap.Bool("isOTLPBasedProvider", datastoreConfig.IsOTLPBasedProvider()))

if datastoreConfig.IsOTLPBasedProvider() && w.inmemoryDatastore != nil {
Expand Down

0 comments on commit 9c3bbb0

Please sign in to comment.