Skip to content

Commit

Permalink
[exporter/loki] Remove usage of LogRecord Name field (#7565)
Browse files Browse the repository at this point in the history
Fixes #7555

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored Feb 4, 2022
1 parent 69270ed commit dad3d22
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
5 changes: 2 additions & 3 deletions exporter/lokiexporter/encode_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func exampleLog() (pdata.LogRecord, pdata.Resource) {

buffer := pdata.NewLogRecord()
buffer.Body().SetStringVal("Example log")
buffer.SetName("name")
buffer.SetSeverityText("error")
buffer.Attributes().Insert("attr1", pdata.NewAttributeValueString("1"))
buffer.Attributes().Insert("attr2", pdata.NewAttributeValueString("2"))
Expand All @@ -39,15 +38,15 @@ func exampleLog() (pdata.LogRecord, pdata.Resource) {
}

func TestConvertWithStringBody(t *testing.T) {
in := `{"name":"name","body":"Example log","traceid":"01020304000000000000000000000000","spanid":"0506070800000000","severity":"error","attributes":{"attr1":"1","attr2":"2"},"resources":{"host.name":"something"}}`
in := `{"body":"Example log","traceid":"01020304000000000000000000000000","spanid":"0506070800000000","severity":"error","attributes":{"attr1":"1","attr2":"2"},"resources":{"host.name":"something"}}`

out, err := encodeJSON(exampleLog())
assert.NoError(t, err)
assert.Equal(t, in, out)
}

func TestConvertWithMapBody(t *testing.T) {
in := `{"name":"name","body":{"key1":"value","key2":"value"},"traceid":"01020304000000000000000000000000","spanid":"0506070800000000","severity":"error","attributes":{"attr1":"1","attr2":"2"},"resources":{"host.name":"something"}}`
in := `{"body":{"key1":"value","key2":"value"},"traceid":"01020304000000000000000000000000","spanid":"0506070800000000","severity":"error","attributes":{"attr1":"1","attr2":"2"},"resources":{"host.name":"something"}}`

log, resource := exampleLog()
mapVal := pdata.NewAttributeValueMap()
Expand Down
5 changes: 0 additions & 5 deletions exporter/lokiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ func (l *lokiExporter) convertAttributesToLabels(attributes pdata.AttributeMap,
func (l *lokiExporter) convertLogBodyToEntry(lr pdata.LogRecord, res pdata.Resource) (*logproto.Entry, error) {
var b strings.Builder

if len(lr.Name()) > 0 {
b.WriteString("name=")
b.WriteString(lr.Name())
b.WriteRune(' ')
}
if len(lr.SeverityText()) > 0 {
b.WriteString("severity=")
b.WriteString(lr.SeverityText())
Expand Down
3 changes: 1 addition & 2 deletions exporter/lokiexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ func TestExporter_convertLogBodyToEntry(t *testing.T) {
res.Attributes().Insert("pod.name", pdata.NewAttributeValueString("something123"))

lr := pdata.NewLogRecord()
lr.SetName("Checkout")
lr.Body().SetStringVal("Payment succeeded")
lr.SetTraceID(pdata.NewTraceID([16]byte{1, 2, 3, 4}))
lr.SetSpanID(pdata.NewSpanID([8]byte{5, 6, 7, 8}))
Expand All @@ -498,7 +497,7 @@ func TestExporter_convertLogBodyToEntry(t *testing.T) {

expEntry := &logproto.Entry{
Timestamp: time.Unix(0, int64(lr.Timestamp())),
Line: "name=Checkout severity=DEBUG severityN=5 traceID=01020304000000000000000000000000 spanID=0506070800000000 host.name=something Payment succeeded",
Line: "severity=DEBUG severityN=5 traceID=01020304000000000000000000000000 spanID=0506070800000000 host.name=something Payment succeeded",
}
require.NotNil(t, entry)
require.Equal(t, expEntry, entry)
Expand Down

0 comments on commit dad3d22

Please sign in to comment.