From 9f612ee9727c719d6d4ac8095e46f6600ec52ad2 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:42:02 +0200 Subject: [PATCH] Throttler: refactor stats variables Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vttablet/tabletserver/throttle/check.go | 9 +++++++-- go/vt/vttablet/tabletserver/throttle/throttler.go | 12 +++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/go/vt/vttablet/tabletserver/throttle/check.go b/go/vt/vttablet/tabletserver/throttle/check.go index 85952a496d1..98d887e8342 100644 --- a/go/vt/vttablet/tabletserver/throttle/check.go +++ b/go/vt/vttablet/tabletserver/throttle/check.go @@ -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 @@ -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) diff --git a/go/vt/vttablet/tabletserver/throttle/throttler.go b/go/vt/vttablet/tabletserver/throttle/throttler.go index 3a35818cb61..d59a7c92e7c 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler.go @@ -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) @@ -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 @@ -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 } @@ -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