Skip to content

Commit

Permalink
Throttler: return app name in check result, synthesize "why throttled…
Browse files Browse the repository at this point in the history
…" explanation from result (#16416)

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Jul 28, 2024
1 parent 9aa9ab5 commit e341f23
Show file tree
Hide file tree
Showing 30 changed files with 1,218 additions and 491 deletions.
2 changes: 2 additions & 0 deletions go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ func TestSchemaChange(t *testing.T) {
assert.GreaterOrEqual(t, lastThrottledTimestamp, startedTimestamp)
component := row.AsString("component_throttled", "")
assert.Contains(t, []string{throttlerapp.VCopierName.String(), throttlerapp.VPlayerName.String()}, component)
reason := row.AsString("reason_throttled", "")
assert.Contains(t, reason, "is explicitly denied access")

// unthrottle
onlineddl.UnthrottleAllMigrations(t, &vtParams)
Expand Down
4 changes: 2 additions & 2 deletions go/vt/binlog/binlogplayer/binlog_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,11 @@ func GenerateUpdateHeartbeat(uid int32, timeUpdated int64) (string, error) {
}

// GenerateUpdateTimeThrottled returns a statement to record the latest throttle time in the _vt.vreplication table.
func GenerateUpdateTimeThrottled(uid int32, timeThrottledUnix int64, componentThrottled string) (string, error) {
func GenerateUpdateTimeThrottled(uid int32, timeThrottledUnix int64, componentThrottled string, reasonThrottled string) (string, error) {
if timeThrottledUnix == 0 {
return "", fmt.Errorf("timeUpdated cannot be zero")
}
return fmt.Sprintf("update _vt.vreplication set time_updated=%v, time_throttled=%v, component_throttled='%v' where id=%v", timeThrottledUnix, timeThrottledUnix, componentThrottled, uid), nil
return fmt.Sprintf("update _vt.vreplication set time_updated=%v, time_throttled=%v, component_throttled='%v', reason_throttled=%v where id=%v", timeThrottledUnix, timeThrottledUnix, componentThrottled, encodeString(MessageTruncate(reasonThrottled)), uid), nil
}

// StartVReplicationUntil returns a statement to start the replication with a stop position.
Expand Down
35 changes: 35 additions & 0 deletions go/vt/binlog/binlogplayer/binlog_player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/mysql/sqlerror"
querypb "vitess.io/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -454,3 +456,36 @@ func TestReadVReplicationStatus(t *testing.T) {
t.Errorf("ReadVReplicationStatus(482821) = %#v, want %#v", got, want)
}
}

func TestEncodeString(t *testing.T) {
tcases := []struct {
in, out string
}{
{
in: "",
out: "''",
},
{
in: "a",
out: "'a'",
},
{
in: "here's",
out: "'here\\'s'",
},
{
in: "online-ddl is denied access due to lag metric value 94.821447 exceeding threshold 5",
out: "'online-ddl is denied access due to lag metric value 94.821447 exceeding threshold 5'",
},
{
in: "'a','b','c'",
out: "'\\'a\\',\\'b\\',\\'c\\''",
},
}
for _, tcase := range tcases {
t.Run(tcase.in, func(t *testing.T) {
out := encodeString(tcase.in)
assert.Equal(t, tcase.out, out)
})
}
}
374 changes: 199 additions & 175 deletions go/vt/proto/binlogdata/binlogdata.pb.go

Large diffs are not rendered by default.

126 changes: 108 additions & 18 deletions go/vt/proto/binlogdata/binlogdata_vtproto.pb.go

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

Loading

0 comments on commit e341f23

Please sign in to comment.