-
Notifications
You must be signed in to change notification settings - Fork 2k
Add initial implementation of pdatagrcp #3231
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package pdatagrpc | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "google.golang.org/grpc" | ||
|
|
||
| "go.opentelemetry.io/collector/consumer/pdata" | ||
| "go.opentelemetry.io/collector/internal" | ||
| otlpcollectorlogs "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1" | ||
| ) | ||
|
|
||
| // TODO: Consider to add `LogsRequest` and `LogsResponse` | ||
|
|
||
| // LogsClient 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 LogsClient interface { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need an interface? I assume there will be only one implementation ever. Should we simply, delete the interface and just have the struct?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can either expose the struct or the interface. I think exposing the interface is more future proof, because we can offer alternative implementations in the future. Not a big thing though, so if you feel strong I can change.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a strong opinion. Works either way. |
||
| // Export pdata.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, in pdata.Logs, opts ...grpc.CallOption) (interface{}, error) | ||
| } | ||
|
|
||
| type logsClient struct { | ||
| rawClient otlpcollectorlogs.LogsServiceClient | ||
| } | ||
|
|
||
| // NewLogsClient returns a new LogsClient connected using the given connection. | ||
| func NewLogsClient(cc *grpc.ClientConn) LogsClient { | ||
| return &logsClient{rawClient: otlpcollectorlogs.NewLogsServiceClient(cc)} | ||
| } | ||
|
|
||
| func (c *logsClient) Export(ctx context.Context, in pdata.Logs, opts ...grpc.CallOption) (interface{}, error) { | ||
| return c.rawClient.Export(ctx, internal.LogsToOtlp(in.InternalRep()), opts...) | ||
| } | ||
|
|
||
| // LogsServer is the server API for OTLP gRPC LogsService service. | ||
| type LogsServer 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, pdata.Logs) (interface{}, error) | ||
| } | ||
|
|
||
| // RegisterLogsServer registers the LogsServer to the grpc.Server. | ||
| func RegisterLogsServer(s *grpc.Server, srv LogsServer) { | ||
| otlpcollectorlogs.RegisterLogsServiceServer(s, &rawLogsServer{srv: srv}) | ||
| } | ||
|
|
||
| type rawLogsServer struct { | ||
| srv LogsServer | ||
| } | ||
|
|
||
| func (s rawLogsServer) Export(ctx context.Context, request *otlpcollectorlogs.ExportLogsServiceRequest) (*otlpcollectorlogs.ExportLogsServiceResponse, error) { | ||
| _, err := s.srv.Export(ctx, pdata.LogsFromInternalRep(internal.LogsFromOtlp(request))) | ||
| return &otlpcollectorlogs.ExportLogsServiceResponse{}, err | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.