Skip to content

Commit

Permalink
Throttler: refactor stats variables (#15574)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Mar 26, 2024
1 parent e9c8d52 commit 7355d99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions go/vt/vttablet/tabletserver/throttle/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const (
selfCheckInterval = 250 * time.Millisecond
)

var (
statsThrottlerCheckAnyTotal = stats.NewCounter("ThrottlerCheckAnyTotal", "total number of checks")
statsThrottlerCheckAnyError = stats.GetOrNewCounter("ThrottlerCheckAnyError", "total number of failed checks")
)

// CheckFlags provide hints for a check
type CheckFlags struct {
ReadCheck bool
Expand Down Expand Up @@ -151,11 +156,11 @@ func (check *ThrottlerCheck) Check(ctx context.Context, appName string, storeTyp
check.throttler.markRecentApp(appName, remoteAddr)
if !throttlerapp.VitessName.Equals(appName) {
go func(statusCode int) {
stats.GetOrNewCounter("ThrottlerCheckAnyTotal", "total number of checks").Add(1)
statsThrottlerCheckAnyTotal.Add(1)
stats.GetOrNewCounter(fmt.Sprintf("ThrottlerCheckAny%s%sTotal", textutil.SingleWordCamel(storeType), textutil.SingleWordCamel(storeName)), "").Add(1)

if statusCode != http.StatusOK {
stats.GetOrNewCounter("ThrottlerCheckAnyError", "total number of failed checks").Add(1)
statsThrottlerCheckAnyError.Add(1)
stats.GetOrNewCounter(fmt.Sprintf("ThrottlerCheckAny%s%sError", textutil.SingleWordCamel(storeType), textutil.SingleWordCamel(storeName)), "").Add(1)
}
}(checkResult.StatusCode)
Expand Down
12 changes: 9 additions & 3 deletions go/vt/vttablet/tabletserver/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ var (
throttleTabletTypes = "replica"
)

var (
statsThrottlerHeartbeatRequests = stats.NewCounter("ThrottlerHeartbeatRequests", "heartbeat requests")
statsThrottlerRecentlyChecked = stats.NewCounter("ThrottlerRecentlyChecked", "recently checked")
statsThrottlerProbeRecentlyChecked = stats.NewCounter("ThrottlerProbeRecentlyChecked", "probe recently checked")
)

func init() {
servenv.OnParseFor("vtcombo", registerThrottlerFlags)
servenv.OnParseFor("vttablet", registerThrottlerFlags)
Expand Down Expand Up @@ -577,7 +583,7 @@ func (throttler *Throttler) requestHeartbeats() {
return
}
go throttler.heartbeatWriter.RequestHeartbeats()
go stats.GetOrNewCounter("ThrottlerHeartbeatRequests", "heartbeat requests").Add(1)
statsThrottlerHeartbeatRequests.Add(1)
}

// stimulatePrimaryThrottler sends a check request to the primary tablet in the shard, to stimulate
Expand Down Expand Up @@ -852,7 +858,7 @@ func (throttler *Throttler) generateTabletProbeFunction(ctx context.Context, clu
// We have just probed a tablet, and it reported back that someone just recently "check"ed it.
// We therefore renew the heartbeats lease.
throttler.requestHeartbeats()
go stats.GetOrNewCounter("ThrottlerProbeRecentlyChecked", "probe recently checked").Add(1)
statsThrottlerProbeRecentlyChecked.Add(1)
}
return mySQLThrottleMetric
}
Expand Down Expand Up @@ -1256,7 +1262,7 @@ func (throttler *Throttler) checkStore(ctx context.Context, appName string, stor
// We mark the fact that someone just made a check. If this is a REPLICA or RDONLY tables, this will be reported back
// to the PRIMARY so that it knows it must renew the heartbeat lease.
checkResult.RecentlyChecked = true
go stats.GetOrNewCounter("ThrottlerRecentlyChecked", "recently checked").Add(1)
statsThrottlerRecentlyChecked.Add(1)
}

return checkResult
Expand Down

0 comments on commit 7355d99

Please sign in to comment.