Currently the Metrics use a singleton instance of the Collector to save or access the metric store. This make accessing it really simple but cause other issues when testing it ( see https://github.com/elastic/logstash/issues/5291)
I suggest we do the following refactor:
PeriodPoller restarted.metric accessor to gain access to the collector.Because of #5400 I've switched the priority to P1 and will go ahead with the refactor.
cc @andrewvc
One other improvement would be to use a lazy cache to synchronize snapshots rather than a thread that does this periodically. It would fix initialization order issues and be a simpler design. We would need code like:
def snapshot
@snapshot_mutex.synchronize do
# nano time is monotonic
return @snapshot if @snapshot.last_updated + 1sInNanos > System.nano_time
@snapshot = make_new_snapshot
end
end
Even with removing the singleton, the LogStash::Agent metrics after config reloading resets the metric collector is still failling. Doing a bit more digging.
I think it might be related to the test case and the agent doesnt reload the new configuration.
I've moved stuff around, to know this.
faillings test fixed, thread safety when we were creating pipelining and settings the metric.
I finished doing this refactor, I will run the test on a dedicated box to make sure we dont have any issue like #5400.
Most helpful comment
faillings test fixed, thread safety when we were creating pipelining and settings the metric.