github.com/go-graphite/carbonapi@v0.17.0/cmd/carbonapi/http/metrics_test.go (about) 1 package http 2 3 import ( 4 "testing" 5 6 "github.com/go-graphite/carbonapi/cmd/carbonapi/config" 7 zipperCfg "github.com/go-graphite/carbonapi/zipper/config" 8 "github.com/lomik/zapwriter" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func Test_initRequestsHistogram(t *testing.T) { 13 logger := zapwriter.Logger("test") 14 tests := []struct { 15 name string 16 config zipperCfg.Config 17 wantLabels []string 18 }{ 19 { 20 name: "fixed", 21 config: zipperCfg.Config{Buckets: 10}, 22 wantLabels: []string{ 23 "_in_0ms_to_100ms", "_in_100ms_to_200ms", "_in_200ms_to_300ms", "_in_300ms_to_400ms", "_in_400ms_to_500ms", 24 "_in_500ms_to_600ms", "_in_600ms_to_700ms", "_in_700ms_to_800ms", "_in_800ms_to_900ms", "_in_900ms_to_1000ms", 25 "_in_1000ms_to_1100ms", 26 }, 27 }, 28 { 29 name: "fixed with sum", 30 config: zipperCfg.Config{Buckets: 10, SumBuckets: true}, 31 wantLabels: []string{ 32 "_to_100ms", "_to_200ms", "_to_300ms", "_to_400ms", "_to_500ms", 33 "_to_600ms", "_to_700ms", "_to_800ms", "_to_900ms", "_to_1000ms", "_to_1100ms", 34 }, 35 }, 36 { 37 name: "variable buckets", 38 config: zipperCfg.Config{BucketsWidth: []int64{100, 500, 1000, 5000, 10000}}, 39 wantLabels: []string{ 40 "_in_0ms_to_100ms", "_in_100ms_to_500ms", "_in_500ms_to_1000ms", "_in_1000ms_to_5000ms", 41 "_in_5000ms_to_10000ms", "_in_10000ms_to_inf", 42 }, 43 }, 44 { 45 name: "variable buckets with sum", 46 config: zipperCfg.Config{BucketsWidth: []int64{100, 500, 1000, 5000, 10000}, SumBuckets: true}, 47 wantLabels: []string{ 48 "_to_100ms", "_to_500ms", "_to_1000ms", "_to_5000ms", "_to_10000ms", "_to_inf", 49 }, 50 }, 51 { 52 name: "variable buckets with partial labels", 53 config: zipperCfg.Config{ 54 BucketsWidth: []int64{100, 500, 1000, 5000, 10000}, 55 BucketsLabels: []string{"low", "", "", "", "high", "inf", "none"}, 56 }, 57 wantLabels: []string{ 58 "low", "_in_100ms_to_500ms", "_in_500ms_to_1000ms", "_in_1000ms_to_5000ms", "high", "inf", 59 }, 60 }, 61 { 62 name: "variable buckets with sum and partial labels", 63 config: zipperCfg.Config{ 64 BucketsWidth: []int64{100, 500, 1000, 5000, 10000}, 65 BucketsLabels: []string{"low", "", "", "", "high", "inf", "none"}, 66 SumBuckets: true, 67 }, 68 wantLabels: []string{ 69 "low", "_to_500ms", "_to_1000ms", "_to_5000ms", "high", "inf", 70 }, 71 }, 72 } 73 for _, tt := range tests { 74 t.Run(tt.name, func(t *testing.T) { 75 config.Config.Upstreams = *zipperCfg.SanitizeConfig(logger, tt.config) 76 got := initRequestsHistogram() 77 assert.Equal(t, tt.wantLabels, got.Labels()) 78 assert.Equal(t, len(tt.wantLabels), len(got.Values())) 79 }) 80 } 81 }