From b819708599d31276b49869f46c06f202ec584eca Mon Sep 17 00:00:00 2001 From: Emily S Date: Tue, 14 Apr 2020 14:37:47 +0200 Subject: [PATCH] Ensure that the running agent's config is used when restarted (#763) * Ensure that the running agent's config is used when restarted * Add changelog entry --- CHANGELOG.asciidoc | 1 + lib/elastic_apm.rb | 2 +- spec/elastic_apm_spec.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5662e8b60..7540526c7 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -50,6 +50,7 @@ endif::[] - Ensure that the log level is updated for the config's logger when value is changed {pull}755[#755] - Set config `false` values to `false`, not `nil` {pull}761[#761] +- Ensure that the previously running agent's config is used in `ElasticAPM.restart` {pull}763[#763] [float] ===== Added diff --git a/lib/elastic_apm.rb b/lib/elastic_apm.rb index c0ed0aa38..87a7494b9 100644 --- a/lib/elastic_apm.rb +++ b/lib/elastic_apm.rb @@ -51,7 +51,7 @@ def stop # one, if it is provided. # Starts the agent if it is not running. # Stops and starts the agent if it is running. - def restart(config = {}) + def restart(config = nil) config ||= agent&.config stop if running? start(config) diff --git a/spec/elastic_apm_spec.rb b/spec/elastic_apm_spec.rb index f85f9972a..9b9b86bd2 100644 --- a/spec/elastic_apm_spec.rb +++ b/spec/elastic_apm_spec.rb @@ -36,12 +36,21 @@ end end context 'when a new config is passed' do + before { ElasticAPM.start } it 'restarts the agent with the new config' do ElasticAPM.restart(api_buffer_size: 10) expect(ElasticAPM::Agent).to be_running expect(ElasticAPM.agent.config.api_buffer_size).to be(10) end end + context 'when no new config is passed' do + before { ElasticAPM.start(api_buffer_size: 10) } + it 'restarts the agent with the same config' do + ElasticAPM.restart + expect(ElasticAPM::Agent).to be_running + expect(ElasticAPM.agent.config.api_buffer_size).to be(10) + end + end end context 'when running', :mock_intake do