Skip to content

Commit

Permalink
Fix series stats merge (#6408)
Browse files Browse the repository at this point in the history
* fix series stats merge

Signed-off-by: Ben Ye <[email protected]>

* update license header

Signed-off-by: Ben Ye <[email protected]>

* use reflect

Signed-off-by: Ben Ye <[email protected]>

---------

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored Jun 1, 2023
1 parent eea398e commit 390926c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/store/hintspb/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions pkg/store/hintspb/custom_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 390926c

Please sign in to comment.