|
7 | 7 |
|
8 | 8 | "github.com/github/freno/pkg/base" |
9 | 9 | "github.com/github/freno/pkg/config" |
| 10 | + metrics "github.com/rcrowley/go-metrics" |
10 | 11 | "github.com/stretchr/testify/assert" |
11 | 12 | ) |
12 | 13 |
|
@@ -247,6 +248,7 @@ func TestCheckMySQLRequiredClusters(t *testing.T) { |
247 | 248 | assert.Equal(t, http.StatusTooManyRequests, result.StatusCode) |
248 | 249 | assert.Equal(t, 60.0, result.Value) |
249 | 250 | assert.Equal(t, 50.0, result.Threshold) |
| 251 | + assert.Equal(t, "mysql/primary", result.MetricName) |
250 | 252 | }) |
251 | 253 |
|
252 | 254 | t.Run("ProxySQL cluster blocks admission", func(t *testing.T) { |
@@ -275,6 +277,7 @@ func TestCheckMySQLRequiredClusters(t *testing.T) { |
275 | 277 | result := check.Check("transitions", "mysql", "replicas", "", &CheckFlags{OKIfNotExists: true}) |
276 | 278 | assert.Equal(t, http.StatusInternalServerError, result.StatusCode) |
277 | 279 | assert.EqualError(t, result.Error, `required MySQL cluster metric "primary" is unavailable`) |
| 280 | + assert.Equal(t, "mysql/primary", result.MetricName) |
278 | 281 | }) |
279 | 282 | } |
280 | 283 |
|
@@ -337,3 +340,31 @@ func TestStabilizeMySQLMetricResetsRecoveryWindow(t *testing.T) { |
337 | 340 | _, err := result.Get() |
338 | 341 | assert.Equal(t, base.RecoveryNotCompleteError, err) |
339 | 342 | } |
| 343 | + |
| 344 | +func TestStabilizeMySQLMetricRequiresHealthyWindowAfterStartup(t *testing.T) { |
| 345 | + originalSettings := config.Settings().Stores.MySQL |
| 346 | + defer func() { |
| 347 | + config.Settings().Stores.MySQL = originalSettings |
| 348 | + }() |
| 349 | + |
| 350 | + config.Settings().Stores.MySQL = config.MySQLConfigurationSettings{ |
| 351 | + Clusters: map[string]*config.MySQLClusterConfigurationSettings{ |
| 352 | + "primary": { |
| 353 | + ThrottleThreshold: 50.0, |
| 354 | + RecoveryDurationMillis: 5000, |
| 355 | + }, |
| 356 | + }, |
| 357 | + } |
| 358 | + |
| 359 | + throttler := NewThrottler() |
| 360 | + start := time.Date(2026, time.September, 23, 12, 0, 0, 0, time.UTC) |
| 361 | + |
| 362 | + result := throttler.stabilizeMySQLMetric("primary", base.NewSimpleMetricResult(30), start) |
| 363 | + _, err := result.Get() |
| 364 | + assert.Equal(t, base.RecoveryNotCompleteError, err) |
| 365 | + |
| 366 | + result = throttler.stabilizeMySQLMetric("primary", base.NewSimpleMetricResult(30), start.Add(5*time.Second)) |
| 367 | + _, err = result.Get() |
| 368 | + assert.Nil(t, err) |
| 369 | + assert.Equal(t, int64(0), metrics.Get("recovery.mysql.primary.active").(metrics.Gauge).Value()) |
| 370 | +} |
0 commit comments