Skip to content

Commit

Permalink
fix: tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nityanandagohain committed Oct 16, 2023
1 parent fefd27a commit 4e43c2d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
5 changes: 4 additions & 1 deletion receiver/httpreceiver/bodyparser/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ func (l *Default) Parse(body []byte) (plog.Logs, int) {
// split by newline and return
// TODO: add configuration for multiline
ld := plog.NewLogs()
data := string(body)
if data == "" {
return ld, 0
}
rl := ld.ResourceLogs().AppendEmpty()
sl := rl.ScopeLogs().AppendEmpty()
data := string(body)
loglines := strings.Split(data, "\n")
for _, log := range loglines {
sl.LogRecords().AppendEmpty().Body().SetStr(log)
Expand Down
8 changes: 8 additions & 0 deletions receiver/httpreceiver/bodyparser/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func TestDefaultParse(t *testing.T) {
return ld
},
},
{
name: "Test 3 - empty",
PayLoad: "",
Logs: func() plog.Logs {
ld := plog.NewLogs()
return ld
},
},
}

for _, tt := range tests {
Expand Down
22 changes: 13 additions & 9 deletions receiver/httpreceiver/bodyparser/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,24 @@ func (l *Heroku) Parse(body []byte) (plog.Logs, int) {
ld := plog.NewLogs()
for resource, logbodies := range resdata {
rl := ld.ResourceLogs().AppendEmpty()
rl.Resource().Attributes().EnsureCapacity(5)
rl.Resource().Attributes().PutStr("priority", resource.priority)
rl.Resource().Attributes().PutStr("version", resource.version)
rl.Resource().Attributes().PutStr("hostname", resource.hostname)
rl.Resource().Attributes().PutStr("appname", resource.appname)
rl.Resource().Attributes().PutStr("procid", resource.procid)
if resource != (rAttrs{}) {
rl.Resource().Attributes().EnsureCapacity(5)
rl.Resource().Attributes().PutStr("priority", resource.priority)
rl.Resource().Attributes().PutStr("version", resource.version)
rl.Resource().Attributes().PutStr("hostname", resource.hostname)
rl.Resource().Attributes().PutStr("appname", resource.appname)
rl.Resource().Attributes().PutStr("procid", resource.procid)
}

sl := rl.ScopeLogs().AppendEmpty()
for _, log := range logbodies {
rec := sl.LogRecords().AppendEmpty()
rec.Body().SetStr(log.body)
rec.Attributes().EnsureCapacity(2)
rec.Attributes().PutStr("timestamp", log.timestamp)
rec.Attributes().PutStr("msgid", log.msgid)
if log.timestamp != "" {
rec.Attributes().EnsureCapacity(2)
rec.Attributes().PutStr("timestamp", log.timestamp)
rec.Attributes().PutStr("msgid", log.msgid)
}
}
}
return ld, len(loglines)
Expand Down
20 changes: 20 additions & 0 deletions receiver/httpreceiver/bodyparser/heroku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ func TestHerokuParse(t *testing.T) {
return ld
},
},
{
name: "Test 3 - empty",
PayLoad: ``,
Logs: func() plog.Logs {
ld := plog.NewLogs()
return ld
},
},
{
name: "Test 4 - wrong pattern",
PayLoad: `28 Setting up own telemetry...`,
Logs: func() plog.Logs {
ld := plog.NewLogs()
rl := ld.ResourceLogs().AppendEmpty()
sl := rl.ScopeLogs().AppendEmpty()
log := sl.LogRecords().AppendEmpty()
log.Body().SetStr("Setting up own telemetry...")
return ld
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 4e43c2d

Please sign in to comment.