diff --git a/.circleci/config.yml b/.circleci/config.yml index 9ba7e9c4fed15..20568a9c4284f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,7 +106,7 @@ jobs: - run: 'make check-deps' - run: name: "Install golangci-lint" - command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 + command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 - run: name: "golangci-lint/Linux" # There are only 4 vCPUs available for this executor, so use only 4 instead of the default number @@ -120,7 +120,7 @@ jobs: - check-changed-files-or-halt - run: name: "Install golangci-lint" - command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 + command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 - run: name: "golangci-lint/macOS" # There are only 4 vCPUs available for this executor, so use only 4 instead of the default number @@ -134,7 +134,7 @@ jobs: - check-changed-files-or-halt - run: name: "Install golangci-lint" - command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 + command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 - run: name: "golangci-lint/Windows" # There are only 4 vCPUs available for this executor, so use only 4 instead of the default number diff --git a/.golangci.yml b/.golangci.yml index 9821917770265..0473e3431bcdf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -284,10 +284,9 @@ linters-settings: - name: import-shadowing - name: increment-decrement - name: indent-error-flow -# Enable again when https://github.com/mgechev/revive/issues/1103 is fixed -# - name: max-public-structs -# exclude: [ "TEST" ] -# arguments: [ 5 ] + - name: max-public-structs + exclude: ["TEST", "~metric.go", "~plugins/common/*"] + arguments: [ 5 ] - name: modifies-parameter - name: modifies-value-receiver - name: optimize-operands-order diff --git a/Makefile b/Makefile index 543bd9ae2f537..71ac0a668c316 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,7 @@ vet: .PHONY: lint-install lint-install: @echo "Installing golangci-lint" - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 @echo "Installing markdownlint" npm install -g markdownlint-cli diff --git a/internal/content_coding.go b/internal/content_coding.go index 624e3c2bffcdb..9070196706cde 100644 --- a/internal/content_coding.go +++ b/internal/content_coding.go @@ -15,8 +15,7 @@ import ( const defaultMaxDecompressionSize int64 = 500 * 1024 * 1024 // 500MB -// DecodingOption provide methods to change the decoding from the standard -// configuration. +// DecodingOption provide methods to change the decoding from the standard configuration. type DecodingOption func(*decoderConfig) type decoderConfig struct { @@ -33,8 +32,7 @@ type encoderConfig struct { level int } -// EncodingOption provide methods to change the encoding from the standard -// configuration. +// EncodingOption provide methods to change the encoding from the standard configuration. type EncodingOption func(*encoderConfig) func WithCompressionLevel(level int) EncodingOption { @@ -43,12 +41,11 @@ func WithCompressionLevel(level int) EncodingOption { } } -// NewStreamContentDecoder returns a reader that will decode the stream -// according to the encoding type. +// NewStreamContentDecoder returns a reader that will decode the stream according to the encoding type. func NewStreamContentDecoder(encoding string, r io.Reader) (io.Reader, error) { switch encoding { case "gzip": - return NewGzipReader(r) + return newGzipReader(r) case "identity", "": return r, nil default: @@ -56,14 +53,14 @@ func NewStreamContentDecoder(encoding string, r io.Reader) (io.Reader, error) { } } -// GzipReader is similar to gzip.Reader but reads only a single gzip stream per read. -type GzipReader struct { +// gzipReader is similar to gzip.Reader but reads only a single gzip stream per read. +type gzipReader struct { r io.Reader z *pgzip.Reader endOfStream bool } -func NewGzipReader(r io.Reader) (io.Reader, error) { +func newGzipReader(r io.Reader) (io.Reader, error) { // We need a read that implements ByteReader in order to line up the next // stream. br := bufio.NewReader(r) @@ -77,10 +74,10 @@ func NewGzipReader(r io.Reader) (io.Reader, error) { // Prevent future calls to Read from reading the following gzip header. z.Multistream(false) - return &GzipReader{r: br, z: z}, nil + return &gzipReader{r: br, z: z}, nil } -func (r *GzipReader) Read(b []byte) (int, error) { +func (r *gzipReader) Read(b []byte) (int, error) { if r.endOfStream { // Reads the next gzip header and prepares for the next stream. err := r.z.Reset(r.r) @@ -106,40 +103,40 @@ func (r *GzipReader) Read(b []byte) (int, error) { func NewContentEncoder(encoding string, options ...EncodingOption) (ContentEncoder, error) { switch encoding { case "gzip": - return NewGzipEncoder(options...) + return newGzipEncoder(options...) case "identity", "": - return NewIdentityEncoder(options...) + return newIdentityEncoder(options...) case "zlib": - return NewZlibEncoder(options...) + return newZlibEncoder(options...) case "zstd": - return NewZstdEncoder(options...) + return newZstdEncoder(options...) default: return nil, errors.New("invalid value for content_encoding") } } -type AutoDecoder struct { +type autoDecoder struct { encoding string - gzip *GzipDecoder - identity *IdentityDecoder + gzip *gzipDecoder + identity *identityDecoder } -func (a *AutoDecoder) SetEncoding(encoding string) { +func (a *autoDecoder) SetEncoding(encoding string) { a.encoding = encoding } -func (a *AutoDecoder) Decode(data []byte) ([]byte, error) { +func (a *autoDecoder) Decode(data []byte) ([]byte, error) { if a.encoding == "gzip" { return a.gzip.Decode(data) } return a.identity.Decode(data) } -func NewAutoContentDecoder(options ...DecodingOption) *AutoDecoder { - var a AutoDecoder +func newAutoContentDecoder(options ...DecodingOption) *autoDecoder { + var a autoDecoder - a.identity = NewIdentityDecoder(options...) - a.gzip = NewGzipDecoder(options...) + a.identity = newIdentityDecoder(options...) + a.gzip = newGzipDecoder(options...) return &a } @@ -147,15 +144,15 @@ func NewAutoContentDecoder(options ...DecodingOption) *AutoDecoder { func NewContentDecoder(encoding string, options ...DecodingOption) (ContentDecoder, error) { switch encoding { case "auto": - return NewAutoContentDecoder(options...), nil + return newAutoContentDecoder(options...), nil case "gzip": - return NewGzipDecoder(options...), nil + return newGzipDecoder(options...), nil case "identity", "": - return NewIdentityDecoder(options...), nil + return newIdentityDecoder(options...), nil case "zlib": - return NewZlibDecoder(options...), nil + return newZlibDecoder(options...), nil case "zstd": - return NewZstdDecoder(options...) + return newZstdDecoder(options...) default: return nil, errors.New("invalid value for content_encoding") } @@ -166,14 +163,14 @@ type ContentEncoder interface { Encode([]byte) ([]byte, error) } -// GzipEncoder compresses the buffer using gzip at the default level. -type GzipEncoder struct { +// gzipEncoder compresses the buffer using gzip at the default level. +type gzipEncoder struct { pwriter *pgzip.Writer writer *gzip.Writer buf *bytes.Buffer } -func NewGzipEncoder(options ...EncodingOption) (*GzipEncoder, error) { +func newGzipEncoder(options ...EncodingOption) (*gzipEncoder, error) { cfg := encoderConfig{level: gzip.DefaultCompression} for _, o := range options { o(&cfg) @@ -194,14 +191,14 @@ func NewGzipEncoder(options ...EncodingOption) (*GzipEncoder, error) { } w, err := gzip.NewWriterLevel(&buf, cfg.level) - return &GzipEncoder{ + return &gzipEncoder{ pwriter: pw, writer: w, buf: &buf, }, err } -func (e *GzipEncoder) Encode(data []byte) ([]byte, error) { +func (e *gzipEncoder) Encode(data []byte) ([]byte, error) { // Parallel Gzip is only faster for larger data chunks. According to the // project's documentation the trade-off size is at about 1MB, so we switch // to parallel Gzip if the data is larger and run the built-in version @@ -212,7 +209,7 @@ func (e *GzipEncoder) Encode(data []byte) ([]byte, error) { return e.encodeSmall(data) } -func (e *GzipEncoder) encodeSmall(data []byte) ([]byte, error) { +func (e *gzipEncoder) encodeSmall(data []byte) ([]byte, error) { e.buf.Reset() e.writer.Reset(e.buf) @@ -227,7 +224,7 @@ func (e *GzipEncoder) encodeSmall(data []byte) ([]byte, error) { return e.buf.Bytes(), nil } -func (e *GzipEncoder) encodeBig(data []byte) ([]byte, error) { +func (e *gzipEncoder) encodeBig(data []byte) ([]byte, error) { e.buf.Reset() e.pwriter.Reset(e.buf) @@ -242,12 +239,12 @@ func (e *GzipEncoder) encodeBig(data []byte) ([]byte, error) { return e.buf.Bytes(), nil } -type ZlibEncoder struct { +type zlibEncoder struct { writer *zlib.Writer buf *bytes.Buffer } -func NewZlibEncoder(options ...EncodingOption) (*ZlibEncoder, error) { +func newZlibEncoder(options ...EncodingOption) (*zlibEncoder, error) { cfg := encoderConfig{level: zlib.DefaultCompression} for _, o := range options { o(&cfg) @@ -262,13 +259,13 @@ func NewZlibEncoder(options ...EncodingOption) (*ZlibEncoder, error) { var buf bytes.Buffer w, err := zlib.NewWriterLevel(&buf, cfg.level) - return &ZlibEncoder{ + return &zlibEncoder{ writer: w, buf: &buf, }, err } -func (e *ZlibEncoder) Encode(data []byte) ([]byte, error) { +func (e *zlibEncoder) Encode(data []byte) ([]byte, error) { e.buf.Reset() e.writer.Reset(e.buf) @@ -283,11 +280,11 @@ func (e *ZlibEncoder) Encode(data []byte) ([]byte, error) { return e.buf.Bytes(), nil } -type ZstdEncoder struct { +type zstdEncoder struct { encoder *zstd.Encoder } -func NewZstdEncoder(options ...EncodingOption) (*ZstdEncoder, error) { +func newZstdEncoder(options ...EncodingOption) (*zstdEncoder, error) { cfg := encoderConfig{level: 3} for _, o := range options { o(&cfg) @@ -309,27 +306,27 @@ func NewZstdEncoder(options ...EncodingOption) (*ZstdEncoder, error) { } e, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(level)) - return &ZstdEncoder{ + return &zstdEncoder{ encoder: e, }, err } -func (e *ZstdEncoder) Encode(data []byte) ([]byte, error) { +func (e *zstdEncoder) Encode(data []byte) ([]byte, error) { return e.encoder.EncodeAll(data, make([]byte, 0, len(data))), nil } -// IdentityEncoder is a null encoder that applies no transformation. -type IdentityEncoder struct{} +// identityEncoder is a null encoder that applies no transformation. +type identityEncoder struct{} -func NewIdentityEncoder(options ...EncodingOption) (*IdentityEncoder, error) { +func newIdentityEncoder(options ...EncodingOption) (*identityEncoder, error) { if len(options) > 0 { return nil, errors.New("identity encoder does not support options") } - return &IdentityEncoder{}, nil + return &identityEncoder{}, nil } -func (*IdentityEncoder) Encode(data []byte) ([]byte, error) { +func (*identityEncoder) Encode(data []byte) ([]byte, error) { return data, nil } @@ -339,21 +336,21 @@ type ContentDecoder interface { Decode([]byte) ([]byte, error) } -// GzipDecoder decompresses buffers with gzip compression. -type GzipDecoder struct { +// gzipDecoder decompresses buffers with gzip compression. +type gzipDecoder struct { preader *pgzip.Reader reader *gzip.Reader buf *bytes.Buffer maxDecompressionSize int64 } -func NewGzipDecoder(options ...DecodingOption) *GzipDecoder { +func newGzipDecoder(options ...DecodingOption) *gzipDecoder { cfg := decoderConfig{maxDecompressionSize: defaultMaxDecompressionSize} for _, o := range options { o(&cfg) } - return &GzipDecoder{ + return &gzipDecoder{ preader: new(pgzip.Reader), reader: new(gzip.Reader), buf: new(bytes.Buffer), @@ -361,9 +358,9 @@ func NewGzipDecoder(options ...DecodingOption) *GzipDecoder { } } -func (*GzipDecoder) SetEncoding(string) {} +func (*gzipDecoder) SetEncoding(string) {} -func (d *GzipDecoder) Decode(data []byte) ([]byte, error) { +func (d *gzipDecoder) Decode(data []byte) ([]byte, error) { // Parallel Gzip is only faster for larger data chunks. According to the // project's documentation the trade-off size is at about 1MB, so we switch // to parallel Gzip if the data is larger and run the built-in version @@ -374,7 +371,7 @@ func (d *GzipDecoder) Decode(data []byte) ([]byte, error) { return d.decodeSmall(data) } -func (d *GzipDecoder) decodeSmall(data []byte) ([]byte, error) { +func (d *gzipDecoder) decodeSmall(data []byte) ([]byte, error) { err := d.reader.Reset(bytes.NewBuffer(data)) if err != nil { return nil, err @@ -395,7 +392,7 @@ func (d *GzipDecoder) decodeSmall(data []byte) ([]byte, error) { return d.buf.Bytes(), nil } -func (d *GzipDecoder) decodeBig(data []byte) ([]byte, error) { +func (d *gzipDecoder) decodeBig(data []byte) ([]byte, error) { err := d.preader.Reset(bytes.NewBuffer(data)) if err != nil { return nil, err @@ -416,26 +413,26 @@ func (d *GzipDecoder) decodeBig(data []byte) ([]byte, error) { return d.buf.Bytes(), nil } -type ZlibDecoder struct { +type zlibDecoder struct { buf *bytes.Buffer maxDecompressionSize int64 } -func NewZlibDecoder(options ...DecodingOption) *ZlibDecoder { +func newZlibDecoder(options ...DecodingOption) *zlibDecoder { cfg := decoderConfig{maxDecompressionSize: defaultMaxDecompressionSize} for _, o := range options { o(&cfg) } - return &ZlibDecoder{ + return &zlibDecoder{ buf: new(bytes.Buffer), maxDecompressionSize: cfg.maxDecompressionSize, } } -func (*ZlibDecoder) SetEncoding(string) {} +func (*zlibDecoder) SetEncoding(string) {} -func (d *ZlibDecoder) Decode(data []byte) ([]byte, error) { +func (d *zlibDecoder) Decode(data []byte) ([]byte, error) { d.buf.Reset() b := bytes.NewBuffer(data) @@ -458,38 +455,38 @@ func (d *ZlibDecoder) Decode(data []byte) ([]byte, error) { return d.buf.Bytes(), nil } -type ZstdDecoder struct { +type zstdDecoder struct { decoder *zstd.Decoder } -func NewZstdDecoder(options ...DecodingOption) (*ZstdDecoder, error) { +func newZstdDecoder(options ...DecodingOption) (*zstdDecoder, error) { cfg := decoderConfig{maxDecompressionSize: defaultMaxDecompressionSize} for _, o := range options { o(&cfg) } d, err := zstd.NewReader(nil, zstd.WithDecoderConcurrency(0), zstd.WithDecoderMaxWindow(uint64(cfg.maxDecompressionSize))) - return &ZstdDecoder{ + return &zstdDecoder{ decoder: d, }, err } -func (*ZstdDecoder) SetEncoding(string) {} +func (*zstdDecoder) SetEncoding(string) {} -func (d *ZstdDecoder) Decode(data []byte) ([]byte, error) { +func (d *zstdDecoder) Decode(data []byte) ([]byte, error) { return d.decoder.DecodeAll(data, nil) } -// IdentityDecoder is a null decoder that returns the input. -type IdentityDecoder struct { +// identityDecoder is a null decoder that returns the input. +type identityDecoder struct { } -func NewIdentityDecoder(_ ...DecodingOption) *IdentityDecoder { - return &IdentityDecoder{} +func newIdentityDecoder(_ ...DecodingOption) *identityDecoder { + return &identityDecoder{} } -func (*IdentityDecoder) SetEncoding(string) {} +func (*identityDecoder) SetEncoding(string) {} -func (*IdentityDecoder) Decode(data []byte) ([]byte, error) { +func (*identityDecoder) Decode(data []byte) ([]byte, error) { return data, nil } diff --git a/internal/content_coding_test.go b/internal/content_coding_test.go index 46401b1129e3f..2d3a1712f0687 100644 --- a/internal/content_coding_test.go +++ b/internal/content_coding_test.go @@ -13,9 +13,9 @@ import ( const maxDecompressionSize = 1024 func TestGzipEncodeDecode(t *testing.T) { - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(t, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + dec := newGzipDecoder(WithMaxDecompressionSize(maxDecompressionSize)) payload, err := enc.Encode([]byte("howdy")) require.NoError(t, err) @@ -27,9 +27,9 @@ func TestGzipEncodeDecode(t *testing.T) { } func TestGzipReuse(t *testing.T) { - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(t, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + dec := newGzipDecoder(WithMaxDecompressionSize(maxDecompressionSize)) payload, err := enc.Encode([]byte("howdy")) require.NoError(t, err) @@ -49,9 +49,9 @@ func TestGzipReuse(t *testing.T) { } func TestZlibEncodeDecode(t *testing.T) { - enc, err := NewZlibEncoder() + enc, err := newZlibEncoder() require.NoError(t, err) - dec := NewZlibDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + dec := newZlibDecoder(WithMaxDecompressionSize(maxDecompressionSize)) payload, err := enc.Encode([]byte("howdy")) require.NoError(t, err) @@ -63,9 +63,9 @@ func TestZlibEncodeDecode(t *testing.T) { } func TestZlibEncodeDecodeWithTooLargeMessage(t *testing.T) { - enc, err := NewZlibEncoder() + enc, err := newZlibEncoder() require.NoError(t, err) - dec := NewZlibDecoder(WithMaxDecompressionSize(3)) + dec := newZlibDecoder(WithMaxDecompressionSize(3)) payload, err := enc.Encode([]byte("howdy")) require.NoError(t, err) @@ -75,9 +75,9 @@ func TestZlibEncodeDecodeWithTooLargeMessage(t *testing.T) { } func TestZstdEncodeDecode(t *testing.T) { - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(t, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(maxDecompressionSize)) require.NoError(t, err) payload, err := enc.Encode([]byte("howdy")) @@ -90,9 +90,9 @@ func TestZstdEncodeDecode(t *testing.T) { } func TestZstdReuse(t *testing.T) { - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(t, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(maxDecompressionSize)) require.NoError(t, err) payload, err := enc.Encode([]byte("howdy")) @@ -113,8 +113,8 @@ func TestZstdReuse(t *testing.T) { } func TestIdentityEncodeDecode(t *testing.T) { - dec := NewIdentityDecoder(WithMaxDecompressionSize(maxDecompressionSize)) - enc, err := NewIdentityEncoder() + dec := newIdentityDecoder(WithMaxDecompressionSize(maxDecompressionSize)) + enc, err := newIdentityEncoder() require.NoError(t, err) payload, err := enc.Encode([]byte("howdy")) @@ -142,7 +142,7 @@ func TestStreamIdentityDecode(t *testing.T) { } func TestStreamGzipDecode(t *testing.T) { - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(t, err) written, err := enc.Encode([]byte("howdy")) require.NoError(t, err) @@ -229,9 +229,9 @@ func BenchmarkGzipEncode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -248,9 +248,9 @@ func BenchmarkGzipDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -267,9 +267,9 @@ func BenchmarkGzipEncodeDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -289,9 +289,9 @@ func BenchmarkGzipEncodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -308,9 +308,9 @@ func BenchmarkGzipDecodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -327,9 +327,9 @@ func BenchmarkGzipEncodeDecodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewGzipEncoder() + enc, err := newGzipEncoder() require.NoError(b, err) - dec := NewGzipDecoder(WithMaxDecompressionSize(dataLen)) + dec := newGzipDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -349,9 +349,9 @@ func BenchmarkZstdEncode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -369,9 +369,9 @@ func BenchmarkZstdDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -389,9 +389,9 @@ func BenchmarkZstdEncodeDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -412,9 +412,9 @@ func BenchmarkZstdEncodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -432,9 +432,9 @@ func BenchmarkZstdDecodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -452,9 +452,9 @@ func BenchmarkZstdEncodeDecodeBig(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 1024*1024)) dataLen := int64(len(data)) + 1 - enc, err := NewZstdEncoder() + enc, err := newZstdEncoder() require.NoError(b, err) - dec, err := NewZstdDecoder(WithMaxDecompressionSize(dataLen)) + dec, err := newZstdDecoder(WithMaxDecompressionSize(dataLen)) require.NoError(b, err) payload, err := enc.Encode(data) require.NoError(b, err) @@ -475,9 +475,9 @@ func BenchmarkZlibEncode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZlibEncoder() + enc, err := newZlibEncoder() require.NoError(b, err) - dec := NewZlibDecoder(WithMaxDecompressionSize(dataLen)) + dec := newZlibDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -494,9 +494,9 @@ func BenchmarkZlibDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZlibEncoder() + enc, err := newZlibEncoder() require.NoError(b, err) - dec := NewZlibDecoder(WithMaxDecompressionSize(dataLen)) + dec := newZlibDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -513,9 +513,9 @@ func BenchmarkZlibEncodeDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - enc, err := NewZlibEncoder() + enc, err := newZlibEncoder() require.NoError(b, err) - dec := NewZlibDecoder(WithMaxDecompressionSize(dataLen)) + dec := newZlibDecoder(WithMaxDecompressionSize(dataLen)) payload, err := enc.Encode(data) require.NoError(b, err) actual, err := dec.Decode(payload) @@ -535,8 +535,8 @@ func BenchmarkIdentityEncodeDecode(b *testing.B) { data := []byte(strings.Repeat("-howdy stranger-", 64)) dataLen := int64(len(data)) + 1 - dec := NewIdentityDecoder(WithMaxDecompressionSize(dataLen)) - enc, err := NewIdentityEncoder() + dec := newIdentityDecoder(WithMaxDecompressionSize(dataLen)) + enc, err := newIdentityEncoder() require.NoError(b, err) payload, err := enc.Encode(data) diff --git a/plugins/inputs/amqp_consumer/amqp_consumer_test.go b/plugins/inputs/amqp_consumer/amqp_consumer_test.go index 481d9fa3ef0d0..1bb8063539aac 100644 --- a/plugins/inputs/amqp_consumer/amqp_consumer_test.go +++ b/plugins/inputs/amqp_consumer/amqp_consumer_test.go @@ -21,7 +21,7 @@ import ( func TestAutoEncoding(t *testing.T) { // Setup a gzipped payload - enc, err := internal.NewGzipEncoder() + enc, err := internal.NewContentEncoder("gzip") require.NoError(t, err) payloadGZip, err := enc.Encode([]byte(`measurementName fieldKey="gzip" 1556813561098000000`)) require.NoError(t, err) @@ -50,7 +50,7 @@ func TestAutoEncoding(t *testing.T) { acc.AssertContainsFields(t, "measurementName", map[string]interface{}{"fieldKey": "gzip"}) // Check the decoding - encIdentity, err := internal.NewIdentityEncoder() + encIdentity, err := internal.NewContentEncoder("identity") require.NoError(t, err) payload, err := encIdentity.Encode([]byte(`measurementName2 fieldKey="identity" 1556813561098000000`)) require.NoError(t, err) diff --git a/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go b/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go index 4362f87f7680a..16c7314d6fb7e 100644 --- a/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go +++ b/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go @@ -143,7 +143,7 @@ func TestRunGzipDecode(t *testing.T) { require.NotNil(t, ps.sub) testTracker := &testTracker{} - enc, err := internal.NewGzipEncoder() + enc, err := internal.NewContentEncoder("gzip") require.NoError(t, err) gzippedMsg, err := enc.Encode([]byte(msgInflux)) require.NoError(t, err) diff --git a/plugins/outputs/influxdb_v2/influxdb_v2.go b/plugins/outputs/influxdb_v2/influxdb_v2.go index 15a66632788e2..a1b95002508ea 100644 --- a/plugins/outputs/influxdb_v2/influxdb_v2.go +++ b/plugins/outputs/influxdb_v2/influxdb_v2.go @@ -69,7 +69,7 @@ func (i *InfluxDB) Init() error { switch i.ContentEncoding { case "", "gzip": i.ContentEncoding = "gzip" - enc, err := internal.NewGzipEncoder() + enc, err := internal.NewContentEncoder("gzip") if err != nil { return fmt.Errorf("setting up gzip encoder failed: %w", err) }