diff --git a/pkg/store/hintspb/custom.go b/pkg/store/hintspb/custom.go index 463418f6fe..40861143c0 100644 --- a/pkg/store/hintspb/custom.go +++ b/pkg/store/hintspb/custom.go @@ -37,7 +37,7 @@ func (m *QueryStats) Merge(other *QueryStats) { m.SeriesFetched += other.SeriesFetched m.SeriesFetchCount += other.SeriesFetchCount - m.SeriesFetchedSizeSum += m.SeriesFetchedSizeSum + m.SeriesFetchedSizeSum += other.SeriesFetchedSizeSum m.SeriesTouched += other.SeriesTouched m.SeriesTouchedSizeSum += other.SeriesTouchedSizeSum diff --git a/pkg/store/hintspb/custom_test.go b/pkg/store/hintspb/custom_test.go new file mode 100644 index 0000000000..3d9691f7c1 --- /dev/null +++ b/pkg/store/hintspb/custom_test.go @@ -0,0 +1,33 @@ +// Copyright (c) The Thanos Authors. +// Licensed under the Apache License 2.0. + +package hintspb + +import ( + "reflect" + "testing" + + "github.com/efficientgo/core/testutil" +) + +func TestQueryStatsMerge(t *testing.T) { + s := &QueryStats{} + ps := reflect.Indirect(reflect.ValueOf(s)) + for i := 0; i < ps.NumField(); i++ { + ps.FieldByIndex([]int{i}).SetInt(int64(1)) + } + o := &QueryStats{} + po := reflect.Indirect(reflect.ValueOf(o)) + for i := 0; i < po.NumField(); i++ { + po.FieldByIndex([]int{i}).SetInt(int64(100)) + } + s.Merge(o) + + // Expected stats. + e := &QueryStats{} + pe := reflect.Indirect(reflect.ValueOf(e)) + for i := 0; i < pe.NumField(); i++ { + pe.FieldByIndex([]int{i}).SetInt(int64(101)) + } + testutil.Equals(t, e, s) +}