From 390926c9ea73bfa1e8da1add0a9a20be70e51d30 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Thu, 1 Jun 2023 10:40:04 -0700 Subject: [PATCH] Fix series stats merge (#6408) * fix series stats merge Signed-off-by: Ben Ye * update license header Signed-off-by: Ben Ye * use reflect Signed-off-by: Ben Ye --------- Signed-off-by: Ben Ye --- pkg/store/hintspb/custom.go | 2 +- pkg/store/hintspb/custom_test.go | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pkg/store/hintspb/custom_test.go 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) +}