18794: Add version and config metrics to workbench1.
authorTom Clegg <tom@curii.com>
Thu, 5 May 2022 14:53:32 +0000 (10:53 -0400)
committerTom Clegg <tom@curii.com>
Thu, 5 May 2022 14:53:32 +0000 (10:53 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

apps/workbench/app/controllers/management_controller.rb [moved from apps/workbench/app/controllers/healthcheck_controller.rb with 54% similarity]
apps/workbench/config/arvados_config.rb
apps/workbench/config/routes.rb

similarity index 54%
rename from apps/workbench/app/controllers/healthcheck_controller.rb
rename to apps/workbench/app/controllers/management_controller.rb
index 691bef8ee578bbd3beeb616906ac44a4df253631..4c8b52f6615f44b5c2765747eaa93f00a58aa3ec 100644 (file)
@@ -2,7 +2,9 @@
 #
 # SPDX-License-Identifier: AGPL-3.0
 
-class HealthcheckController < ApplicationController
+require 'app_version'
+
+class ManagementController < ApplicationController
   skip_around_action :thread_clear
   skip_around_action :set_thread_api_token
   skip_around_action :require_thread_api_token
@@ -28,7 +30,21 @@ class HealthcheckController < ApplicationController
     end
   end
 
-  def ping
+  def metrics
+    render content_type: 'text/plain', plain: <<~EOF
+# HELP arvados_config_load_timestamp_seconds Time when config file was loaded.
+# TYPE arvados_config_load_timestamp_seconds gauge
+arvados_config_load_timestamp_seconds{sha256="#{Rails.configuration.SourceSHA256}"} #{Rails.configuration.LoadTimestamp.to_f}
+# HELP arvados_config_source_timestamp_seconds Timestamp of config file when it was loaded.
+# TYPE arvados_config_source_timestamp_seconds gauge
+arvados_config_source_timestamp_seconds{sha256="#{Rails.configuration.SourceSHA256}"} #{Rails.configuration.SourceTimestamp.to_f}
+# HELP arvados_version_running Indicated version is running.
+# TYPE arvados_version_running gauge
+arvados_version_running{version="#{AppVersion.package_version}"} 1
+EOF
+  end
+
+  def health
     resp = {"health" => "OK"}
     render json: resp
   end
index 7cc46d2983490896c36e96c9081bf3e74013efa2..86b4a47539971e5aa9502676367227595d4179af 100644 (file)
@@ -21,6 +21,7 @@ require 'open3'
 
 # Load the defaults, used by config:migrate and fallback loading
 # legacy application.yml
+load_time = Time.now.utc
 defaultYAML, stderr, status = Open3.capture3("arvados-server", "config-dump", "-config=-", "-skip-legacy", stdin_data: "Clusters: {xxxxx: {}}")
 if !status.success?
   puts stderr
@@ -30,6 +31,8 @@ confs = YAML.load(defaultYAML, deserialize_symbols: false)
 clusterID, clusterConfig = confs["Clusters"].first
 $arvados_config_defaults = clusterConfig
 $arvados_config_defaults["ClusterID"] = clusterID
+$arvados_config_defaults["SourceTimestamp"] = Time.rfc3339(confs["SourceTimestamp"])
+$arvados_config_defaults["SourceSHA256"] = confs["SourceSHA256"]
 
 if ENV["ARVADOS_CONFIG"] == "none"
   # Don't load config. This magic value is set by packaging scripts so
@@ -45,6 +48,8 @@ else
       clusterID, clusterConfig = confs["Clusters"].first
       $arvados_config_global = clusterConfig
       $arvados_config_global["ClusterID"] = clusterID
+      $arvados_config_global["SourceTimestamp"] = Time.rfc3339(confs["SourceTimestamp"])
+      $arvados_config_global["SourceSHA256"] = confs["SourceSHA256"]
     else
       # config-dump failed, assume we will be loading from legacy
       # application.yml, initialize with defaults.
@@ -55,6 +60,7 @@ end
 
 # Now make a copy
 $arvados_config = $arvados_config_global.deep_dup
+$arvados_config["LoadTimestamp"] = load_time
 
 # Declare all our configuration items.
 arvcfg = ConfigLoader.new
index ffc09ac933acf8d88fa1b07cac460c144a805a45..0bf8dffc67be2602760b68a55f2d2bd1580ac303 100644 (file)
@@ -130,7 +130,8 @@ Rails.application.routes.draw do
 
   root :to => 'projects#index'
 
-  match '/_health/ping', to: 'healthcheck#ping', via: [:get]
+  match '/_health/:check', to: 'management#health', via: [:get]
+  match '/metrics', to: 'management#metrics', via: [:get]
 
   get '/tests/mithril', to: 'tests#mithril'