Skip to content

Commit

Permalink
stats: Add Counts() method to multi counter type.
Browse files Browse the repository at this point in the history
An existing test used this functionality. When we stopped exporting the
"counters" type, the test lost that functionality. Instead of relying on
an implementation detail, there is a proper public method now.

Signed-off-by: Michael Berlin <mberlin@google.com>
  • Loading branch information
michael-berlin committed Apr 21, 2018
1 parent 8b2491a commit 9a1fc3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions go/stats/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ func (mc *CountersWithMultiLabels) Reset(names []string) {
mc.counters.Reset(mapKey(names))
}

// Counts returns a copy of the Counters' map.
// The key is a single string where all labels are joiend by a "." e.g.
// "label1.label2".
func (mc *CountersWithMultiLabels) Counts() map[string]int64 {
return mc.counters.Counts()
}

// GaugesWithMultiLabels is a CountersWithMultiLabels implementation where the values can go up and down
type GaugesWithMultiLabels struct {
CountersWithMultiLabels
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,13 +1821,13 @@ func TestQueryExecutorTableAclDryRun(t *testing.T) {
qre := newTestQueryExecutor(ctx, tsv, query, 0)
defer tsv.StopService()
checkPlanID(t, planbuilder.PlanPassSelect, qre.plan.PlanID)
beforeCount := tabletenv.TableaclPseudoDenied.Counters.Counts()[tableACLStatsKey]
beforeCount := tabletenv.TableaclPseudoDenied.Counts()[tableACLStatsKey]
// query should fail because current user do not have read permissions
_, err := qre.Execute()
if err != nil {
t.Fatalf("qre.Execute() = %v, want: nil", err)
}
afterCount := tabletenv.TableaclPseudoDenied.Counters.Counts()[tableACLStatsKey]
afterCount := tabletenv.TableaclPseudoDenied.Counts()[tableACLStatsKey]
if afterCount-beforeCount != 1 {
t.Fatalf("table acl pseudo denied count should increase by one. got: %d, want: %d", afterCount, beforeCount+1)
}
Expand Down

0 comments on commit 9a1fc3f

Please sign in to comment.