|
58 | 58 | targetKsOpts = make(map[string]string)
|
59 | 59 | httpClient = throttlebase.SetupHTTPClient(time.Second)
|
60 | 60 | sourceThrottlerAppName = throttlerapp.VStreamerName
|
61 |
| - targetThrottlerAppName = throttlerapp.VReplicationName |
| 61 | + targetThrottlerAppName = throttlerapp.VPlayerName |
62 | 62 | )
|
63 | 63 |
|
64 | 64 | const (
|
@@ -1199,18 +1199,7 @@ func materializeProduct(t *testing.T, useVtctldClient bool) {
|
1199 | 1199 | for _, tab := range customerTablets {
|
1200 | 1200 | waitForRowCountInTablet(t, tab, keyspace, workflow, 5)
|
1201 | 1201 | // Confirm that we updated the stats on the target tablets as expected.
|
1202 |
| - jsVal, err := getDebugVar(t, tab.Port, []string{"VReplicationThrottledCounts"}) |
1203 |
| - require.NoError(t, err) |
1204 |
| - require.NotEqual(t, "{}", jsVal) |
1205 |
| - // The JSON value looks like this: {"cproduct.4.tablet.vstreamer": 2} |
1206 |
| - vstreamerThrottledCount := gjson.Get(jsVal, fmt.Sprintf(`%s\.*\.tablet\.vstreamer`, workflow)).Int() |
1207 |
| - require.Greater(t, vstreamerThrottledCount, int64(0)) |
1208 |
| - // We only need to do this stat check once. |
1209 |
| - val, err := getDebugVar(t, tab.Port, []string{"VReplicationThrottledCountTotal"}) |
1210 |
| - require.NoError(t, err) |
1211 |
| - throttledCount, err := strconv.ParseInt(val, 10, 64) |
1212 |
| - require.NoError(t, err) |
1213 |
| - require.GreaterOrEqual(t, throttledCount, vstreamerThrottledCount) |
| 1202 | + confirmVReplicationThrottling(t, tab, sourceKs, workflow, sourceThrottlerAppName) |
1214 | 1203 | }
|
1215 | 1204 | })
|
1216 | 1205 | t.Run("unthrottle-app-product", func(t *testing.T) {
|
@@ -1245,12 +1234,7 @@ func materializeProduct(t *testing.T, useVtctldClient bool) {
|
1245 | 1234 | for _, tab := range customerTablets {
|
1246 | 1235 | waitForRowCountInTablet(t, tab, keyspace, workflow, 8)
|
1247 | 1236 | // Confirm that we updated the stats on the target tablets as expected.
|
1248 |
| - jsVal, err := getDebugVar(t, tab.Port, []string{"VReplicationThrottledCounts"}) |
1249 |
| - require.NoError(t, err) |
1250 |
| - require.NotEqual(t, "{}", jsVal) |
1251 |
| - // The JSON value now looks like this: {"cproduct.4.tablet.vstreamer": 2, "cproduct.4.tablet.vplayer": 4} |
1252 |
| - vplayerThrottledCount := gjson.Get(jsVal, fmt.Sprintf(`%s\.*\.tablet\.vplayer`, workflow)).Int() |
1253 |
| - require.Greater(t, vplayerThrottledCount, int64(0)) |
| 1237 | + confirmVReplicationThrottling(t, tab, sourceKs, workflow, targetThrottlerAppName) |
1254 | 1238 | }
|
1255 | 1239 | })
|
1256 | 1240 | t.Run("unthrottle-app-customer", func(t *testing.T) {
|
@@ -1806,3 +1790,52 @@ func waitForInnoDBHistoryLength(t *testing.T, tablet *cluster.VttabletProcess, e
|
1806 | 1790 | func releaseInnoDBRowHistory(t *testing.T, dbConn *mysql.Conn) {
|
1807 | 1791 | execQuery(t, dbConn, "rollback")
|
1808 | 1792 | }
|
| 1793 | + |
| 1794 | +// confirmVReplicationThrottling confirms that the throttling related metrics reflect that |
| 1795 | +// the workflow is being throttled as expected, via the expected app name, and that this |
| 1796 | +// is impacting the lag as expected. |
| 1797 | +// The tablet passed should be a target tablet for the given workflow while the keyspace |
| 1798 | +// name provided should be the source keyspace as the target tablet stats note the stream's |
| 1799 | +// source keyspace and shard. |
| 1800 | +func confirmVReplicationThrottling(t *testing.T, tab *cluster.VttabletProcess, keyspace, workflow string, appname throttlerapp.Name) { |
| 1801 | + const ( |
| 1802 | + sleepTime = 5 * time.Second |
| 1803 | + zv = int64(0) |
| 1804 | + ) |
| 1805 | + time.Sleep(sleepTime) // To be sure that we accrue some lag |
| 1806 | + |
| 1807 | + jsVal, err := getDebugVar(t, tab.Port, []string{"VReplicationThrottledCounts"}) |
| 1808 | + require.NoError(t, err) |
| 1809 | + require.NotEqual(t, "{}", jsVal) |
| 1810 | + // The JSON value looks like this: {"cproduct.4.tablet.vstreamer": 2, "cproduct.4.tablet.vplayer": 4} |
| 1811 | + throttledCount := gjson.Get(jsVal, fmt.Sprintf(`%s\.*\.tablet\.%s`, workflow, appname)).Int() |
| 1812 | + require.Greater(t, throttledCount, zv, "JSON value: %s", jsVal) |
| 1813 | + |
| 1814 | + val, err := getDebugVar(t, tab.Port, []string{"VReplicationThrottledCountTotal"}) |
| 1815 | + require.NoError(t, err) |
| 1816 | + require.NotEqual(t, "", val) |
| 1817 | + throttledCountTotal, err := strconv.ParseInt(val, 10, 64) |
| 1818 | + require.NoError(t, err) |
| 1819 | + require.GreaterOrEqual(t, throttledCountTotal, throttledCount, "Value: %s", val) |
| 1820 | + |
| 1821 | + // We do not calculate replication lag for the vcopier as it's not replicating |
| 1822 | + // events. |
| 1823 | + if appname != throttlerapp.VCopierName { |
| 1824 | + jsVal, err = getDebugVar(t, tab.Port, []string{"VReplicationLagSeconds"}) |
| 1825 | + require.NoError(t, err) |
| 1826 | + require.NotEqual(t, "{}", jsVal) |
| 1827 | + // The JSON value looks like this: {"product.0.cproduct.4": 6} |
| 1828 | + vreplLagSeconds := gjson.Get(jsVal, fmt.Sprintf(`%s\.*\.%s\.*`, keyspace, workflow)).Int() |
| 1829 | + require.NoError(t, err) |
| 1830 | + // Take off 1 second to deal with timing issues in the test. |
| 1831 | + minLagSecs := int64(int64(sleepTime.Seconds()) - 1) |
| 1832 | + require.GreaterOrEqual(t, vreplLagSeconds, minLagSecs, "JSON value: %s", jsVal) |
| 1833 | + |
| 1834 | + val, err = getDebugVar(t, tab.Port, []string{"VReplicationLagSecondsMax"}) |
| 1835 | + require.NoError(t, err) |
| 1836 | + require.NotEqual(t, "", val) |
| 1837 | + vreplLagSecondsMax, err := strconv.ParseInt(val, 10, 64) |
| 1838 | + require.NoError(t, err) |
| 1839 | + require.GreaterOrEqual(t, vreplLagSecondsMax, vreplLagSeconds, "Value: %s", val) |
| 1840 | + } |
| 1841 | +} |
0 commit comments