Skip to content

Commit

Permalink
Add private method to GrpcServer interface, disallow direct implement…
Browse files Browse the repository at this point in the history
…ation (#7029)

Fixes #6966

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jan 27, 2023
1 parent 504a00b commit e520829
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .chloggen/fixgrpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pdata

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add private method to GrpcServer interface, disallow direct implementation

# One or more tracking issues or pull requests related to the change
issues: [6966]
5 changes: 5 additions & 0 deletions pdata/plog/plogotlp/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type GRPCServer interface {
// For performance reasons, it is recommended to keep this RPC
// alive for the entire life of the application.
Export(context.Context, ExportRequest) (ExportResponse, error)

// unexported disallow implementation of the GRPCServer.
unexported()
}

var _ GRPCServer = (*UnimplementedGRPCServer)(nil)
Expand All @@ -74,6 +77,8 @@ func (*UnimplementedGRPCServer) Export(context.Context, ExportRequest) (ExportRe
return ExportResponse{}, status.Errorf(codes.Unimplemented, "method Export not implemented")
}

func (*UnimplementedGRPCServer) unexported() {}

// RegisterGRPCServer registers the Server to the grpc.Server.
func RegisterGRPCServer(s *grpc.Server, srv GRPCServer) {
otlpcollectorlog.RegisterLogsServiceServer(s, &rawLogsServer{srv: srv})
Expand Down
6 changes: 6 additions & 0 deletions pdata/pmetric/pmetricotlp/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ func (c *grpcClient) Export(ctx context.Context, request ExportRequest, opts ...
func (c *grpcClient) unexported() {}

// GRPCServer is the server API for OTLP gRPC MetricsService service.
// Implementations MUST embed UnimplementedGRPCServer.
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, ExportRequest) (ExportResponse, error)

// unexported disallow implementation of the GRPCServer.
unexported()
}

var _ GRPCServer = (*UnimplementedGRPCServer)(nil)
Expand All @@ -73,6 +77,8 @@ func (*UnimplementedGRPCServer) Export(context.Context, ExportRequest) (ExportRe
return ExportResponse{}, status.Errorf(codes.Unimplemented, "method Export not implemented")
}

func (*UnimplementedGRPCServer) unexported() {}

// RegisterGRPCServer registers the GRPCServer to the grpc.Server.
func RegisterGRPCServer(s *grpc.Server, srv GRPCServer) {
otlpcollectormetrics.RegisterMetricsServiceServer(s, &rawMetricsServer{srv: srv})
Expand Down
6 changes: 6 additions & 0 deletions pdata/ptrace/ptraceotlp/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ func (c *grpcClient) Export(ctx context.Context, request ExportRequest, opts ...
func (c *grpcClient) unexported() {}

// GRPCServer is the server API for OTLP gRPC TracesService service.
// Implementations MUST embed UnimplementedGRPCServer.
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, ExportRequest) (ExportResponse, error)

// unexported disallow implementation of the GRPCServer.
unexported()
}

var _ GRPCServer = (*UnimplementedGRPCServer)(nil)
Expand All @@ -74,6 +78,8 @@ func (*UnimplementedGRPCServer) Export(context.Context, ExportRequest) (ExportRe
return ExportResponse{}, status.Errorf(codes.Unimplemented, "method Export not implemented")
}

func (*UnimplementedGRPCServer) unexported() {}

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

0 comments on commit e520829

Please sign in to comment.