Skip to content

Commit

Permalink
[pdata] Rename Client|Server to GRPC[Client|Server] (#6165)
Browse files Browse the repository at this point in the history
Co-authored-by: Bogdan Drutu <[email protected]>
  • Loading branch information
dmitryax and bogdandrutu authored Sep 28, 2022
1 parent 3b70df9 commit 1c217b3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Deprecate `pmetric.Metric.DataType()` in favor of `pmetric.Metric.Type()`. (#6127)
- Deprecate `pmetric.NumberDataPoint.[Set]?[Int|Double]Val()` in favor of `pmetric.NumberDataPoint.[Set]?[Int|Double]Value()`. (#6134)
- Deprecate `pmetric.Exemplar.[Set]?[Int|Double]Val()` in favor of `pmetric.Exemplar.[Set]?[Int|Double]Value()`. (#6134)
- Deprecate `p[metric|log|trace]otlp.[Client|Server]` in favor of `p[metric|log|trace]otlp.GRPC[Client|Server]` (#6165)
- Deprecate pdata Clone methods in favor of CopyTo for consistency with other pdata structs (#6164)
- `pmetric.Metrics.Clone` is deprecated in favor of `pmetric.Metrics.CopyTo`
- `ptrace.Traces.Clone` is deprecated in favor of `pmetric.Traces.CopyTo`
Expand Down
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,13 @@ func (ms *mockedStream) Context() context.Context {
func TestClientInfoInterceptors(t *testing.T) {
testCases := []struct {
desc string
tester func(context.Context, ptraceotlp.Client)
tester func(context.Context, ptraceotlp.GRPCClient)
}{
{
// we only have unary services, we don't have any clients we could use
// to test with streaming services
desc: "unary",
tester: func(ctx context.Context, cl ptraceotlp.Client) {
tester: func(ctx context.Context, cl ptraceotlp.GRPCClient) {
resp, errResp := cl.Export(ctx, ptraceotlp.NewRequest())
require.NoError(t, errResp)
require.NotNil(t, resp)
Expand Down
6 changes: 3 additions & 3 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type exporter struct {
config *Config

// gRPC clients and connection.
traceExporter ptraceotlp.Client
metricExporter pmetricotlp.Client
logExporter plogotlp.Client
traceExporter ptraceotlp.GRPCClient
metricExporter pmetricotlp.GRPCClient
logExporter plogotlp.GRPCClient
clientConn *grpc.ClientConn
metadata metadata.MD
callOptions []grpc.CallOption
Expand Down
20 changes: 13 additions & 7 deletions pdata/plog/plogotlp/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,26 @@ func (lr Request) Logs() plog.Logs {
return plog.Logs(internal.NewLogs(lr.orig))
}

// Client is the client API for OTLP-GRPC Logs service.
// GRPCClient is the client API for OTLP-GRPC Logs service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type Client interface {
type GRPCClient interface {
// Export plog.Logs to the server.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(ctx context.Context, request Request, opts ...grpc.CallOption) (Response, error)
}

// Deprecated: [0.61.0] Use GRPCClient instead
type Client = GRPCClient

type logsClient struct {
rawClient otlpcollectorlog.LogsServiceClient
}

// NewClient returns a new Client connected using the given connection.
func NewClient(cc *grpc.ClientConn) Client {
func NewClient(cc *grpc.ClientConn) GRPCClient {
return &logsClient{rawClient: otlpcollectorlog.NewLogsServiceClient(cc)}
}

Expand All @@ -140,22 +143,25 @@ func (c *logsClient) Export(ctx context.Context, request Request, opts ...grpc.C
return Response{orig: rsp}, err
}

// Server is the server API for OTLP gRPC LogsService service.
type Server interface {
// GRPCServer is the server API for OTLP gRPC LogsService service.
type GRPCServer interface {
// Export is called every time a new request is received.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(context.Context, Request) (Response, error)
}

// Deprecated: [0.61.0] Use GRPCServer instead
type Server = GRPCServer

// RegisterServer registers the Server to the grpc.Server.
func RegisterServer(s *grpc.Server, srv Server) {
func RegisterServer(s *grpc.Server, srv GRPCServer) {
otlpcollectorlog.RegisterLogsServiceServer(s, &rawLogsServer{srv: srv})
}

type rawLogsServer struct {
srv Server
srv GRPCServer
}

func (s rawLogsServer) Export(ctx context.Context, request *otlpcollectorlog.ExportLogsServiceRequest) (*otlpcollectorlog.ExportLogsServiceResponse, error) {
Expand Down
20 changes: 13 additions & 7 deletions pdata/pmetric/pmetricotlp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,26 @@ func (mr Request) Metrics() pmetric.Metrics {
return pmetric.Metrics(internal.NewMetrics(mr.orig))
}

// Client is the client API for OTLP-GRPC Metrics service.
// GRPCClient is the client API for OTLP-GRPC Metrics service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type Client interface {
type GRPCClient interface {
// Export pmetric.Metrics to the server.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(ctx context.Context, request Request, opts ...grpc.CallOption) (Response, error)
}

// Deprecated: [0.61.0] Use GRPCClient instead
type Client = GRPCClient

type metricsClient struct {
rawClient otlpcollectormetrics.MetricsServiceClient
}

// NewClient returns a new Client connected using the given connection.
func NewClient(cc *grpc.ClientConn) Client {
func NewClient(cc *grpc.ClientConn) GRPCClient {
return &metricsClient{rawClient: otlpcollectormetrics.NewMetricsServiceClient(cc)}
}

Expand All @@ -136,17 +139,20 @@ func (c *metricsClient) Export(ctx context.Context, request Request, opts ...grp
return Response{orig: rsp}, err
}

// Server is the server API for OTLP gRPC MetricsService service.
type Server interface {
// GRPCServer is the server API for OTLP gRPC MetricsService service.
type GRPCServer interface {
// Export is called every time a new request is received.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(context.Context, Request) (Response, error)
}

// RegisterServer registers the Server to the grpc.Server.
func RegisterServer(s *grpc.Server, srv Server) {
// Deprecated: [0.61.0] Use GRPCServer instead
type Server = GRPCServer

// RegisterServer registers the GRPCServer to the grpc.Server.
func RegisterServer(s *grpc.Server, srv GRPCServer) {
otlpcollectormetrics.RegisterMetricsServiceServer(s, &rawMetricsServer{srv: srv})
}

Expand Down
22 changes: 14 additions & 8 deletions pdata/ptrace/ptraceotlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,26 @@ func (tr Request) Traces() ptrace.Traces {
return ptrace.Traces(internal.NewTraces(tr.orig))
}

// Client is the client API for OTLP-GRPC Traces service.
// GRPCClient is the client API for OTLP-GRPC Traces service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type Client interface {
type GRPCClient interface {
// Export ptrace.Traces to the server.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(ctx context.Context, request Request, opts ...grpc.CallOption) (Response, error)
}

// Deprecated: [0.61.0] Use GRPCClient instead
type Client = GRPCClient

type tracesClient struct {
rawClient otlpcollectortrace.TraceServiceClient
}

// NewClient returns a new Client connected using the given connection.
func NewClient(cc *grpc.ClientConn) Client {
func NewClient(cc *grpc.ClientConn) GRPCClient {
return &tracesClient{rawClient: otlpcollectortrace.NewTraceServiceClient(cc)}
}

Expand All @@ -141,22 +144,25 @@ func (c *tracesClient) Export(ctx context.Context, request Request, opts ...grpc
return Response{orig: rsp}, err
}

// Server is the server API for OTLP gRPC TracesService service.
type Server interface {
// GRPCServer is the server API for OTLP gRPC TracesService service.
type GRPCServer interface {
// Export is called every time a new request is received.
//
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(context.Context, Request) (Response, error)
}

// RegisterServer registers the Server to the grpc.Server.
func RegisterServer(s *grpc.Server, srv Server) {
// Deprecated: [0.61.0] Use GRPCServer instead
type Server = GRPCServer

// RegisterServer registers the GRPCServer to the grpc.Server.
func RegisterServer(s *grpc.Server, srv GRPCServer) {
otlpcollectortrace.RegisterTraceServiceServer(s, &rawTracesServer{srv: srv})
}

type rawTracesServer struct {
srv Server
srv GRPCServer
}

func (s rawTracesServer) Export(ctx context.Context, request *otlpcollectortrace.ExportTraceServiceRequest) (*otlpcollectortrace.ExportTraceServiceResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/internal/logs/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestExport_ErrorConsumer(t *testing.T) {
assert.Equal(t, plogotlp.Response{}, resp)
}

func makeLogsServiceClient(t *testing.T, lc consumer.Logs) plogotlp.Client {
func makeLogsServiceClient(t *testing.T, lc consumer.Logs) plogotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, lc)
cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
require.NoError(t, err, "Failed to create the TraceServiceClient: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/internal/metrics/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestExport_ErrorConsumer(t *testing.T) {
assert.Equal(t, pmetricotlp.Response{}, resp)
}

func makeMetricsServiceClient(t *testing.T, mc consumer.Metrics) pmetricotlp.Client {
func makeMetricsServiceClient(t *testing.T, mc consumer.Metrics) pmetricotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, mc)

cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/internal/trace/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestExport_ErrorConsumer(t *testing.T) {
assert.Equal(t, ptraceotlp.Response{}, resp)
}

func makeTraceServiceClient(t *testing.T, tc consumer.Traces) ptraceotlp.Client {
func makeTraceServiceClient(t *testing.T, tc consumer.Traces) ptraceotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, tc)
cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
require.NoError(t, err, "Failed to create the TraceServiceClient: %v", err)
Expand Down

0 comments on commit 1c217b3

Please sign in to comment.