Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b1c50a0a
Commit
b1c50a0a
authored
Jan 04, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional Grafana tag to distinguish environments
parent
734994d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
lib/gitlab/database/reindexing/grafana_notifier.rb
lib/gitlab/database/reindexing/grafana_notifier.rb
+3
-2
spec/lib/gitlab/database/reindexing/grafana_notifier_spec.rb
spec/lib/gitlab/database/reindexing/grafana_notifier_spec.rb
+5
-4
No files found.
lib/gitlab/database/reindexing/grafana_notifier.rb
View file @
b1c50a0a
...
@@ -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
...
...
spec/lib/gitlab/database/reindexing/grafana_notifier_spec.rb
View file @
b1c50a0a
...
@@ -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'
,
a
dditional_tag
,
a
ction
.
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'
,
a
dditional_tag
,
a
ction
.
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment