Skip to content

Commit

Permalink
Hold TraceReader In Query Service
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Nov 16, 2024
1 parent aadc917 commit 2321c76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
4 changes: 3 additions & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics"
"github.com/jaegertracing/jaeger/storage/spanstore"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage_v2/factoryadapter"
)

// all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store
Expand Down Expand Up @@ -219,7 +220,8 @@ func startQuery(
telset telemetery.Setting,
) *queryApp.Server {
spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, telset.Metrics)
qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts)
traceReader := factoryadapter.NewTraceReader(spanReader)
qs := querysvc.NewQueryService(traceReader, depReader, *queryOpts)

server, err := queryApp.NewServer(context.Background(), qs, metricsQueryService, qOpts, tm, telset)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/jaegertracing/jaeger/plugin/metrics/disabled"
"github.com/jaegertracing/jaeger/storage/metricsstore"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage_v2/factoryadapter"
)

var (
Expand Down Expand Up @@ -66,6 +67,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error {
}

spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, queryMetricsFactory)
traceReader := factoryadapter.NewTraceReader(spanReader)

depReader, err := f.CreateDependencyReader()
if err != nil {
Expand All @@ -76,7 +78,7 @@ func (s *server) Start(ctx context.Context, host component.Host) error {
if err := s.addArchiveStorage(&opts, host); err != nil {
return err
}
qs := querysvc.NewQueryService(spanReader, depReader, opts)
qs := querysvc.NewQueryService(traceReader, depReader, opts)

mqs, err := s.createMetricReader(host)
if err != nil {
Expand Down
44 changes: 31 additions & 13 deletions cmd/query/app/querysvc/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"github.com/jaegertracing/jaeger/model/adjuster"
"github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage/dependencystore"
"github.com/jaegertracing/jaeger/storage/spanstore"
spanstore_v1 "github.com/jaegertracing/jaeger/storage/spanstore"
"github.com/jaegertracing/jaeger/storage_v2/factoryadapter"
"github.com/jaegertracing/jaeger/storage_v2/spanstore"
)

var errNoArchiveSpanStorage = errors.New("archive span storage was not configured")
Expand All @@ -25,8 +27,8 @@ const (

// QueryServiceOptions has optional members of QueryService
type QueryServiceOptions struct {
ArchiveSpanReader spanstore.Reader
ArchiveSpanWriter spanstore.Writer
ArchiveSpanReader spanstore_v1.Reader
ArchiveSpanWriter spanstore_v1.Writer
Adjuster adjuster.Adjuster
}

Expand All @@ -40,15 +42,15 @@ type StorageCapabilities struct {

// QueryService contains span utils required by the query-service.
type QueryService struct {
spanReader spanstore.Reader
traceReader spanstore.Reader
dependencyReader dependencystore.Reader
options QueryServiceOptions
}

// NewQueryService returns a new QueryService.
func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService {
func NewQueryService(traceReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService {

Check warning on line 51 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L51

Added line #L51 was not covered by tests
qsvc := &QueryService{
spanReader: spanReader,
traceReader: traceReader,

Check warning on line 53 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L53

Added line #L53 was not covered by tests
dependencyReader: dependencyReader,
options: options,
}
Expand All @@ -61,7 +63,11 @@ func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencysto

// GetTrace is the queryService implementation of spanstore.Reader.GetTrace
func (qs QueryService) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
trace, err := qs.spanReader.GetTrace(ctx, traceID)
spanReader, err := factoryadapter.GetV1Reader(qs.traceReader)
if err != nil {
return nil, err
}
trace, err := spanReader.GetTrace(ctx, traceID)

Check warning on line 70 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L66-L70

Added lines #L66 - L70 were not covered by tests
if errors.Is(err, spanstore.ErrTraceNotFound) {
if qs.options.ArchiveSpanReader == nil {
return nil, err
Expand All @@ -73,20 +79,32 @@ func (qs QueryService) GetTrace(ctx context.Context, traceID model.TraceID) (*mo

// GetServices is the queryService implementation of spanstore.Reader.GetServices
func (qs QueryService) GetServices(ctx context.Context) ([]string, error) {
return qs.spanReader.GetServices(ctx)
spanReader, err := factoryadapter.GetV1Reader(qs.traceReader)
if err != nil {
return nil, err
}
return spanReader.GetServices(ctx)

Check warning on line 86 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L82-L86

Added lines #L82 - L86 were not covered by tests
}

// GetOperations is the queryService implementation of spanstore.Reader.GetOperations
func (qs QueryService) GetOperations(
ctx context.Context,
query spanstore.OperationQueryParameters,
) ([]spanstore.Operation, error) {
return qs.spanReader.GetOperations(ctx, query)
query spanstore_v1.OperationQueryParameters,
) ([]spanstore_v1.Operation, error) {
spanReader, err := factoryadapter.GetV1Reader(qs.traceReader)
if err != nil {
return nil, err
}
return spanReader.GetOperations(ctx, query)

Check warning on line 98 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L93-L98

Added lines #L93 - L98 were not covered by tests
}

// FindTraces is the queryService implementation of spanstore.Reader.FindTraces
func (qs QueryService) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
return qs.spanReader.FindTraces(ctx, query)
func (qs QueryService) FindTraces(ctx context.Context, query *spanstore_v1.TraceQueryParameters) ([]*model.Trace, error) {
spanReader, err := factoryadapter.GetV1Reader(qs.traceReader)
if err != nil {
return nil, err
}
return spanReader.FindTraces(ctx, query)

Check warning on line 107 in cmd/query/app/querysvc/query_service.go

View check run for this annotation

Codecov / codecov/patch

cmd/query/app/querysvc/query_service.go#L102-L107

Added lines #L102 - L107 were not covered by tests
}

// ArchiveTrace is the queryService utility to archive traces.
Expand Down
4 changes: 3 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/jaegertracing/jaeger/ports"
metricsstoreMetrics "github.com/jaegertracing/jaeger/storage/metricsstore/metrics"
spanstoreMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
"github.com/jaegertracing/jaeger/storage_v2/factoryadapter"
)

func main() {
Expand Down Expand Up @@ -89,6 +90,7 @@ func main() {
logger.Fatal("Failed to create span reader", zap.Error(err))
}
spanReader = spanstoreMetrics.NewReadMetricsDecorator(spanReader, metricsFactory)
traceReader := factoryadapter.NewTraceReader(spanReader)
dependencyReader, err := storageFactory.CreateDependencyReader()
if err != nil {
logger.Fatal("Failed to create dependency reader", zap.Error(err))
Expand All @@ -100,7 +102,7 @@ func main() {
}
queryServiceOptions := queryOpts.BuildQueryServiceOptions(storageFactory, logger)
queryService := querysvc.NewQueryService(
spanReader,
traceReader,
dependencyReader,
*queryServiceOptions)
tm := tenancy.NewManager(&queryOpts.Tenancy)
Expand Down

0 comments on commit 2321c76

Please sign in to comment.