forked from elastic/apm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2] Add event size limit (elastic#1352)
Default limit is set to 300kb.
- Loading branch information
Showing
25 changed files
with
470 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
beater/approved-stream-result/TestV2LineExceeded.approved.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"accepted": 0, | ||
"errors": [ | ||
{ | ||
"document": "{\"metadata\": {\"user\"", | ||
"message": "event exceeded the permitted size." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package decoder | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var ErrLineTooLong = errors.New("Line exceeded permitted length") | ||
|
||
// LineReader reads length-limited lines from streams using a limited amount of memory. | ||
type LineReader struct { | ||
reader io.Reader | ||
br *bufio.Reader | ||
maxLineLength int | ||
skip bool | ||
} | ||
|
||
func NewLineReader(reader io.Reader, maxLineLength int) *LineReader { | ||
return &LineReader{ | ||
reader: reader, | ||
br: bufio.NewReaderSize(reader, maxLineLength), | ||
maxLineLength: maxLineLength, | ||
} | ||
} | ||
|
||
// ReadLine reads the next line from the given reader. | ||
// If it encounters a line that is longer than `maxLineLength` it will | ||
// return the first `maxLineLength` bytes with `ErrLineTooLong`. On the next | ||
// call it will return the next line. | ||
func (lr *LineReader) ReadLine() ([]byte, error) { | ||
for { | ||
prefix := false | ||
line, err := lr.br.ReadSlice('\n') | ||
if err == bufio.ErrBufferFull { | ||
prefix = true | ||
} | ||
|
||
if !lr.skip { | ||
if prefix { | ||
lr.skip = true | ||
return line[:lr.maxLineLength], ErrLineTooLong | ||
} | ||
|
||
if len(line) > 0 && line[len(line)-1] == '\n' { | ||
line = line[:len(line)-1] | ||
} | ||
return line, err | ||
} else if err == io.EOF { | ||
return nil, io.EOF | ||
} else if !prefix { | ||
lr.skip = false | ||
} | ||
} | ||
} |
Oops, something went wrong.