Skip to content

Commit

Permalink
Remove LogsFromOtlp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigran Najaryan committed Sep 1, 2020
1 parent cf9e4e0 commit 83361dc
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions consumer/pdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Logs struct {
}

// LogsFromOtlp creates the internal Logs representation from the ProtoBuf.
func LogsFromOtlp(orig []*otlplogs.ResourceLogs) Logs {
return Logs{&orig}
func LogsFromInternalRep(logs internal.OtlpLogsWrapper) Logs {
return Logs{logs.Orig}
}

// NewLogs creates a new Logs.
Expand All @@ -58,7 +58,7 @@ func (ld Logs) Clone() Logs {
resourceSpansClones = append(resourceSpansClones,
proto.Clone(resourceSpans).(*otlplogs.ResourceLogs))
}
return LogsFromOtlp(resourceSpansClones)
return Logs{orig: &resourceSpansClones}
}

// LogRecordCount calculates the total number of log records.
Expand Down
13 changes: 7 additions & 6 deletions consumer/pdata/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/internal"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"
)

Expand Down Expand Up @@ -46,26 +47,26 @@ func TestLogRecordCount(t *testing.T) {
}

func TestLogRecordCountWithNils(t *testing.T) {
assert.EqualValues(t, 0, LogsFromOtlp([]*otlplogs.ResourceLogs{nil, {}}).LogRecordCount())
assert.EqualValues(t, 0, LogsFromOtlp([]*otlplogs.ResourceLogs{
assert.EqualValues(t, 0, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{nil, {}})).LogRecordCount())
assert.EqualValues(t, 0, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{
{
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{nil, {}},
},
}).LogRecordCount())
assert.EqualValues(t, 2, LogsFromOtlp([]*otlplogs.ResourceLogs{
})).LogRecordCount())
assert.EqualValues(t, 2, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{
{
InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{
{
Logs: []*otlplogs.LogRecord{nil, {}},
},
},
},
}).LogRecordCount())
})).LogRecordCount())
}

func TestToFromLogProto(t *testing.T) {
otlp := []*otlplogs.ResourceLogs(nil)
td := LogsFromOtlp(otlp)
td := LogsFromInternalRep(internal.LogsFromOtlp(otlp))
assert.EqualValues(t, NewLogs(), td)
assert.EqualValues(t, otlp, *td.orig)
}
5 changes: 3 additions & 2 deletions exporter/fileexporter/file_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal"
"go.opentelemetry.io/collector/internal/data"
collectorlogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
collectormetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/metrics/v1"
Expand Down Expand Up @@ -120,7 +121,7 @@ func TestFileLogsExporterNoErrors(t *testing.T) {
},
},
}
assert.NoError(t, exporter.ConsumeLogs(context.Background(), pdata.LogsFromOtlp(ld)))
assert.NoError(t, exporter.ConsumeLogs(context.Background(), pdata.LogsFromInternalRep(internal.LogsFromOtlp(ld))))
assert.NoError(t, exporter.Shutdown(context.Background()))

var unmarshaler = &jsonpb.Unmarshaler{}
Expand Down Expand Up @@ -211,7 +212,7 @@ func TestFileLogsExporterErrors(t *testing.T) {
exporter := &fileExporter{file: mf}
require.NotNil(t, exporter)

assert.Error(t, exporter.ConsumeLogs(context.Background(), pdata.LogsFromOtlp(ld)))
assert.Error(t, exporter.ConsumeLogs(context.Background(), pdata.LogsFromInternalRep(internal.LogsFromOtlp(ld))))
assert.NoError(t, exporter.Shutdown(context.Background()))
})
}
Expand Down
7 changes: 4 additions & 3 deletions internal/data/testdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal"
otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"
)

Expand Down Expand Up @@ -54,7 +55,7 @@ func generateLogOtlpOneEmptyResourceLogs() []*otlplogs.ResourceLogs {
}

func GenerateLogDataOneEmptyOneNilResourceLogs() pdata.Logs {
return pdata.LogsFromOtlp(generateLogOtlpOneEmptyOneNilResourceLogs())
return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneEmptyOneNilResourceLogs()))

}

Expand Down Expand Up @@ -104,7 +105,7 @@ func generateLogOtlpOneEmptyLogs() []*otlplogs.ResourceLogs {
}

func GenerateLogDataOneEmptyOneNilLogRecord() pdata.Logs {
return pdata.LogsFromOtlp(generateLogOtlpOneEmptyOneNilLogRecord())
return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneEmptyOneNilLogRecord()))
}

func generateLogOtlpOneEmptyOneNilLogRecord() []*otlplogs.ResourceLogs {
Expand Down Expand Up @@ -173,7 +174,7 @@ func generateLogOtlpOneLog() []*otlplogs.ResourceLogs {
}

func GenerateLogDataOneLogOneNil() pdata.Logs {
return pdata.LogsFromOtlp(generateLogOtlpOneLogOneNil())
return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneLogOneNil()))
}

func generateLogOtlpOneLogOneNil() []*otlplogs.ResourceLogs {
Expand Down
2 changes: 1 addition & 1 deletion internal/data/testdata/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestToFromOtlpLog(t *testing.T) {
for i := range allTestCases {
test := allTestCases[i]
t.Run(test.name, func(t *testing.T) {
ld := pdata.LogsFromOtlp(test.otlp)
ld := pdata.LogsFromInternalRep(internal.LogsFromOtlp(test.otlp))
assert.EqualValues(t, test.ld, ld)
otlp := internal.LogsToOtlp(ld.InternalRep())
assert.EqualValues(t, test.otlp, otlp)
Expand Down
4 changes: 4 additions & 0 deletions internal/otlp_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ type OtlpLogsWrapper struct {
func LogsToOtlp(l OtlpLogsWrapper) []*otlplogs.ResourceLogs {
return *l.Orig
}

func LogsFromOtlp(logs []*otlplogs.ResourceLogs) OtlpLogsWrapper {
return OtlpLogsWrapper{Orig: &logs}
}
3 changes: 2 additions & 1 deletion receiver/otlpreceiver/logs/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/collector/client"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal"
collectorlog "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
"go.opentelemetry.io/collector/obsreport"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (r *Receiver) Export(ctx context.Context, req *collectorlog.ExportLogsServi
// We need to ensure that it propagates the receiver name as a tag
ctxWithReceiverName := obsreport.ReceiverContext(ctx, r.instanceName, receiverTransport, receiverTagValue)

ld := pdata.LogsFromOtlp(req.ResourceLogs)
ld := pdata.LogsFromInternalRep(internal.LogsFromOtlp(req.ResourceLogs))
err := r.sendToNextConsumer(ctxWithReceiverName, ld)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion receiver/otlpreceiver/logs/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal"
collectorlog "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/logs/v1"
otlplog "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"
"go.opentelemetry.io/collector/obsreport"
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestExport(t *testing.T) {

// Keep log data to compare the test result against it
// Clone needed because OTLP proto XXX_ fields are altered in the GRPC downstream
traceData := pdata.LogsFromOtlp(resourceLogs).Clone()
traceData := pdata.LogsFromInternalRep(internal.LogsFromOtlp(resourceLogs)).Clone()

req := &collectorlog.ExportLogsServiceRequest{
ResourceLogs: resourceLogs,
Expand Down

0 comments on commit 83361dc

Please sign in to comment.