Skip to content

Commit c9036ae

Browse files
authored
[jaeger-v2] Define an internal interface of storage v2 spanstore (jaegertracing#5399)
## Which problem is this PR solving? - Part of jaegertracing#5334 ## Description of the changes - An API design of Storage V2 spanstore and its proto file. - For the detailed discussion and how we arrived to this design, please take a look at https://docs.google.com/document/d/1IvUcDsdRxMPK-xTUE32w3NSAGTkUcmnDQttN6ijUnWs/edit?usp=sharing ## How was this change tested? - This PR hasn't been tested yet since it only contains interfaces and no actual implementation to be tested. ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: James Ryans <[email protected]>
1 parent 48a1df9 commit c9036ae

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

storage_v2/empty_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package storage_v2
5+
6+
import (
7+
"testing"
8+
9+
"github.com/jaegertracing/jaeger/pkg/testutils"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
testutils.VerifyGoLeaks(m)
14+
}

storage_v2/factory.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package storage_v2
5+
6+
import (
7+
"context"
8+
)
9+
10+
// Factory is a general factory interface to be reused across different storage factories.
11+
// It lives within the OTEL collector extension component's lifecycle.
12+
// The Initialize and Close functions supposed to be called from the
13+
// OTEL component's Start and Shutdown functions.
14+
type FactoryBase interface {
15+
// Initialize performs internal initialization of the factory,
16+
// such as opening connections to the backend store.
17+
Initialize(ctx context.Context) error
18+
19+
// Close closes the resources held by the factory
20+
Close(ctx context.Context) error
21+
}

storage_v2/spanstore/empty_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package spanstore
5+
6+
import (
7+
"testing"
8+
9+
"github.com/jaegertracing/jaeger/pkg/testutils"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
testutils.VerifyGoLeaks(m)
14+
}

storage_v2/spanstore/factory.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package spanstore
5+
6+
import (
7+
"github.com/jaegertracing/jaeger/storage_v2"
8+
)
9+
10+
// Factory defines an interface for a factory that can create implementations of
11+
// different span storage components.
12+
type Factory interface {
13+
storage_v2.FactoryBase
14+
15+
// CreateTraceReader creates a spanstore.Reader.
16+
CreateTraceReader() (Reader, error)
17+
18+
// CreateTraceWriter creates a spanstore.Writer.
19+
CreateTraceWriter() (Writer, error)
20+
}

storage_v2/spanstore/reader.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package spanstore
5+
6+
import (
7+
"context"
8+
"time"
9+
10+
"go.opentelemetry.io/collector/pdata/pcommon"
11+
"go.opentelemetry.io/collector/pdata/ptrace"
12+
13+
spanstore_v1 "github.com/jaegertracing/jaeger/storage/spanstore"
14+
)
15+
16+
// ErrTraceNotFound is returned by Reader's GetTrace if no data is found for given trace ID.
17+
var ErrTraceNotFound = spanstore_v1.ErrTraceNotFound
18+
19+
// Reader finds and loads traces and other data from storage.
20+
type Reader interface {
21+
// GetTrace retrieves the trace with a given id.
22+
//
23+
// If no spans are stored for this trace, it returns ErrTraceNotFound.
24+
GetTrace(ctx context.Context, traceID pcommon.TraceID) (ptrace.Traces, error)
25+
26+
// GetServices returns all service names known to the backend from spans
27+
// within its retention period.
28+
GetServices(ctx context.Context) ([]string, error)
29+
30+
// GetOperations returns all operation names for a given service
31+
// known to the backend from spans within its retention period.
32+
GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error)
33+
34+
// FindTraces returns all traces matching query parameters. There's currently
35+
// an implementation-dependent ambiguity whether all query filters (such as
36+
// multiple tags) must apply to the same span within a trace, or can be satisfied
37+
// by different spans.
38+
//
39+
// If no matching traces are found, the function returns (nil, nil).
40+
FindTraces(ctx context.Context, query TraceQueryParameters) ([]ptrace.Traces, error)
41+
42+
// FindTraceIDs does the same search as FindTraces, but returns only the list
43+
// of matching trace IDs.
44+
//
45+
// If no matching traces are found, the function returns (nil, nil).
46+
FindTraceIDs(ctx context.Context, query TraceQueryParameters) ([]pcommon.TraceID, error)
47+
}
48+
49+
// TraceQueryParameters contains parameters of a trace query.
50+
type TraceQueryParameters struct {
51+
ServiceName string
52+
OperationName string
53+
Tags map[string]string
54+
StartTimeMin time.Time
55+
StartTimeMax time.Time
56+
DurationMin time.Duration
57+
DurationMax time.Duration
58+
NumTraces int
59+
}
60+
61+
// OperationQueryParameters contains parameters of query operations, empty spanKind means get operations for all kinds of span.
62+
type OperationQueryParameters struct {
63+
ServiceName string
64+
SpanKind string
65+
}
66+
67+
// Operation contains operation name and span kind
68+
type Operation struct {
69+
Name string
70+
SpanKind string
71+
}

storage_v2/spanstore/writer.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package spanstore
5+
6+
import (
7+
"context"
8+
9+
"go.opentelemetry.io/collector/pdata/ptrace"
10+
)
11+
12+
// Writer writes spans to storage.
13+
type Writer interface {
14+
// WriteTrace writes a batch of spans to storage. Idempotent.
15+
// Implementations are not required to support atomic transactions,
16+
// so if any of the spans fail to be written an error is returned.
17+
// Compatible with OTLP Exporter API.
18+
WriteTraces(ctx context.Context, td ptrace.Traces) error
19+
}

0 commit comments

Comments
 (0)