Skip to content

Commit 7c08745

Browse files
author
Jarret Lavallee
committed
(GH-81) Handle an empty array when PuppetDB is down
Prior to this commit, the collection would fail with a undefined method when there was a PuppetDB instance that was offline. This commit adds a check to ensure that the undefined method error does not happen, while maintaining the error array. This was reproducable by stopping PuppetDB and running PuppetDB collection. It would previously fail to do the collection and throw an exception. After this commnit, the collection will complete and the error array will be updated with the connection failure.
1 parent da73e8d commit 7c08745

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

files/pe_metrics.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ def retrieve_additional_metrics(host, port, use_ssl, metrics_type, metrics)
124124

125125
host_url = generate_host_url(host, port, use_ssl)
126126

127+
metrics_array = []
127128
endpoint = "#{host_url}/metrics/v2/read"
128129
metrics_output = post_endpoint(endpoint, use_ssl, metrics.to_json)
130+
return metrics_array if metrics_output.empty?
129131

130-
metrics_array = []
131132
metrics.each_index do |index|
132133
metric_name = metrics[index]['name']
133134
metric_data = metrics_output[index]

0 commit comments

Comments
 (0)