-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[grpc][v2] Implement GetServices
Call in GRPC reader for remote storage api v2
#6829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed718e7
Add GetTraces Call To GRPC Client
mahadzaryab1 8664d2a
Address Feedback
mahadzaryab1 161d699
Rename File
mahadzaryab1 4c29422
Implement tracestore.Reader
mahadzaryab1 a6ddcb2
Add package_test.go
mahadzaryab1 7f6a59b
Implement GetServices And Write Unit Test
mahadzaryab1 eeb62d6
Add Missing Unit Test And Documentation
mahadzaryab1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package grpc | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testutils.VerifyGoLeaks(m) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package grpc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"iter" | ||
|
||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/jaegertracing/jaeger/internal/storage/v2/api/tracestore" | ||
"github.com/jaegertracing/jaeger/proto-gen/storage/v2" | ||
) | ||
|
||
var _ tracestore.Reader = (*TraceReader)(nil) | ||
|
||
var errFailedToGetServices = errors.New("failed to get services") | ||
|
||
type TraceReader struct { | ||
client storage.TraceReaderClient | ||
} | ||
|
||
// NewTraceReader creates a TraceReader that communicates with a remote gRPC storage server. | ||
// The provided gRPC connection is used exclusively for reading traces, meaning it is safe | ||
// to enable instrumentation on the connection without risk of recursively generating traces. | ||
func NewTraceReader(conn *grpc.ClientConn) *TraceReader { | ||
return &TraceReader{ | ||
client: storage.NewTraceReaderClient(conn), | ||
} | ||
} | ||
|
||
func (*TraceReader) GetTraces( | ||
context.Context, | ||
...tracestore.GetTraceParams, | ||
) iter.Seq2[[]ptrace.Traces, error] { | ||
panic("not implemented") | ||
} | ||
|
||
func (tr *TraceReader) GetServices(ctx context.Context) ([]string, error) { | ||
resp, err := tr.client.GetServices(ctx, &storage.GetServicesRequest{}) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w: %w", errFailedToGetServices, err) | ||
} | ||
return resp.Services, nil | ||
} | ||
|
||
func (*TraceReader) GetOperations( | ||
context.Context, | ||
tracestore.OperationQueryParams, | ||
) ([]tracestore.Operation, error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (*TraceReader) FindTraces( | ||
context.Context, | ||
tracestore.TraceQueryParams, | ||
) iter.Seq2[[]ptrace.Traces, error] { | ||
panic("not implemented") | ||
} | ||
|
||
func (*TraceReader) FindTraceIDs( | ||
context.Context, | ||
tracestore.TraceQueryParams, | ||
) iter.Seq2[[]tracestore.FoundTraceID, error] { | ||
panic("not implemented") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package grpc | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/jaegertracing/jaeger/internal/storage/v2/api/tracestore" | ||
"github.com/jaegertracing/jaeger/proto-gen/storage/v2" | ||
) | ||
|
||
// testServer implements the storage.TraceReaderServer interface | ||
// to simulate responses for testing. | ||
type testServer struct { | ||
storage.UnimplementedTraceReaderServer | ||
|
||
getServicesError error | ||
} | ||
|
||
func (s *testServer) GetServices( | ||
context.Context, | ||
*storage.GetServicesRequest, | ||
) (*storage.GetServicesResponse, error) { | ||
if s.getServicesError != nil { | ||
return nil, s.getServicesError | ||
} | ||
return &storage.GetServicesResponse{ | ||
Services: []string{"service-a", "service-b"}, | ||
}, nil | ||
} | ||
|
||
func startTestServer(t *testing.T, testServer *testServer) *grpc.ClientConn { | ||
listener, err := net.Listen("tcp", ":0") | ||
require.NoError(t, err) | ||
|
||
server := grpc.NewServer() | ||
storage.RegisterTraceReaderServer(server, testServer) | ||
|
||
go func() { | ||
server.Serve(listener) | ||
}() | ||
|
||
conn, err := grpc.NewClient( | ||
listener.Addr().String(), | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup( | ||
func() { | ||
conn.Close() | ||
server.Stop() | ||
listener.Close() | ||
}, | ||
) | ||
|
||
return conn | ||
} | ||
|
||
func TestTraceReader_GetTraces(t *testing.T) { | ||
tr := &TraceReader{} | ||
|
||
require.Panics(t, func() { | ||
tr.GetTraces(context.Background(), tracestore.GetTraceParams{}) | ||
}) | ||
} | ||
|
||
func TestTraceReader_GetServices(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
testServer *testServer | ||
expectedServices []string | ||
expectedError error | ||
}{ | ||
{ | ||
name: "success", | ||
testServer: &testServer{}, | ||
expectedServices: []string{"service-a", "service-b"}, | ||
}, | ||
{ | ||
name: "error", | ||
testServer: &testServer{ | ||
getServicesError: assert.AnError, | ||
}, | ||
expectedError: errFailedToGetServices, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
conn := startTestServer(t, test.testServer) | ||
|
||
reader := NewTraceReader(conn) | ||
services, err := reader.GetServices(context.Background()) | ||
|
||
require.ErrorIs(t, err, test.expectedError) | ||
require.Equal(t, test.expectedServices, services) | ||
}) | ||
} | ||
} | ||
|
||
func TestTraceReader_GetOperations(t *testing.T) { | ||
tr := &TraceReader{} | ||
|
||
require.Panics(t, func() { | ||
tr.GetOperations(context.Background(), tracestore.OperationQueryParams{}) | ||
}) | ||
} | ||
|
||
func TestTraceReader_FindTraces(t *testing.T) { | ||
tr := &TraceReader{} | ||
|
||
require.Panics(t, func() { | ||
tr.FindTraces(context.Background(), tracestore.TraceQueryParams{}) | ||
}) | ||
} | ||
|
||
func TestTraceReader_FindTraceIDs(t *testing.T) { | ||
tr := &TraceReader{} | ||
|
||
require.Panics(t, func() { | ||
tr.FindTraceIDs(context.Background(), tracestore.TraceQueryParams{}) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the panic will be from nil ptr dereference rather than from "not implemented"