feature: [jaeger poc] add test grpc client

This commit is contained in:
Jiekun 2025-01-29 00:13:07 +08:00
parent 615d719fac
commit df2c973e50
No known key found for this signature in database
GPG key ID: 37B4C62D72F5CFB5
2 changed files with 44 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package jaeger
import (
"context"
"encoding/json"
"fmt"
"strconv"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/insertutils"
@ -16,7 +17,7 @@ type SpanWriterPluginServer struct {
func (s *SpanWriterPluginServer) WriteSpan(ctx context.Context, req *proto.WriteSpanRequest) (*proto.WriteSpanResponse, error) {
span := req.GetSpan()
if span == nil {
return nil, nil
return &proto.WriteSpanResponse{}, fmt.Errorf("span not found")
}
jsonSpan, err := json.Marshal(span)

View file

@ -0,0 +1,42 @@
package main
import (
"context"
"fmt"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vlinsert/jaeger/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"testing"
)
func newSpanReaderPluginClient(t *testing.T) proto.SpanReaderPluginClient {
conn, err := grpc.NewClient(fmt.Sprintf("0.0.0.0:%d", 17271), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("cannot connect to server: %v", err)
}
return proto.NewSpanReaderPluginClient(conn)
}
func newSpanWriterPluginClient(t *testing.T) proto.SpanWriterPluginClient {
conn, err := grpc.NewClient(fmt.Sprintf("0.0.0.0:%d", 17271), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("cannot connect to server: %v", err)
}
return proto.NewSpanWriterPluginClient(conn)
}
func TestSpanWriter(t *testing.T) {
// This is NOT a unit test. Please run the VictoriaLogs before executing this test.
client := newSpanWriterPluginClient(t)
req := &proto.WriteSpanRequest{}
resp, err := client.WriteSpan(context.Background(), req)
fmt.Println(resp, err)
}
func TestSpanReaderGetOperations(t *testing.T) {
// This is NOT a unit test. Please run the VictoriaLogs before executing this test.
client := newSpanReaderPluginClient(t)
req := &proto.GetOperationsRequest{}
resp, err := client.GetOperations(context.Background(), req)
fmt.Println(resp, err)
}