Skip to content

Commit

Permalink
Remove usage of LogRecord.Name field (#4804)
Browse files Browse the repository at this point in the history
The LogRecord Name field [is removed](open-telemetry/opentelemetry-specification#2271) from the specification and is [going to be removed](open-telemetry/opentelemetry-proto#357) from the OTLP.
  • Loading branch information
tigrannajaryan authored Feb 8, 2022
1 parent b1d41f0 commit 18fb011
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
3 changes: 0 additions & 3 deletions internal/testdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func GenerateLogsTwoLogRecordsSameResourceOneDifferent() pdata.Logs {
return ld
}
func fillLogOne(log pdata.LogRecord) {
log.SetName("logA")
log.SetTimestamp(TestLogTimestamp)
log.SetDroppedAttributesCount(1)
log.SetSeverityNumber(pdata.SeverityNumberINFO)
Expand All @@ -94,7 +93,6 @@ func fillLogOne(log pdata.LogRecord) {
}

func fillLogTwo(log pdata.LogRecord) {
log.SetName("logB")
log.SetTimestamp(TestLogTimestamp)
log.SetDroppedAttributesCount(1)
log.SetSeverityNumber(pdata.SeverityNumberINFO)
Expand All @@ -108,7 +106,6 @@ func fillLogTwo(log pdata.LogRecord) {
}

func fillLogThree(log pdata.LogRecord) {
log.SetName("logC")
log.SetTimestamp(TestLogTimestamp)
log.SetDroppedAttributesCount(1)
log.SetSeverityNumber(pdata.SeverityNumberWARN)
Expand Down
4 changes: 2 additions & 2 deletions model/otlp/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ var logsOTLP = func() pdata.Logs {
il := rl.InstrumentationLibraryLogs().AppendEmpty()
il.InstrumentationLibrary().SetName("name")
il.InstrumentationLibrary().SetVersion("version")
il.LogRecords().AppendEmpty().SetName("testMetric")
il.LogRecords().AppendEmpty().SetSeverityText("Error")
return ld
}()

var logsJSON = `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"testHost"}}]},"instrumentationLibraryLogs":[{"instrumentationLibrary":{"name":"name","version":"version"},"logRecords":[{"name":"testMetric","body":{},"traceId":"","spanId":""}]}]}]}`
var logsJSON = `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"testHost"}}]},"instrumentationLibraryLogs":[{"instrumentationLibrary":{"name":"name","version":"version"},"logRecords":[{"severityText":"Error","body":{},"traceId":"","spanId":""}]}]}]}`

func TestTracesJSON(t *testing.T) {
encoder := NewJSONTracesMarshaler()
Expand Down
3 changes: 1 addition & 2 deletions model/otlp/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestProtobufLogsSizer(t *testing.T) {
sizer := NewProtobufLogsMarshaler().(pdata.LogsSizer)
marshaler := NewProtobufLogsMarshaler()
ld := pdata.NewLogs()
ld.ResourceLogs().AppendEmpty().InstrumentationLibraryLogs().AppendEmpty().LogRecords().AppendEmpty().SetName("foo")
ld.ResourceLogs().AppendEmpty().InstrumentationLibraryLogs().AppendEmpty().LogRecords().AppendEmpty().SetSeverityText("error")

size := sizer.LogsSize(ld)

Expand Down Expand Up @@ -190,7 +190,6 @@ func generateBenchmarkLogs(logsCount int) pdata.Logs {
ilm.LogRecords().EnsureCapacity(logsCount)
for i := 0; i < logsCount; i++ {
im := ilm.LogRecords().AppendEmpty()
im.SetName("test_name")
im.SetTimestamp(endTime)
}
return md
Expand Down
16 changes: 8 additions & 8 deletions processor/batchprocessor/batch_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func TestBatchLogProcessor_ReceivingData(t *testing.T) {
ld := testdata.GenerateLogsManyLogRecordsSameResource(logsPerRequest)
logs := ld.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for logIndex := 0; logIndex < logsPerRequest; logIndex++ {
logs.At(logIndex).SetName(getTestLogName(requestNum, logIndex))
logs.At(logIndex).SetSeverityText(getTestLogSeverityText(requestNum, logIndex))
}
logDataSlice = append(logDataSlice, ld.Clone())
assert.NoError(t, batcher.ConsumeLogs(context.Background(), ld))
Expand All @@ -612,13 +612,13 @@ func TestBatchLogProcessor_ReceivingData(t *testing.T) {

require.Equal(t, requestCount*logsPerRequest, sink.LogRecordCount())
receivedMds := sink.AllLogs()
logsReceivedByName := logsReceivedByName(receivedMds)
logsReceivedBySeverityText := logsReceivedBySeverityText(receivedMds)
for requestNum := 0; requestNum < requestCount; requestNum++ {
logs := logDataSlice[requestNum].ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for logIndex := 0; logIndex < logsPerRequest; logIndex++ {
require.EqualValues(t,
logs.At(logIndex),
logsReceivedByName[getTestLogName(requestNum, logIndex)])
logsReceivedBySeverityText[getTestLogSeverityText(requestNum, logIndex)])
}
}
}
Expand Down Expand Up @@ -763,12 +763,12 @@ func TestBatchLogProcessor_Shutdown(t *testing.T) {
require.Equal(t, 1, len(sink.AllLogs()))
}

func getTestLogName(requestNum, index int) string {
func getTestLogSeverityText(requestNum, index int) string {
return fmt.Sprintf("test-log-int-%d-%d", requestNum, index)
}

func logsReceivedByName(lds []pdata.Logs) map[string]pdata.LogRecord {
logsReceivedByName := map[string]pdata.LogRecord{}
func logsReceivedBySeverityText(lds []pdata.Logs) map[string]pdata.LogRecord {
logsReceivedBySeverityText := map[string]pdata.LogRecord{}
for i := range lds {
ld := lds[i]
rms := ld.ResourceLogs()
Expand All @@ -778,12 +778,12 @@ func logsReceivedByName(lds []pdata.Logs) map[string]pdata.LogRecord {
logs := ilms.At(j).LogRecords()
for k := 0; k < logs.Len(); k++ {
log := logs.At(k)
logsReceivedByName[log.Name()] = log
logsReceivedBySeverityText[log.SeverityText()] = log
}
}
}
}
return logsReceivedByName
return logsReceivedBySeverityText
}

func TestShutdown(t *testing.T) {
Expand Down
50 changes: 25 additions & 25 deletions processor/batchprocessor/splitlogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestSplitLogs(t *testing.T) {
ld := testdata.GenerateLogsManyLogRecordsSameResource(20)
logs := ld.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(0, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(0, i))
}
cp := pdata.NewLogs()
cpLogs := cp.ResourceLogs().AppendEmpty().InstrumentationLibraryLogs().AppendEmpty().LogRecords()
Expand All @@ -61,100 +61,100 @@ func TestSplitLogs(t *testing.T) {
assert.Equal(t, splitSize, split.LogRecordCount())
assert.Equal(t, cp, split)
assert.Equal(t, 15, ld.LogRecordCount())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())

split = splitLogs(splitSize, ld)
assert.Equal(t, 10, ld.LogRecordCount())
assert.Equal(t, "test-log-int-0-5", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-9", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-5", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-9", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())

split = splitLogs(splitSize, ld)
assert.Equal(t, 5, ld.LogRecordCount())
assert.Equal(t, "test-log-int-0-10", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-14", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-10", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-14", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())

split = splitLogs(splitSize, ld)
assert.Equal(t, 5, ld.LogRecordCount())
assert.Equal(t, "test-log-int-0-15", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-19", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-15", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-19", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())
}

func TestSplitLogsMultipleResourceLogs(t *testing.T) {
td := testdata.GenerateLogsManyLogRecordsSameResource(20)
logs := td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(0, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(0, i))
}
// add second index to resource logs
testdata.GenerateLogsManyLogRecordsSameResource(20).
ResourceLogs().At(0).CopyTo(td.ResourceLogs().AppendEmpty())
logs = td.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(1, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(1, i))
}

splitSize := 5
split := splitLogs(splitSize, td)
assert.Equal(t, splitSize, split.LogRecordCount())
assert.Equal(t, 35, td.LogRecordCount())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())
}

func TestSplitLogsMultipleResourceLogs_split_size_greater_than_log_size(t *testing.T) {
td := testdata.GenerateLogsManyLogRecordsSameResource(20)
logs := td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(0, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(0, i))
}
// add second index to resource logs
testdata.GenerateLogsManyLogRecordsSameResource(20).
ResourceLogs().At(0).CopyTo(td.ResourceLogs().AppendEmpty())
logs = td.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(1, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(1, i))
}

splitSize := 25
split := splitLogs(splitSize, td)
assert.Equal(t, splitSize, split.LogRecordCount())
assert.Equal(t, 40-splitSize, td.LogRecordCount())
assert.Equal(t, 1, td.ResourceLogs().Len())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-19", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(19).Name())
assert.Equal(t, "test-log-int-1-0", split.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-1-4", split.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-19", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(19).SeverityText())
assert.Equal(t, "test-log-int-1-0", split.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-1-4", split.ResourceLogs().At(1).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())
}

func TestSplitLogsMultipleILL(t *testing.T) {
td := testdata.GenerateLogsManyLogRecordsSameResource(20)
logs := td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(0, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(0, i))
}
// add second index to ILL
td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).
CopyTo(td.ResourceLogs().At(0).InstrumentationLibraryLogs().AppendEmpty())
logs = td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(1).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(1, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(1, i))
}

// add third index to ILL
td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).
CopyTo(td.ResourceLogs().At(0).InstrumentationLibraryLogs().AppendEmpty())
logs = td.ResourceLogs().At(0).InstrumentationLibraryLogs().At(2).LogRecords()
for i := 0; i < logs.Len(); i++ {
logs.At(i).SetName(getTestLogName(2, i))
logs.At(i).SetSeverityText(getTestLogSeverityText(2, i))
}

splitSize := 40
split := splitLogs(splitSize, td)
assert.Equal(t, splitSize, split.LogRecordCount())
assert.Equal(t, 20, td.LogRecordCount())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).Name())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).Name())
assert.Equal(t, "test-log-int-0-0", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(0).SeverityText())
assert.Equal(t, "test-log-int-0-4", split.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).LogRecords().At(4).SeverityText())
}

func BenchmarkSplitLogs(b *testing.B) {
Expand All @@ -164,7 +164,7 @@ func BenchmarkSplitLogs(b *testing.B) {
testdata.GenerateLogsManyLogRecordsSameResource(20).ResourceLogs().MoveAndAppendTo(md.ResourceLogs())
ms := rms.At(rms.Len() - 1).InstrumentationLibraryLogs().At(0).LogRecords()
for i := 0; i < ms.Len(); i++ {
ms.At(i).SetName(getTestLogName(1, i))
ms.At(i).SetSeverityText(getTestLogSeverityText(1, i))
}
}

Expand Down

0 comments on commit 18fb011

Please sign in to comment.