Commit b1c50a0a authored by Andreas Brandl's avatar Andreas Brandl

Additional Grafana tag to distinguish environments

parent 734994d4
...@@ -5,9 +5,10 @@ module Gitlab ...@@ -5,9 +5,10 @@ module Gitlab
module Reindexing module Reindexing
# This can be used to send annotations for reindexing to a Grafana API # This can be used to send annotations for reindexing to a Grafana API
class GrafanaNotifier class GrafanaNotifier
def initialize(api_key = ENV['GITLAB_GRAFANA_API_KEY'], api_url = ENV['GITLAB_GRAFANA_API_URL']) def initialize(api_key = ENV['GITLAB_GRAFANA_API_KEY'], api_url = ENV['GITLAB_GRAFANA_API_URL'], additional_tag = ENV['GITLAB_REINDEXING_GRAFANA_TAG'] || Rails.env)
@api_key = api_key @api_key = api_key
@api_url = api_url @api_url = api_url
@additional_tag = additional_tag
end end
def notify_start(action) def notify_start(action)
...@@ -37,7 +38,7 @@ module Gitlab ...@@ -37,7 +38,7 @@ module Gitlab
def base_payload(action) def base_payload(action)
{ {
time: (action.action_start.utc.to_f * 1000).to_i, time: (action.action_start.utc.to_f * 1000).to_i,
tags: ['reindex', action.index.tablename, action.index.name] tags: ['reindex', @additional_tag, action.index.tablename, action.index.name].compact
} }
end end
......
...@@ -7,6 +7,7 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do ...@@ -7,6 +7,7 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do
let(:api_key) { "foo" } let(:api_key) { "foo" }
let(:api_url) { "http://bar"} let(:api_url) { "http://bar"}
let(:additional_tag) { "some-tag" }
let(:action) { create(:reindex_action) } let(:action) { create(:reindex_action) }
...@@ -73,12 +74,12 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do ...@@ -73,12 +74,12 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do
end end
describe '#notify_start' do describe '#notify_start' do
subject { described_class.new(api_key, api_url).notify_start(action) } subject { described_class.new(api_key, api_url, additional_tag).notify_start(action) }
let(:payload) do let(:payload) do
{ {
time: (action.action_start.utc.to_f * 1000).to_i, time: (action.action_start.utc.to_f * 1000).to_i,
tags: ['reindex', action.index.tablename, action.index.name], tags: ['reindex', additional_tag, action.index.tablename, action.index.name],
text: "Started reindexing of #{action.index.name} on #{action.index.tablename}" text: "Started reindexing of #{action.index.name} on #{action.index.tablename}"
} }
end end
...@@ -87,12 +88,12 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do ...@@ -87,12 +88,12 @@ RSpec.describe Gitlab::Database::Reindexing::GrafanaNotifier do
end end
describe '#notify_end' do describe '#notify_end' do
subject { described_class.new(api_key, api_url).notify_end(action) } subject { described_class.new(api_key, api_url, additional_tag).notify_end(action) }
let(:payload) do let(:payload) do
{ {
time: (action.action_start.utc.to_f * 1000).to_i, time: (action.action_start.utc.to_f * 1000).to_i,
tags: ['reindex', action.index.tablename, action.index.name], tags: ['reindex', additional_tag, action.index.tablename, action.index.name],
text: "Finished reindexing of #{action.index.name} on #{action.index.tablename} (#{action.state})", text: "Finished reindexing of #{action.index.name} on #{action.index.tablename} (#{action.state})",
timeEnd: (action.action_end.utc.to_f * 1000).to_i, timeEnd: (action.action_end.utc.to_f * 1000).to_i,
isRegion: true isRegion: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment