diff --git a/.chloggen/msg_fix-snappy-lazy-read.yaml b/.chloggen/msg_fix-snappy-lazy-read.yaml new file mode 100644 index 00000000000..3188cfcc8b9 --- /dev/null +++ b/.chloggen/msg_fix-snappy-lazy-read.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: confighttp + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Snappy compression to lazy read for memory efficiency + +# One or more tracking issues or pull requests related to the change +issues: [] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/config/confighttp/compression.go b/config/confighttp/compression.go index 4498fefe864..3c1a494e0c2 100644 --- a/config/confighttp/compression.go +++ b/config/confighttp/compression.go @@ -58,17 +58,10 @@ var availableDecoders = map[string]func(body io.ReadCloser) (io.ReadCloser, erro } return zr, nil }, + //nolint:unparam // ignoring lint since method needs to fit typedef "snappy": func(body io.ReadCloser) (io.ReadCloser, error) { - sr := snappy.NewReader(body) - sb := new(bytes.Buffer) - _, err := io.Copy(sb, sr) - if err != nil { - return nil, err - } - if err = body.Close(); err != nil { - return nil, err - } - return io.NopCloser(sb), nil + // Lazy Reading content to improve memory efficiency + return io.NopCloser(snappy.NewReader(body)), nil }, } diff --git a/config/confighttp/compression_test.go b/config/confighttp/compression_test.go index a4fcb013f4f..fe087827418 100644 --- a/config/confighttp/compression_test.go +++ b/config/confighttp/compression_test.go @@ -230,7 +230,7 @@ func TestHTTPContentDecompressionHandler(t *testing.T) { encoding: "snappy", reqBody: bytes.NewBuffer(testBody), respCode: http.StatusBadRequest, - respBody: "snappy: corrupt input\n", + respBody: "snappy: corrupt input", }, { name: "UnsupportedCompression",