FIX: use execute_command to run git rev-list

FIX: use execute_command to run git rev-list

execute_command properly raises a runtime error if it fails for any reason

This will keep @@version clean so it will recover if there is a temp git execution failure due to a low memory condition or similar

gauge returning -1 means that we are having trouble running git command gauge returning -2 means that we have given up running git command after 10 failures

diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
index 1b3e920..73e1ed2 100644
--- a/lib/internal_metric/global.rb
+++ b/lib/internal_metric/global.rb
@@ -31,13 +31,17 @@ module DiscoursePrometheus::InternalMetric
       @fault_logged = {}
 
       begin
-        @@version ||= `git rev-list --count HEAD`.to_i
+        @@version ||= Discourse::Utils.execute_command("git rev-list --count HEAD").to_i
       rescue => e
         Discourse.warn_exception(e, message: "Failed to calculate discourse_version metric")
-        @@version = 0
+        @@retries ||= 10
+        @@retries -= 1
+        if @@retries < 0
+          @@version = -1
+        end
       end
 
-      @version = @@version
+      @version = @@version || -2
     end
 
     def collect

GitHub sha: 39d6326a

1 Like