Skip to content

Commit

Permalink
fix: minor fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nityanandagohain committed Oct 16, 2023
1 parent c8b43e2 commit 86d1386
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions receiver/httpreceiver/bodyparser/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Default struct {
}

func (l *Default) Parse(body []byte) plog.Logs {
func (l *Default) Parse(body []byte) (plog.Logs, int) {
// split by newline and return
// TODO: add configuration for multiline
ld := plog.NewLogs()
Expand All @@ -20,5 +20,5 @@ func (l *Default) Parse(body []byte) plog.Logs {
for _, log := range loglines {
sl.LogRecords().AppendEmpty().Body().SetStr(log)
}
return ld
return ld, len(loglines)
}
2 changes: 1 addition & 1 deletion receiver/httpreceiver/bodyparser/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDefaultParse(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := d.Parse([]byte(tt.PayLoad))
res, _ := d.Parse([]byte(tt.PayLoad))
logs := tt.Logs()
assert.Equal(t, logs, res)
})
Expand Down
4 changes: 2 additions & 2 deletions receiver/httpreceiver/bodyparser/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import "go.opentelemetry.io/collector/pdata/plog"
type GCloud struct {
}

func (l *GCloud) Parse(body []byte) plog.Logs {
return plog.Logs{}
func (l *GCloud) Parse(body []byte) (plog.Logs, int) {
return plog.Logs{}, 0
}
4 changes: 2 additions & 2 deletions receiver/httpreceiver/bodyparser/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type log struct {
body string
}

func (l *Heroku) Parse(body []byte) plog.Logs {
func (l *Heroku) Parse(body []byte) (plog.Logs, int) {
data := string(body)

loglines := octectCountingSplitter(data)
Expand Down Expand Up @@ -91,7 +91,7 @@ func (l *Heroku) Parse(body []byte) plog.Logs {
rec.Attributes().PutStr("msgid", log.msgid)
}
}
return ld
return ld, len(loglines)

}

Expand Down
3 changes: 2 additions & 1 deletion receiver/httpreceiver/bodyparser/heroku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestHerokuParse(t *testing.T) {
name string
PayLoad string
Logs func() plog.Logs
count int
isError bool
}{
{
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestHerokuParse(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := d.Parse([]byte(tt.PayLoad))
res, _ := d.Parse([]byte(tt.PayLoad))
logs := tt.Logs()
assert.Equal(t, logs, res)
})
Expand Down
2 changes: 1 addition & 1 deletion receiver/httpreceiver/bodyparser/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bodyparser
import "go.opentelemetry.io/collector/pdata/plog"

type Parser interface {
Parse(body []byte) plog.Logs
Parse(body []byte) (plog.Logs, int)
}

func GetBodyParser(source string) Parser {
Expand Down
11 changes: 2 additions & 9 deletions receiver/httpreceiver/httpsreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"sync"
"time"
Expand All @@ -25,13 +24,8 @@ const (
defaultEndpoint = ":54321"

defaultServerTimeout = 20 * time.Second
// responseErrNextConsumer = "Internal Server Error"
)

// var (
// errNextConsumerRespBody = initJSONResponse(responseErrNextConsumer)
// )

// NewFactory creates a factory for httpreceiver
func NewFactory() receiver.Factory {
return receiver.NewFactory(metadata.Type, createDefaultConfig, receiver.WithLogs(createLogsReceiver, metadata.LogsStability))
Expand Down Expand Up @@ -184,19 +178,18 @@ func (r *httpreceiver) handleLogs(w http.ResponseWriter, req *http.Request) {
return
}

logs := r.parser.Parse(body)
logs, totalCount := r.parser.Parse(body)

err = r.logsConsumer.ConsumeLogs(ctx, logs)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

log.Printf("Received logs: %d\n", logs.LogRecordCount)
r.obsrecv.EndMetricsOp(
ctx,
metadata.Type,
logs.LogRecordCount(),
totalCount,
err)

}

0 comments on commit 86d1386

Please sign in to comment.