Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttler: refactor stats variables #15574

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading