Add a link to kibana logs with time range filter.

Add a link to kibana logs with time range filter.

diff --git a/app/controllers/discourse_prometheus_alert_receiver/receiver_controller.rb b/app/controllers/discourse_prometheus_alert_receiver/receiver_controller.rb
index e285bd2..4c1cdf1 100644
--- a/app/controllers/discourse_prometheus_alert_receiver/receiver_controller.rb
+++ b/app/controllers/discourse_prometheus_alert_receiver/receiver_controller.rb
@@ -68,7 +68,8 @@ module DiscoursePrometheusAlertReceiver
       Jobs.enqueue(:process_grouped_alerts,
         token: @token,
         data: params[:data].to_json,
-        graph_url: params[:graphURL]
+        graph_url: params[:graphURL],
+        logs_url: params[:logsURL]
       )
 
       render json: success_json
diff --git a/app/jobs/concerns/alert_post_mixin.rb b/app/jobs/concerns/alert_post_mixin.rb
index 49f5576..0fef3fb 100644
--- a/app/jobs/concerns/alert_post_mixin.rb
+++ b/app/jobs/concerns/alert_post_mixin.rb
@@ -65,6 +65,9 @@ module AlertPostMixin
       cells += " --- |"
     end
 
+    headers += " |"
+    cells += " --- |"
+
     "#{headers}\n#{cells}"
   end
 
@@ -75,6 +78,8 @@ module AlertPostMixin
       item += " #{description} |"
     end
 
+    item += " [:file_folder:](#{logs_link(alert)}) |"
+
     item
   end
 
@@ -110,6 +115,14 @@ module AlertPostMixin
     url.to_s
   end
 
+  def logs_link(alert)
+    url = "#{alert['logs_url']}#/discover"
+    begin_t = Time.parse(alert['starts_at'])
+    end_t   = Time.parse(alert['ends_at']) rescue Time.zone.now
+
+    "#{url}?_g=(time:(from:'#{begin_t}',mode:absolute,to:'#{end_t}'))"
+  end
+
   def prev_topic_link(topic_id)
     return "" if topic_id.nil?
     created_at = Topic.where(id: topic_id).pluck(:created_at).first
diff --git a/app/jobs/regular/process_grouped_alerts.rb b/app/jobs/regular/process_grouped_alerts.rb
index f26f2f1..a7fa901 100644
--- a/app/jobs/regular/process_grouped_alerts.rb
+++ b/app/jobs/regular/process_grouped_alerts.rb
@@ -12,6 +12,7 @@ module Jobs
       token = args[:token]
       data = JSON.parse(args[:data])
       graph_url = args[:graph_url]
+      logs_url = args[:logs_url]
 
       receiver = PluginStore.get(
         ::DiscoursePrometheusAlertReceiver::PLUGIN_NAME,

GitHub sha: 33617184

1 Like

fix the spec