7x Fix sub second config.reload.interval (#12611)

Clean backport of #12589

Due to a change in #11803, using `to_seconds` to normalize values of `config.reload.interval`
would resolve to a value of 0 causing issues in tests where short reload intervals were desired.
This commit uses the `to_nanos` method to preserve the previous functionality.

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
This commit is contained in:
Rob Bavey 2021-02-02 11:59:56 -05:00 committed by GitHub
parent 73154014cb
commit 656c2bfd42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -92,7 +92,9 @@ class LogStash::Agent
end end
# Normalize time interval to seconds # Normalize time interval to seconds
@reload_interval = setting("config.reload.interval").to_seconds # we can't do .to_seconds here as values under 1 seconds are rounded to 0
# so we get the nanos and convert to seconds instead.
@reload_interval = setting("config.reload.interval").to_nanos * 1e-9
@collect_metric = setting("metric.collect") @collect_metric = setting("metric.collect")

View file

@ -191,7 +191,9 @@ describe LogStash::Agent do
end end
it "it will keep trying to converge" do it "it will keep trying to converge" do
sleep(agent_settings.get("config.reload.interval").to_seconds * 20) # let the interval reload a few times # we can't do .to_seconds here as values under 1 seconds are rounded to 0
# causing a race condition in the test. So we get the nanos and convert to seconds
sleep(agent_settings.get("config.reload.interval").to_nanos * 1e-9 * 20) # let the interval reload a few times
expect(subject.pipelines_count).to eq(0) expect(subject.pipelines_count).to eq(0)
expect(source_loader.fetch_count).to be > 1 expect(source_loader.fetch_count).to be > 1
end end