From 18fb01178b794a0b8e2f3b0e48ab6f81056ae2b5 Mon Sep 17 00:00:00 2001 From: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com> Date: Tue, 8 Feb 2022 11:56:16 -0500 Subject: [PATCH] Remove usage of LogRecord.Name field (#4804) The LogRecord Name field [is removed](https://github.com/open-telemetry/opentelemetry-specification/pull/2271) from the specification and is [going to be removed](https://github.com/open-telemetry/opentelemetry-proto/pull/357) from the OTLP. --- internal/testdata/log.go | 3 -- model/otlp/json_test.go | 4 +- model/otlp/pb_test.go | 3 +- .../batchprocessor/batch_processor_test.go | 16 +++--- processor/batchprocessor/splitlogs_test.go | 50 +++++++++---------- 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/internal/testdata/log.go b/internal/testdata/log.go index e26ddbc61b4..4be6279da6a 100644 --- a/internal/testdata/log.go +++ b/internal/testdata/log.go @@ -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) @@ -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) @@ -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) diff --git a/model/otlp/json_test.go b/model/otlp/json_test.go index 541b1f2a814..cde75064a37 100644 --- a/model/otlp/json_test.go +++ b/model/otlp/json_test.go @@ -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() diff --git a/model/otlp/pb_test.go b/model/otlp/pb_test.go index ed4a9ddf304..a9a88fd4b98 100644 --- a/model/otlp/pb_test.go +++ b/model/otlp/pb_test.go @@ -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) @@ -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 diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index 53813ecd587..f7b01f60ed2 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_test.go @@ -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)) @@ -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)]) } } } @@ -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() @@ -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) { diff --git a/processor/batchprocessor/splitlogs_test.go b/processor/batchprocessor/splitlogs_test.go index dd91b63f9b8..2bec917935b 100644 --- a/processor/batchprocessor/splitlogs_test.go +++ b/processor/batchprocessor/splitlogs_test.go @@ -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() @@ -61,59 +61,59 @@ 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 @@ -121,24 +121,24 @@ func TestSplitLogsMultipleResourceLogs_split_size_greater_than_log_size(t *testi 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 @@ -146,15 +146,15 @@ func TestSplitLogsMultipleILL(t *testing.T) { 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) { @@ -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)) } }