Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Result to Include Signal Types #409

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions input/elasticapm/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,25 @@ func (p *Processor) handleStream(
if n == 0 {
return readErr
}

if err := p.processBatch(ctx, processor, batch); err != nil {
if err := processor.ProcessBatch(ctx, batch); err != nil {
return fmt.Errorf("cannot process batch: %w", err)
}
for _, v := range *batch {
rubvs marked this conversation as resolved.
Show resolved Hide resolved
switch v.Type() {
case modelpb.SpanEventType:
result.SpanAccepted++
case modelpb.TransactionEventType:
result.TransactionAccepted++
case modelpb.MetricEventType:
result.MetricAccepted++
case modelpb.LogEventType:
rubvs marked this conversation as resolved.
Show resolved Hide resolved
result.LogAccepted++
}
}
result.Accepted += n
return readErr
}

// processBatch processes the batch and returns the events to the pool after it's been processed.
func (p *Processor) processBatch(ctx context.Context, processor modelpb.BatchProcessor, batch *modelpb.Batch) error {
return processor.ProcessBatch(ctx, batch)
}

rubvs marked this conversation as resolved.
Show resolved Hide resolved
// getStreamReader returns a streamReader that reads ND-JSON lines from r.
func (p *Processor) getStreamReader(r io.Reader) *streamReader {
return &streamReader{
Expand Down
8 changes: 6 additions & 2 deletions input/elasticapm/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

func TestHandleStreamReaderError(t *testing.T) {
readErr := errors.New("read failed")
cnt := 5
var calls int
var reader readerFunc = func(p []byte) (int, error) {
calls++
Expand All @@ -43,7 +44,7 @@ func TestHandleStreamReaderError(t *testing.T) {
}
buf := bytes.NewBuffer(nil)
buf.WriteString(validMetadata + "\n")
for i := 0; i < 5; i++ {
for i := 0; i < cnt; i++ {
buf.WriteString(validTransaction + "\n")
}
return copy(p, buf.Bytes()), nil
Expand All @@ -60,7 +61,10 @@ func TestHandleStreamReaderError(t *testing.T) {
reader, 10, nopBatchProcessor{}, &actualResult,
)
assert.ErrorIs(t, err, readErr)
assert.Equal(t, Result{Accepted: 5}, actualResult)
assert.Equal(t, Result{
Accepted: cnt,
TransactionAccepted: cnt,
}, actualResult)
}

type readerFunc func([]byte) (int, error)
Expand Down
22 changes: 19 additions & 3 deletions input/elasticapm/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,34 @@ import (

type Result struct {
errorsSpace [5]error

// Errors holds a limited number of errors that occurred while
// processing the event stream. If the limit is reached, the
// counters above are still incremented.
Errors []error

// Accepted holds the number of valid events accepted.
Accepted int
Accepted int
SpanAccepted int
TransactionAccepted int
MetricAccepted int
LogAccepted int
rubvs marked this conversation as resolved.
Show resolved Hide resolved

// TooLarge holds the number of events that were rejected due
// to exceeding the event size limit.
TooLarge int
TooLarge int
SpanTooLarge int
TransactionTooLarge int
MetricTooLarge int
LogTooLarge int

// Invalid holds the number of events that were rejected due
// to being invalid, excluding those that are counted by TooLarge.
Invalid int
Invalid int
SpanInvalid int
TransactionInvalid int
MetricInvalid int
LogInvalid int
}

func (r *Result) addError(err error) {
Expand Down
Loading