Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loki/pkg/chunkenc/hash_test.go

61 lines
1.3 KiB

Improve metric queries by computing samples at the edges. (#2293) * First pass breaking the code appart. Wondering how we're going to achieve fast mutation of labels. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Work in progress. I realize I need hash for deduping lines. going to benchmark somes. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Tested some hash and decided which one to use. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Wip Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Starting working on ingester. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Trying to find a better hash function. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * More hash testing we have a winner. xxhash it is. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Settle on xxhash Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Better params interfacing. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add interface for queryparams for things that exist in both type of params. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add storage sample iterator implementations. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixing tests and verifying we don't get collions for the hashing method. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixing ingesters tests and refactoring utility function/tests. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixing and testing that stats are still well computed. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixing more tests. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * More engine tests finished. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes sharding evaluator. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes more engine tests. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fix error tests in the engine. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Finish fixing all tests. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fixes a bug where extractor was not passed in correctly. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add notes about upgrade. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Renamed and fix a bug. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Add memchunk tests and starting test for sampleIterator. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Test heap sample iterator. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * working on test. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Finishing testing all new iterators. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Making sure all store functions are tested. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Benchmark and verify everything is working well. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Make the linter happy. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * use xxhash v2. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Fix a flaky test because of map. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * go.mod. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> Co-authored-by: Edward Welch <edward.welch@grafana.com>
6 years ago
package chunkenc
import (
"hash/fnv"
"testing"
"github.com/cespare/xxhash/v2"
"github.com/segmentio/fasthash/fnv1a"
"github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/chunkenc/testdata"
)
var res uint64
func Benchmark_fnv64a(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < len(testdata.LogsBytes); i++ {
h := fnv.New64a()
_, _ = h.Write(testdata.LogsBytes[i])
res = h.Sum64()
}
}
}
func Benchmark_fnv64a_third_party(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < len(testdata.LogsBytes); i++ {
res = fnv1a.HashBytes64(testdata.LogsBytes[i])
}
}
}
func Benchmark_xxhash(b *testing.B) {
for n := 0; n < b.N; n++ {
for i := 0; i < len(testdata.LogsBytes); i++ {
res = xxhash.Sum64(testdata.LogsBytes[i])
}
}
}
func Test_xxhash_integrity(t *testing.T) {
data := []uint64{}
for i := 0; i < len(testdata.LogsBytes); i++ {
data = append(data, xxhash.Sum64(testdata.LogsBytes[i]))
}
for i := 0; i < len(testdata.LogsBytes); i++ {
require.Equal(t, data[i], xxhash.Sum64(testdata.LogsBytes[i]))
}
unique := map[uint64]struct{}{}
for i := 0; i < len(testdata.LogsBytes); i++ {
_, ok := unique[xxhash.Sum64(testdata.LogsBytes[i])]
require.False(t, ok, string(testdata.LogsBytes[i])) // all lines have been made unique
unique[xxhash.Sum64(testdata.LogsBytes[i])] = struct{}{}
}
}