Skip to content

Commit

Permalink
Added support for snappy to enable prometheus remote write (#8983)
Browse files Browse the repository at this point in the history
Adding a feature.

This adds `snappy` support for the confighttp compression package.
This provides support for enabling the prometheus remote write receiver
which only supports snappy.

#7632

Added unit test coverage and testing integration with prometheus remote
write compatibility.

---------

Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
JustinMason and bogdandrutu authored Feb 12, 2024
1 parent 488e45d commit 1a57837
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .chloggen/add-snappy-confighttp-decompress.yaml
Original file line number Diff line number Diff line change
@@ -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: Adds support for Snappy decompression of HTTP requests.

# One or more tracking issues or pull requests related to the change
issues: [7632]

# (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: []
13 changes: 13 additions & 0 deletions config/confighttp/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"net/http"

"github.com/golang/snappy"
"github.com/klauspost/compress/zstd"

"go.opentelemetry.io/collector/config/configcompression"
Expand Down Expand Up @@ -117,6 +118,18 @@ func httpContentDecompressor(h http.Handler, eh func(w http.ResponseWriter, r *h
}
return zr, nil
},
"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
},
},
}
d.decoders["deflate"] = d.decoders["zlib"]
Expand Down
13 changes: 13 additions & 0 deletions config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func TestHTTPContentDecompressionHandler(t *testing.T) {
reqBody: compressZstd(t, testBody),
respCode: http.StatusOK,
},
{
name: "ValidSnappy",
encoding: "snappy",
reqBody: compressSnappy(t, testBody),
respCode: http.StatusOK,
},
{
name: "InvalidDeflate",
encoding: "deflate",
Expand Down Expand Up @@ -218,6 +224,13 @@ func TestHTTPContentDecompressionHandler(t *testing.T) {
respCode: http.StatusBadRequest,
respBody: "invalid input: magic number mismatch",
},
{
name: "InvalidSnappy",
encoding: "snappy",
reqBody: bytes.NewBuffer(testBody),
respCode: http.StatusBadRequest,
respBody: "snappy: corrupt input\n",
},
{
name: "UnsupportedCompression",
encoding: "nosuchcompression",
Expand Down

0 comments on commit 1a57837

Please sign in to comment.