Skip to content

Commit

Permalink
Add a link to kibana logs with time range filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinothkannans committed Nov 20, 2019
1 parent cda4fb4 commit 3361718
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Expand Up @@ -68,7 +68,8 @@ def receive_grouped_alerts
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
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/concerns/alert_post_mixin.rb
Expand Up @@ -65,6 +65,9 @@ def thead(alerts, datacenter, external_link)
cells += " --- |"
end

headers += " |"
cells += " --- |"

"#{headers}\n#{cells}"
end

Expand All @@ -75,6 +78,8 @@ def alert_item(alert)
item += " #{description} |"
end

item += " [:file_folder:](#{logs_link(alert)}) |"

item
end

Expand Down Expand Up @@ -110,6 +115,14 @@ def alert_link(alert)
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
Expand Down
1 change: 1 addition & 0 deletions app/jobs/regular/process_grouped_alerts.rb
Expand Up @@ -12,6 +12,7 @@ def execute(args)
token = args[:token]
data = JSON.parse(args[:data])
graph_url = args[:graph_url]
logs_url = args[:logs_url]

receiver = PluginStore.get(
::DiscoursePrometheusAlertReceiver::PLUGIN_NAME,
Expand Down

1 comment on commit 3361718

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.