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: CheckThrottlerResponseCode to replace HTTP status codes #16491

Merged
merged 2 commits into from
Jul 31, 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
95 changes: 62 additions & 33 deletions go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go

Large diffs are not rendered by default.

920 changes: 517 additions & 403 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Large diffs are not rendered by default.

102 changes: 93 additions & 9 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions go/vt/vttablet/tabletmanager/rpc_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (tm *TabletManager) CheckThrottler(ctx context.Context, req *tabletmanagerd
return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "nil checkResult")
}
resp := &tabletmanagerdatapb.CheckThrottlerResponse{
ResponseCode: throttle.ResponseCodeFromStatus(checkResult.ResponseCode, checkResult.StatusCode),
StatusCode: int32(checkResult.StatusCode),
Value: checkResult.Value,
Threshold: checkResult.Threshold,
Expand All @@ -64,22 +65,24 @@ func (tm *TabletManager) CheckThrottler(ctx context.Context, req *tabletmanagerd
}
for name, metric := range checkResult.Metrics {
resp.Metrics[name] = &tabletmanagerdatapb.CheckThrottlerResponse_Metric{
Name: name,
Scope: metric.Scope,
StatusCode: int32(metric.StatusCode),
Value: metric.Value,
Threshold: metric.Threshold,
Message: metric.Message,
Name: name,
Scope: metric.Scope,
StatusCode: int32(metric.StatusCode),
ResponseCode: throttle.ResponseCodeFromStatus(metric.ResponseCode, metric.StatusCode),
Value: metric.Value,
Threshold: metric.Threshold,
Message: metric.Message,
}
}
if len(checkResult.Metrics) == 0 {
// For backwards compatibility, when the checked tablet is of lower version, it does not return a
// matrics map, but only the one metric.
resp.Metrics[base.DefaultMetricName.String()] = &tabletmanagerdatapb.CheckThrottlerResponse_Metric{
StatusCode: int32(checkResult.StatusCode),
Value: checkResult.Value,
Threshold: checkResult.Threshold,
Message: checkResult.Message,
StatusCode: int32(checkResult.StatusCode),
ResponseCode: throttle.ResponseCodeFromStatus(checkResult.ResponseCode, checkResult.StatusCode),
Value: checkResult.Value,
Threshold: checkResult.Threshold,
Message: checkResult.Message,
}
}
if checkResult.Error != nil {
Expand Down Expand Up @@ -140,8 +143,9 @@ func (tm *TabletManager) GetThrottlerStatus(ctx context.Context, req *tabletmana
}
for _, recentApp := range status.RecentApps {
resp.RecentApps[recentApp.AppName] = &tabletmanagerdatapb.GetThrottlerStatusResponse_RecentApp{
CheckedAt: protoutil.TimeToProto(recentApp.CheckedAt),
StatusCode: int32(recentApp.StatusCode),
CheckedAt: protoutil.TimeToProto(recentApp.CheckedAt),
StatusCode: int32(recentApp.StatusCode),
ResponseCode: recentApp.ResponseCode,
}
}
return resp, nil
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vttablet/tabletserver/tabletserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"vitess.io/vitess/go/vt/mysqlctl"
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
querypb "vitess.io/vitess/go/vt/proto/query"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
Expand Down Expand Up @@ -1800,8 +1801,9 @@ func (tsv *TabletServer) registerThrottlerCheckHandlers() {
}
metricNames := tsv.lagThrottler.MetricNames(r.URL.Query()["m"])
checkResult := tsv.lagThrottler.Check(ctx, appName, metricNames, flags)
if checkResult.StatusCode == http.StatusNotFound && flags.OKIfNotExists {
if checkResult.ResponseCode == tabletmanagerdatapb.CheckThrottlerResponseCode_UNKNOWN_METRIC && flags.OKIfNotExists {
checkResult.StatusCode = http.StatusOK // 200
checkResult.ResponseCode = tabletmanagerdatapb.CheckThrottlerResponseCode_OK
}

if r.Method == http.MethodGet {
Expand Down
18 changes: 11 additions & 7 deletions go/vt/vttablet/tabletserver/throttle/base/recent_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ package base

import (
"time"

tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
)

// RecentApp indicates when an app was last checked
type RecentApp struct {
AppName string
CheckedAt time.Time
StatusCode int
AppName string
CheckedAt time.Time
StatusCode int
ResponseCode tabletmanagerdatapb.CheckThrottlerResponseCode
}

// NewRecentApp creates a RecentApp
func NewRecentApp(appName string, statusCode int) *RecentApp {
func NewRecentApp(appName string, statusCode int, responseCode tabletmanagerdatapb.CheckThrottlerResponseCode) *RecentApp {
result := &RecentApp{
AppName: appName,
CheckedAt: time.Now(),
StatusCode: statusCode,
AppName: appName,
CheckedAt: time.Now(),
StatusCode: statusCode,
ResponseCode: responseCode,
}
return result
}
Loading
Loading