Class: Gitlab::Database::Reindexing::GrafanaNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/reindexing/grafana_notifier.rb

Overview

This can be used to send annotations for reindexing to a Grafana API

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_url: nil, additional_tag: nil) ⇒ GrafanaNotifier

Returns a new instance of GrafanaNotifier.



8
9
10
11
12
# File 'lib/gitlab/database/reindexing/grafana_notifier.rb', line 8

def initialize(api_key: nil, api_url: nil, additional_tag: nil)
  @api_key = api_key || default_api_key
  @api_url = api_url || default_api_url
  @additional_tag = additional_tag || default_additional_tag
end

Instance Method Details

#notify_end(action) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/database/reindexing/grafana_notifier.rb', line 24

def notify_end(action)
  return unless enabled?

  payload = base_payload(action).merge(
    text: "Finished reindexing of #{action.index.name} on #{action.index.tablename} (#{action.state})",
    timeEnd: (action.action_end.utc.to_f * 1000).to_i,
    isRegion: true
  )

  annotate(payload)
end

#notify_start(action) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/database/reindexing/grafana_notifier.rb', line 14

def notify_start(action)
  return unless enabled?

  payload = base_payload(action).merge(
    text: "Started reindexing of #{action.index.name} on #{action.index.tablename}"
  )

  annotate(payload)
end