Compare commits

...

2 Commits

Author SHA1 Message Date
Max Kotliar
a679728f69 app/vmauth: increment config reload metric after reload auth config 2025-08-13 14:12:59 +03:00
Max Kotliar
335c614a7c apptest: Fix flaky TestSingleVMAuthRouterWithAuth
Do not check vmauth_config_last_reload_success_timestamp_seconds since
it may contain the timestamp < time.Now() due to how lib/fasttime works.

Instead, compare the number of config reloads.

follow up on
https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9369 and
https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9572

master:
```
$gotest -race ./apptest/tests/
-run=TestSingleVMAuthRouterWithInternalAddr -count=40
ok  	github.com/VictoriaMetrics/VictoriaMetrics/apptest/tests
	90.176s
```

pr:
```
$gotest -race ./apptest/tests/
-run=TestSingleVMAuthRouterWithInternalAddr -count=40
ok  	github.com/VictoriaMetrics/VictoriaMetrics/apptest/tests
	46.130s
```
2025-08-13 14:00:44 +03:00
3 changed files with 15 additions and 16 deletions

View File

@@ -627,8 +627,8 @@ func authConfigReloader(sighupCh <-chan os.Signal) {
}
updateFn := func() {
configReloads.Inc()
updated, err := reloadAuthConfig()
configReloads.Inc()
if err != nil {
logger.Errorf("failed to load auth config; using the last successfully loaded config; error: %s", err)
configSuccess.Set(0)

View File

@@ -123,9 +123,7 @@ func (app *Vmagent) ReloadRelabelConfigs(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
if currTotal <= prevTotal {
t.Fatalf("relabel configs were not reloaded after SIGHUP signal; previous total: %f, current total: %f", prevTotal, currTotal)
}
t.Fatalf("relabel configs were not reloaded after SIGHUP signal; previous total: %f, current total: %f", prevTotal, currTotal)
}
// sendBlocking sends the data to vmstorage by executing `send` function and

View File

@@ -56,31 +56,32 @@ func StartVmauth(instance string, flags []string, cli *Client, configFilePath st
}, nil
}
// UpdateConfiguration performs configuration file reload for app and waits for configuration apply
// UpdateConfiguration updates the vmauth configuration file with the provided YAML content,
// sends SIGHUP to trigger config reload
// and waits until vmauth_config_last_reload_total increases.
// Fails the test if no reload is detected within 2 seconds.
func (app *Vmauth) UpdateConfiguration(t *testing.T, configFileYAML string) {
t.Helper()
// Since the metric vmauth_config_last_reload_success_timestamp_seconds has second precision,
// we need to wait for at least 1 second before reloading the config to see the change.
time.Sleep(time.Millisecond * 1100)
ct := app.GetIntMetric(t, "vmauth_config_last_reload_success_timestamp_seconds")
fs.MustWriteSync(app.configFilePath, []byte(configFileYAML))
prevTotal := app.GetIntMetric(t, "vmauth_config_last_reload_total")
if err := app.process.Signal(syscall.SIGHUP); err != nil {
t.Fatalf("unexpected signal error: %s", err)
}
// Since the metric vmauth_config_last_reload_success_timestamp_seconds has second precision,
// we have to wait longer than 1 second to account for the worst case scenario.
for range 15 {
ts := app.GetIntMetric(t, "vmauth_config_last_reload_success_timestamp_seconds")
if ts > ct {
var currTotal int
for range 20 {
currTotal = app.GetIntMetric(t, "vmauth_config_last_reload_total")
if currTotal > prevTotal {
return
}
time.Sleep(time.Millisecond * 100)
}
t.Fatalf("timeout waiting for config reload success")
t.Fatalf("config were not reloaded after SIGHUP signal; previous total: %d, current total: %d", prevTotal, currTotal)
}
// GetHTTPListenAddr returns listen http addr