This commit is contained in:
ANIRUDH 2025-08-05 20:03:00 +05:30 committed by GitHub
commit 7935e333f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 9 deletions

View File

@ -1195,7 +1195,8 @@ func main() {
g.Add(
func() error {
<-reloadReady.C
ticker := time.NewTicker(time.Duration(cfg.autoReloadInterval))
defer ticker.Stop()
for {
select {
case <-hup:
@ -1220,15 +1221,19 @@ func main() {
}
}
}
case <-time.Tick(time.Duration(cfg.autoReloadInterval)):
case <-ticker.C:
if !cfg.enableAutoReload {
continue
}
currentChecksum, err := config.GenerateChecksum(cfg.configFile)
if err != nil {
checksum = currentChecksum
logger.Error("Failed to generate checksum during configuration reload", "err", err)
} else if currentChecksum == checksum {
continue
}
if currentChecksum == checksum {
continue
}
logger.Info("Configuration file change detected, reloading the configuration.")
@ -1237,6 +1242,8 @@ func main() {
logger.Error("Error reloading config", "err", err)
} else {
checksum = currentChecksum
ticker.Stop()
ticker = time.NewTicker(time.Duration(cfg.autoReloadInterval))
}
case <-cancel:
return nil

View File

@ -417,7 +417,27 @@ func getCurrentGaugeValuesFor(t *testing.T, reg prometheus.Gatherer, metricNames
func TestAgentSuccessfulStartup(t *testing.T) {
t.Parallel()
prom := exec.Command(promPath, "-test.main", "--agent", "--web.listen-address=0.0.0.0:0", "--config.file="+agentConfig)
tempDir := t.TempDir()
configPath := filepath.Join(tempDir, "agent.yml")
configContent := `
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
`
require.NoError(t, os.WriteFile(configPath, []byte(configContent), 0o644))
prom := exec.Command(promPath,
"-test.main",
"--enable-feature=agent",
"--web.listen-address=0.0.0.0:0",
"--config.file="+configPath,
"--storage.tsdb.path="+filepath.Join(tempDir, "data"),
)
require.NoError(t, prom.Start())
actualExitStatus := 0
@ -428,8 +448,8 @@ func TestAgentSuccessfulStartup(t *testing.T) {
case err := <-done:
t.Logf("prometheus agent should be still running: %v", err)
actualExitStatus = prom.ProcessState.ExitCode()
case <-time.After(startupTime):
prom.Process.Kill()
case <-time.After(3 * time.Second):
_ = prom.Process.Kill()
}
require.Equal(t, 0, actualExitStatus)
}

View File

@ -137,9 +137,12 @@ func runTestSteps(t *testing.T, steps []struct {
require.NoError(t, os.WriteFile(configFilePath, []byte(step.configText), 0o644), "Failed to write config file for step")
require.Eventually(t, func() bool {
return verifyScrapeInterval(t, baseURL, step.expectedInterval) &&
verifyConfigReloadMetric(t, baseURL, step.expectedMetric)
if step.expectedMetric == 0 {
return verifyScrapeInterval(t, baseURL, step.expectedInterval) || verifyConfigReloadMetric(t, baseURL, step.expectedMetric)
}
return verifyScrapeInterval(t, baseURL, step.expectedInterval) && verifyConfigReloadMetric(t, baseURL, step.expectedMetric)
}, 10*time.Second, 500*time.Millisecond, "Prometheus config reload didn't happen in time")
}
}