Skip to content

Commit

Permalink
Move internal data wrappers to model/internal
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jun 29, 2021
1 parent 6986310 commit 74dde9c
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions model/otlp/json_marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/gogo/protobuf/jsonpb"

"go.opentelemetry.io/collector/internal"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -48,18 +48,18 @@ func newJSONMarshaler() *jsonMarshaler {

func (e *jsonMarshaler) MarshalLogs(ld pdata.Logs) ([]byte, error) {
buf := bytes.Buffer{}
err := e.delegate.Marshal(&buf, internal.LogsToOtlp(ld.InternalRep()))
err := e.delegate.Marshal(&buf, internal2.LogsToOtlp(ld.InternalRep()))
return buf.Bytes(), err
}

func (e *jsonMarshaler) MarshalMetrics(md pdata.Metrics) ([]byte, error) {
buf := bytes.Buffer{}
err := e.delegate.Marshal(&buf, internal.MetricsToOtlp(md.InternalRep()))
err := e.delegate.Marshal(&buf, internal2.MetricsToOtlp(md.InternalRep()))
return buf.Bytes(), err
}

func (e *jsonMarshaler) MarshalTraces(td pdata.Traces) ([]byte, error) {
buf := bytes.Buffer{}
err := e.delegate.Marshal(&buf, internal.TracesToOtlp(td.InternalRep()))
err := e.delegate.Marshal(&buf, internal2.TracesToOtlp(td.InternalRep()))
return buf.Bytes(), err
}
8 changes: 4 additions & 4 deletions model/otlp/json_unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

"github.com/gogo/protobuf/jsonpb"

"go.opentelemetry.io/collector/internal"
otlpcollectorlogs "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlpcollectormetrics "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1"
otlpcollectortrace "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -52,17 +52,17 @@ func newJSONUnmarshaler() *jsonUnmarshaler {
func (d *jsonUnmarshaler) UnmarshalLogs(buf []byte) (pdata.Logs, error) {
ld := &otlpcollectorlogs.ExportLogsServiceRequest{}
err := d.delegate.Unmarshal(bytes.NewReader(buf), ld)
return pdata.LogsFromInternalRep(internal.LogsFromOtlp(ld)), err
return pdata.LogsFromInternalRep(internal2.LogsFromOtlp(ld)), err
}

func (d *jsonUnmarshaler) UnmarshalMetrics(buf []byte) (pdata.Metrics, error) {
md := &otlpcollectormetrics.ExportMetricsServiceRequest{}
err := d.delegate.Unmarshal(bytes.NewReader(buf), md)
return pdata.MetricsFromInternalRep(internal.MetricsFromOtlp(md)), err
return pdata.MetricsFromInternalRep(internal2.MetricsFromOtlp(md)), err
}

func (d *jsonUnmarshaler) UnmarshalTraces(buf []byte) (pdata.Traces, error) {
td := &otlpcollectortrace.ExportTraceServiceRequest{}
err := d.delegate.Unmarshal(bytes.NewReader(buf), td)
return pdata.TracesFromInternalRep(internal.TracesFromOtlp(td)), err
return pdata.TracesFromInternalRep(internal2.TracesFromOtlp(td)), err
}
8 changes: 4 additions & 4 deletions model/otlp/pb_marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package otlp

import (
"go.opentelemetry.io/collector/internal"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand All @@ -41,13 +41,13 @@ func newPbMarshaler() *pbMarshaler {
}

func (e *pbMarshaler) MarshalLogs(ld pdata.Logs) ([]byte, error) {
return internal.LogsToOtlp(ld.InternalRep()).Marshal()
return internal2.LogsToOtlp(ld.InternalRep()).Marshal()
}

func (e *pbMarshaler) MarshalMetrics(md pdata.Metrics) ([]byte, error) {
return internal.MetricsToOtlp(md.InternalRep()).Marshal()
return internal2.MetricsToOtlp(md.InternalRep()).Marshal()
}

func (e *pbMarshaler) MarshalTraces(td pdata.Traces) ([]byte, error) {
return internal.TracesToOtlp(td.InternalRep()).Marshal()
return internal2.TracesToOtlp(td.InternalRep()).Marshal()
}
10 changes: 5 additions & 5 deletions model/otlp/pb_unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package otlp

import (
"go.opentelemetry.io/collector/internal"
otlpcollectorlogs "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlpcollectormetrics "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1"
otlpcollectortrace "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -46,20 +46,20 @@ func newPbUnmarshaler() *pbUnmarshaler {
func (d *pbUnmarshaler) UnmarshalLogs(buf []byte) (pdata.Logs, error) {
ld := &otlpcollectorlogs.ExportLogsServiceRequest{}
err := ld.Unmarshal(buf)
return pdata.LogsFromInternalRep(internal.LogsFromOtlp(ld)), err
return pdata.LogsFromInternalRep(internal2.LogsFromOtlp(ld)), err
}

func (d *pbUnmarshaler) UnmarshalMetrics(buf []byte) (pdata.Metrics, error) {
md := &otlpcollectormetrics.ExportMetricsServiceRequest{}
err := md.Unmarshal(buf)
return pdata.MetricsFromInternalRep(internal.MetricsFromOtlp(md)), err
return pdata.MetricsFromInternalRep(internal2.MetricsFromOtlp(md)), err
}

func (d *pbUnmarshaler) UnmarshalTraces(buf []byte) (pdata.Traces, error) {
td := &otlpcollectortrace.ExportTraceServiceRequest{}
err := td.Unmarshal(buf)
if err == nil {
internal.TracesCompatibilityChanges(td)
internal2.TracesCompatibilityChanges(td)
}
return pdata.TracesFromInternalRep(internal.TracesFromOtlp(td)), err
return pdata.TracesFromInternalRep(internal2.TracesFromOtlp(td)), err
}
6 changes: 3 additions & 3 deletions model/otlpgrpc/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"google.golang.org/grpc"

"go.opentelemetry.io/collector/internal"
otlpcollectorlogs "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func NewLogsClient(cc *grpc.ClientConn) LogsClient {
}

func (c *logsClient) Export(ctx context.Context, in pdata.Logs, opts ...grpc.CallOption) (LogsResponse, error) {
rsp, err := c.rawClient.Export(ctx, internal.LogsToOtlp(in.InternalRep()), opts...)
rsp, err := c.rawClient.Export(ctx, internal2.LogsToOtlp(in.InternalRep()), opts...)
return LogsResponse{orig: rsp}, err
}

Expand All @@ -80,6 +80,6 @@ type rawLogsServer struct {
}

func (s rawLogsServer) Export(ctx context.Context, request *otlpcollectorlogs.ExportLogsServiceRequest) (*otlpcollectorlogs.ExportLogsServiceResponse, error) {
rsp, err := s.srv.Export(ctx, pdata.LogsFromInternalRep(internal.LogsFromOtlp(request)))
rsp, err := s.srv.Export(ctx, pdata.LogsFromInternalRep(internal2.LogsFromOtlp(request)))
return rsp.orig, err
}
6 changes: 3 additions & 3 deletions model/otlpgrpc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"google.golang.org/grpc"

"go.opentelemetry.io/collector/internal"
otlpcollectormetrics "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func NewMetricsClient(cc *grpc.ClientConn) MetricsClient {
}

func (c *metricsClient) Export(ctx context.Context, in pdata.Metrics, opts ...grpc.CallOption) (MetricsResponse, error) {
rsp, err := c.rawClient.Export(ctx, internal.MetricsToOtlp(in.InternalRep()), opts...)
rsp, err := c.rawClient.Export(ctx, internal2.MetricsToOtlp(in.InternalRep()), opts...)
return MetricsResponse{orig: rsp}, err
}

Expand All @@ -80,6 +80,6 @@ type rawMetricsServer struct {
}

func (s rawMetricsServer) Export(ctx context.Context, request *otlpcollectormetrics.ExportMetricsServiceRequest) (*otlpcollectormetrics.ExportMetricsServiceResponse, error) {
rsp, err := s.srv.Export(ctx, pdata.MetricsFromInternalRep(internal.MetricsFromOtlp(request)))
rsp, err := s.srv.Export(ctx, pdata.MetricsFromInternalRep(internal2.MetricsFromOtlp(request)))
return rsp.orig, err
}
8 changes: 4 additions & 4 deletions model/otlpgrpc/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"google.golang.org/grpc"

"go.opentelemetry.io/collector/internal"
otlpcollectortraces "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
"go.opentelemetry.io/collector/model/pdata"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ func NewTracesClient(cc *grpc.ClientConn) TracesClient {

// Export implements the TracesClient interface.
func (c *tracesClient) Export(ctx context.Context, in pdata.Traces, opts ...grpc.CallOption) (TracesResponse, error) {
rsp, err := c.rawClient.Export(ctx, internal.TracesToOtlp(in.InternalRep()), opts...)
rsp, err := c.rawClient.Export(ctx, internal2.TracesToOtlp(in.InternalRep()), opts...)
return TracesResponse{orig: rsp}, err
}

Expand All @@ -81,7 +81,7 @@ type rawTracesServer struct {
}

func (s rawTracesServer) Export(ctx context.Context, request *otlpcollectortraces.ExportTraceServiceRequest) (*otlpcollectortraces.ExportTraceServiceResponse, error) {
internal.TracesCompatibilityChanges(request)
rsp, err := s.srv.Export(ctx, pdata.TracesFromInternalRep(internal.TracesFromOtlp(request)))
internal2.TracesCompatibilityChanges(request)
rsp, err := s.srv.Export(ctx, pdata.TracesFromInternalRep(internal2.TracesFromOtlp(request)))
return rsp.orig, err
}
10 changes: 5 additions & 5 deletions model/pdata/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package pdata

import (
"go.opentelemetry.io/collector/internal"
otlpcollectorlog "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlplogs "go.opentelemetry.io/collector/internal/data/protogen/logs/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
)

// LogsMarshaler marshals pdata.Logs into bytes.
Expand Down Expand Up @@ -52,8 +52,8 @@ func NewLogs() Logs {
// LogsFromInternalRep creates the internal Logs representation from the ProtoBuf. Should
// not be used outside this module. This is intended to be used only by OTLP exporter and
// File exporter, which legitimately need to work with OTLP Protobuf structs.
func LogsFromInternalRep(logs internal.LogsWrapper) Logs {
return Logs{orig: internal.LogsToOtlp(logs)}
func LogsFromInternalRep(logs internal2.LogsWrapper) Logs {
return Logs{orig: internal2.LogsToOtlp(logs)}
}

// LogsFromOtlpProtoBytes converts OTLP Collector ExportLogsServiceRequest
Expand All @@ -71,8 +71,8 @@ func LogsFromOtlpProtoBytes(data []byte) (Logs, error) {
// InternalRep returns internal representation of the logs. Should not be used outside
// this module. This is intended to be used only by OTLP exporter and File exporter,
// which legitimately need to work with OTLP Protobuf structs.
func (ld Logs) InternalRep() internal.LogsWrapper {
return internal.LogsFromOtlp(ld.orig)
func (ld Logs) InternalRep() internal2.LogsWrapper {
return internal2.LogsFromOtlp(ld.orig)
}

// ToOtlpProtoBytes converts this Logs to the OTLP Collector ExportLogsServiceRequest
Expand Down
4 changes: 2 additions & 2 deletions model/pdata/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/internal"
otlpcollectorlog "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlplogs "go.opentelemetry.io/collector/internal/data/protogen/logs/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
)

func TestLogRecordCount(t *testing.T) {
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestLogRecordCountWithEmpty(t *testing.T) {
}

func TestToFromLogProto(t *testing.T) {
wrapper := internal.LogsFromOtlp(&otlpcollectorlog.ExportLogsServiceRequest{})
wrapper := internal2.LogsFromOtlp(&otlpcollectorlog.ExportLogsServiceRequest{})
ld := LogsFromInternalRep(wrapper)
assert.EqualValues(t, NewLogs(), ld)
assert.EqualValues(t, &otlpcollectorlog.ExportLogsServiceRequest{}, ld.orig)
Expand Down
10 changes: 5 additions & 5 deletions model/pdata/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package pdata

import (
"go.opentelemetry.io/collector/internal"
otlpcollectormetrics "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1"
otlpmetrics "go.opentelemetry.io/collector/internal/data/protogen/metrics/v1"
internal2 "go.opentelemetry.io/collector/model/internal"
)

// MetricsMarshaler marshals pdata.Metrics into bytes.
Expand Down Expand Up @@ -50,8 +50,8 @@ func NewMetrics() Metrics {

// MetricsFromInternalRep creates Metrics from the internal representation.
// Should not be used outside this module.
func MetricsFromInternalRep(wrapper internal.MetricsWrapper) Metrics {
return Metrics{orig: internal.MetricsToOtlp(wrapper)}
func MetricsFromInternalRep(wrapper internal2.MetricsWrapper) Metrics {
return Metrics{orig: internal2.MetricsToOtlp(wrapper)}
}

// MetricsFromOtlpProtoBytes converts the OTLP Collector ExportMetricsServiceRequest
Expand All @@ -68,8 +68,8 @@ func MetricsFromOtlpProtoBytes(data []byte) (Metrics, error) {

// InternalRep returns internal representation of the Metrics.
// Should not be used outside this module.
func (md Metrics) InternalRep() internal.MetricsWrapper {
return internal.MetricsFromOtlp(md.orig)
func (md Metrics) InternalRep() internal2.MetricsWrapper {
return internal2.MetricsFromOtlp(md.orig)
}

// ToOtlpProtoBytes converts this Metrics to the OTLP Collector ExportMetricsServiceRequest
Expand Down
Loading

0 comments on commit 74dde9c

Please sign in to comment.