File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,7 +72,11 @@ def id
7272 # main task terminates
7373 def do_close
7474 @logger . debug ( "Closing" , :plugin => self . class . name )
75- close
75+ begin
76+ close
77+ ensure
78+ LogStash ::PluginMetadata . delete_for_plugin ( self . id )
79+ end
7680 end
7781
7882 # Subclasses should implement this close method if you need to perform any
Original file line number Diff line number Diff line change @@ -7,8 +7,7 @@ module LogStash
77 # `PluginMetadata` provides a space to store key/value metadata about a plugin, typically metadata about
88 # external resources that can be gleaned during plugin registration.
99 #
10- # Data is persisted across pipeline reloads, and no effort is made to clean up metadata from pipelines
11- # that no longer exist after a pipeline reload.
10+ # Data should not be persisted across pipeline reloads, and should be cleaned up after a pipeline reload
1211 #
1312 # - It MUST NOT be used to store processing state
1413 # - It SHOULD NOT be updated frequently.
@@ -28,6 +27,7 @@ module LogStash
2827 #
2928 # @since 7.1
3029 class PluginMetadata
30+ include LogStash ::Util ::Loggable
3131
3232 Thread . exclusive do
3333 @registry = ThreadSafe ::Cache . new unless defined? ( @registry )
@@ -63,6 +63,7 @@ def exists?(plugin_id)
6363 #
6464 # @return [Boolean]
6565 def delete_for_plugin ( plugin_id )
66+ logger . debug ( "Removing metadata for plugin #{ plugin_id } " )
6667 old_registry = @registry . delete ( plugin_id )
6768 old_registry . clear unless old_registry . nil?
6869 end
Original file line number Diff line number Diff line change @@ -328,6 +328,14 @@ def register; end
328328 expect ( old_value ) . to be_nil
329329 expect ( plugin_instance . plugin_metadata . get ( :foo ) ) . to eq ( new_value )
330330 end
331+
332+ it 'removes metadata when the plugin is closed' do
333+ new_value = 'foo'
334+ plugin_instance . plugin_metadata . set ( :foo , new_value )
335+ expect ( plugin_instance . plugin_metadata . get ( :foo ) ) . to eq ( new_value )
336+ plugin_instance . do_close
337+ expect ( plugin_instance . plugin_metadata . set? ( :foo ) ) . to be_falsey
338+ end
331339 end
332340 end
333341 end
You can’t perform that action at this time.
0 commit comments