mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Low-level sampling, fix for specialized queries like min/max/avg/compare * Whoops fix rate when not sampling * Add trace-level sampling experimental support * Make trace and span sampling individually configurable. Determine results scaling factor at the end based on actual encountered data, instead of upfront, for better accuracy * Add different trace sampling mode that weights data by trace span count * Sampler refactor + first draft of automatic sampling * tweaks * Committing everything before cleaning up * Simplify to sample=true hint and automatically determine the sampling approach that is needed. Comments and cleanup * Support sample=0.xx too * Lint, cleanup * Use logger instead of println * cleanup iterator releaser * Review feedback, cleanup hints, multiplier check * Add tests for avg_over_time and scaling * Add test for compare() * Add tests for compare() scaling * changelog * add comments * Fix gap for query type that needs full trace * more changelog
35 lines
876 B
Go
35 lines
876 B
Go
package traceql
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAdaptiveSamplerRate(t *testing.T) {
|
|
testCases := []struct {
|
|
proportion float64
|
|
lim int
|
|
}{
|
|
// Anything 10% or less is sampled at 100%
|
|
{proportion: 0.01, lim: 1},
|
|
{proportion: 0.05, lim: 1},
|
|
{proportion: 0.1, lim: 1},
|
|
// Between 11% and 20% is sampled at 1 in 2
|
|
{proportion: 0.15, lim: 2},
|
|
{proportion: 0.2, lim: 2},
|
|
{proportion: 0.25, lim: 3},
|
|
{proportion: 0.3, lim: 3},
|
|
{proportion: 0.4, lim: 4},
|
|
{proportion: 0.5, lim: 5},
|
|
{proportion: 0.6, lim: 6},
|
|
{proportion: 0.8, lim: 8},
|
|
{proportion: 0.9, lim: 9},
|
|
{proportion: 1.0, lim: 10}, // in 100% of data, sample 10%
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
require.Equal(t, tc.lim, rateFor(tc.proportion), "sample rate for %f, wanted %d, got %d", tc.proportion, tc.lim, rateFor(tc.proportion))
|
|
}
|
|
}
|