From cd16c67f593505d67d05e69b0579a99ea79e16e5 Mon Sep 17 00:00:00 2001 From: James Ryans Date: Thu, 25 Apr 2024 16:11:39 +0700 Subject: [PATCH] construct the storage_v2 spanstore interface structure --- storage_v2/spanstore/factory.go | 18 +++++++++ storage_v2/spanstore/reader.go | 65 +++++++++++++++++++++++++++++++++ storage_v2/spanstore/writer.go | 17 +++++++++ 3 files changed, 100 insertions(+) create mode 100644 storage_v2/spanstore/factory.go create mode 100644 storage_v2/spanstore/reader.go create mode 100644 storage_v2/spanstore/writer.go diff --git a/storage_v2/spanstore/factory.go b/storage_v2/spanstore/factory.go new file mode 100644 index 000000000000..30d08a2f87e5 --- /dev/null +++ b/storage_v2/spanstore/factory.go @@ -0,0 +1,18 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package spanstore + +// Factory defines an interface for a factory that can create implementations of different storage components. +// Implementations are also encouraged to implement plugin.Configurable interface. +type Factory interface { + // Initialize performs internal initialization of the factory, such as opening connections to the backend store. + // It is called after all configuration of the factory itself has been done. + Initialize() error + + // CreateSpanReader creates a spanstore.Reader. + CreateTraceReader() (Reader, error) + + // CreateSpanWriter creates a spanstore.Writer. + CreateTraceWriter() (Writer, error) +} diff --git a/storage_v2/spanstore/reader.go b/storage_v2/spanstore/reader.go new file mode 100644 index 000000000000..0c8a0065d609 --- /dev/null +++ b/storage_v2/spanstore/reader.go @@ -0,0 +1,65 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package spanstore + +import ( + "context" + "time" + + "github.com/jaegertracing/jaeger/model" +) + +// Reader finds and loads traces and other data from storage. +type Reader interface { + // GetTrace retrieves the trace with a given id. + // + // If no spans are stored for this trace, it returns ErrTraceNotFound. + GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) + + // GetServices returns all service names known to the backend from spans + // within its retention period. + GetServices(ctx context.Context) ([]string, error) + + // GetOperations returns all operation names for a given service + // known to the backend from spans within its retention period. + GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error) + + // FindTraces returns all traces matching query parameters. There's currently + // an implementation-dependent abiguity whether all query filters (such as + // multiple tags) must apply to the same span within a trace, or can be satisfied + // by different spans. + // + // If no matching traces are found, the function returns (nil, nil). + FindTraces(ctx context.Context, query *TraceQueryParameters) ([]*model.Trace, error) + + // FindTraceIDs does the same search as FindTraces, but returns only the list + // of matching trace IDs. + // + // If no matching traces are found, the function returns (nil, nil). + FindTraceIDs(ctx context.Context, query *TraceQueryParameters) ([]model.TraceID, error) +} + +// TraceQueryParameters contains parameters of a trace query. +type TraceQueryParameters struct { + ServiceName string + OperationName string + Tags map[string]string + StartTimeMin time.Time + StartTimeMax time.Time + DurationMin time.Duration + DurationMax time.Duration + NumTraces int +} + +// OperationQueryParameters contains parameters of query operations, empty spanKind means get operations for all kinds of span. +type OperationQueryParameters struct { + ServiceName string + SpanKind string +} + +// Operation contains operation name and span kind +type Operation struct { + Name string + SpanKind string +} diff --git a/storage_v2/spanstore/writer.go b/storage_v2/spanstore/writer.go new file mode 100644 index 000000000000..0b71b31b30d0 --- /dev/null +++ b/storage_v2/spanstore/writer.go @@ -0,0 +1,17 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package spanstore + +import ( + "context" + + "go.opentelemetry.io/collector/pdata/ptrace" +) + +// Writer writes spans to storage. +type Writer interface { + // WriteTrace writes batches of spans at once and + // compatible with OTLP Exporter API. + WriteTraces(ctx context.Context, td ptrace.Traces) error +}