Skip to content

Commit

Permalink
(PUP-12061) Handle changing splay in puppet.conf
Browse files Browse the repository at this point in the history
Previously, enabling or disabling splay in puppet.conf did not work if the
agent was already running periodically.

If the agent was started with splay disabled, then enabling it would cause a
NoMethodError, when trying to call Puppet::Scheduler::Job#splay_limit

If the agent was started with splay enabled, then disabling it would have no
effect, since we never recalculated the splay limit.

To handle these cases, always create a SplayJob for the agent_run job and set
its splay_limit to either the limit or 0, depending on whether splay is enabled
or not. Setting a splay_limit to 0 causes the splay to also be set to 0 because
rand(1) always returns 0.
  • Loading branch information
joshcooper committed Sep 26, 2024
1 parent ccfcec2 commit f35b6d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def remove_pidfile

# Loop forever running events - or, at least, until we exit.
def run_event_loop
agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], Puppet[:splay], Puppet[:splaylimit]) do |job|
splaylimit = Puppet[:splay] ? Puppet[:splaylimit] : 0

agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], true, splaylimit) do |job|
if job.splay != 0
Puppet.info "Running agent every #{job.run_interval} seconds with splay #{job.splay} of #{job.splay_limit} seconds"
else
Expand All @@ -171,7 +173,7 @@ def run_event_loop
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
Puppet.settings.reparse_config_files
agent_run.run_interval = Puppet[:runinterval]
agent_run.splay_limit = Puppet[:splaylimit] if Puppet[:splay]
agent_run.splay_limit = Puppet[:splay] ? Puppet[:splaylimit] : 0
if Puppet[:filetimeout] == 0
reparse_run.disable
else
Expand Down
22 changes: 21 additions & 1 deletion spec/unit/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run_loop(jobs)

it "does not splay the agent run by default" do
daemon.start
expect(agent_run).to be_an_instance_of(Puppet::Scheduler::Job)
expect(agent_run.splay).to eq(0)
end

describe "and calculating splay" do
Expand Down Expand Up @@ -115,6 +115,26 @@ def run_loop(jobs)

expect(agent_run.splay).to eq(init_splay)
end

it "recalculates when splay is enabled later" do
Puppet[:splay] = false
daemon.start

Puppet[:splay] = true
allow(agent_run).to receive(:rand).and_return(999)
reparse_run.run(Time.now)

expect(agent_run.splay).to eq(999)
end

it "sets splay to 0 when splay is disabled" do
daemon.start

Puppet[:splay] = false
reparse_run.run(Time.now)

expect(agent_run.splay).to eq(0)
end
end
end

Expand Down

0 comments on commit f35b6d5

Please sign in to comment.