@@ -22,6 +22,7 @@ import (
2222 "io"
2323 "net/http"
2424 "runtime"
25+ "strconv"
2526 "strings"
2627 "sync"
2728 "testing"
5758 targetKsOpts = make (map [string ]string )
5859 httpClient = throttlebase .SetupHTTPClient (time .Second )
5960 sourceThrottlerAppName = throttlerapp .VStreamerName
60- targetThrottlerAppName = throttlerapp .VReplicationName
61+ targetThrottlerAppName = throttlerapp .VPlayerName
6162)
6263
6364const (
@@ -1196,6 +1197,8 @@ func materializeProduct(t *testing.T, useVtctldClient bool) {
11961197 // we expect the additional rows to **not appear** in the materialized view
11971198 for _ , tab := range customerTablets {
11981199 waitForRowCountInTablet (t , tab , keyspace , workflow , 5 )
1200+ // Confirm that we updated the stats on the target tablets as expected.
1201+ confirmVReplicationThrottling (t , tab , sourceKs , workflow , sourceThrottlerAppName )
11991202 }
12001203 })
12011204 t .Run ("unthrottle-app-product" , func (t * testing.T ) {
@@ -1229,6 +1232,8 @@ func materializeProduct(t *testing.T, useVtctldClient bool) {
12291232 // rows to **not appear** in the materialized view.
12301233 for _ , tab := range customerTablets {
12311234 waitForRowCountInTablet (t , tab , keyspace , workflow , 8 )
1235+ // Confirm that we updated the stats on the target tablets as expected.
1236+ confirmVReplicationThrottling (t , tab , sourceKs , workflow , targetThrottlerAppName )
12321237 }
12331238 })
12341239 t .Run ("unthrottle-app-customer" , func (t * testing.T ) {
@@ -1784,3 +1789,52 @@ func waitForInnoDBHistoryLength(t *testing.T, tablet *cluster.VttabletProcess, e
17841789func releaseInnoDBRowHistory (t * testing.T , dbConn * mysql.Conn ) {
17851790 execQuery (t , dbConn , "rollback" )
17861791}
1792+
1793+ // confirmVReplicationThrottling confirms that the throttling related metrics reflect that
1794+ // the workflow is being throttled as expected, via the expected app name, and that this
1795+ // is impacting the lag as expected.
1796+ // The tablet passed should be a target tablet for the given workflow while the keyspace
1797+ // name provided should be the source keyspace as the target tablet stats note the stream's
1798+ // source keyspace and shard.
1799+ func confirmVReplicationThrottling (t * testing.T , tab * cluster.VttabletProcess , keyspace , workflow string , appname throttlerapp.Name ) {
1800+ const (
1801+ sleepTime = 5 * time .Second
1802+ zv = int64 (0 )
1803+ )
1804+ time .Sleep (sleepTime ) // To be sure that we accrue some lag
1805+
1806+ jsVal , err := getDebugVar (t , tab .Port , []string {"VReplicationThrottledCounts" })
1807+ require .NoError (t , err )
1808+ require .NotEqual (t , "{}" , jsVal )
1809+ // The JSON value looks like this: {"cproduct.4.tablet.vstreamer": 2, "cproduct.4.tablet.vplayer": 4}
1810+ throttledCount := gjson .Get (jsVal , fmt .Sprintf (`%s\.*\.tablet\.%s` , workflow , appname )).Int ()
1811+ require .Greater (t , throttledCount , zv , "JSON value: %s" , jsVal )
1812+
1813+ val , err := getDebugVar (t , tab .Port , []string {"VReplicationThrottledCountTotal" })
1814+ require .NoError (t , err )
1815+ require .NotEqual (t , "" , val )
1816+ throttledCountTotal , err := strconv .ParseInt (val , 10 , 64 )
1817+ require .NoError (t , err )
1818+ require .GreaterOrEqual (t , throttledCountTotal , throttledCount , "Value: %s" , val )
1819+
1820+ // We do not calculate replication lag for the vcopier as it's not replicating
1821+ // events.
1822+ if appname != throttlerapp .VCopierName {
1823+ jsVal , err = getDebugVar (t , tab .Port , []string {"VReplicationLagSeconds" })
1824+ require .NoError (t , err )
1825+ require .NotEqual (t , "{}" , jsVal )
1826+ // The JSON value looks like this: {"product.0.cproduct.4": 6}
1827+ vreplLagSeconds := gjson .Get (jsVal , fmt .Sprintf (`%s\.*\.%s\.*` , keyspace , workflow )).Int ()
1828+ require .NoError (t , err )
1829+ // Take off 1 second to deal with timing issues in the test.
1830+ minLagSecs := int64 (int64 (sleepTime .Seconds ()) - 1 )
1831+ require .GreaterOrEqual (t , vreplLagSeconds , minLagSecs , "JSON value: %s" , jsVal )
1832+
1833+ val , err = getDebugVar (t , tab .Port , []string {"VReplicationLagSecondsMax" })
1834+ require .NoError (t , err )
1835+ require .NotEqual (t , "" , val )
1836+ vreplLagSecondsMax , err := strconv .ParseInt (val , 10 , 64 )
1837+ require .NoError (t , err )
1838+ require .GreaterOrEqual (t , vreplLagSecondsMax , vreplLagSeconds , "Value: %s" , val )
1839+ }
1840+ }
0 commit comments