mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
Improve remote write handling in vmagent by setting the
`Content-Encoding` header based on the actual request body, rather than
relying on configuration.
- Detects Zstd compression via the Zstd magic number.
- Falls back to Snappy if Zstd is not detected.
- Persistent queue may now contain mixed-encoding content.
- Add basic vmagent integration tests
Follow up on
https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5344 and
12cd32fd75.
Extracted from
https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8462
Related issue:
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5301
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package encoding_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
|
"github.com/golang/snappy"
|
|
)
|
|
|
|
func TestIsZstd(t *testing.T) {
|
|
// nil
|
|
if encoding.IsZstd(nil) {
|
|
t.Fatalf("unexpected IsZstd result; got true; expecting false")
|
|
}
|
|
|
|
// empty
|
|
if encoding.IsZstd([]byte{}) {
|
|
t.Fatalf("unexpected IsZstd result; got true; expecting false")
|
|
}
|
|
|
|
// less than 4 bytes
|
|
if encoding.IsZstd([]byte(`foo`)) {
|
|
t.Fatalf("unexpected IsZstd result; got true; expecting false")
|
|
}
|
|
|
|
// plain text
|
|
if encoding.IsZstd([]byte(`foobar`)) {
|
|
t.Fatalf("unexpected IsZstd result; got true; expecting false")
|
|
}
|
|
|
|
// snappy compressed
|
|
if encoding.IsZstd(snappy.Encode(nil, []byte(`foobar`))) {
|
|
t.Fatalf("unexpected IsZstd result; got true; expecting false")
|
|
}
|
|
|
|
// zstd minimum compressed level
|
|
if !encoding.IsZstd(encoding.CompressZSTDLevel(nil, []byte(`foobar`), -22)) {
|
|
t.Fatalf("unexpected IsZstd result; got false; expecting true")
|
|
}
|
|
|
|
// zstd maximum compressed level
|
|
if !encoding.IsZstd(encoding.CompressZSTDLevel(nil, []byte(`foobar`), 22)) {
|
|
t.Fatalf("unexpected IsZstd result; got false; expecting true")
|
|
}
|
|
}
|