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
7d447cc5
Commit
7d447cc5
authored
Nov 28, 2019
by
Sarah Yasonik
Committed by
Sean McGivern
Nov 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept user-defined dashboard uids in Grafana embeds
parent
41884a8b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
1 deletion
+67
-1
app/services/metrics/dashboard/grafana_metric_embed_service.rb
...ervices/metrics/dashboard/grafana_metric_embed_service.rb
+1
-1
changelogs/unreleased/sy-grafana-fix-uid.yml
changelogs/unreleased/sy-grafana-fix-uid.yml
+5
-0
spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb
...es/metrics/dashboard/grafana_metric_embed_service_spec.rb
+61
-0
No files found.
app/services/metrics/dashboard/grafana_metric_embed_service.rb
View file @
7d447cc5
...
@@ -133,7 +133,7 @@ module Metrics
...
@@ -133,7 +133,7 @@ module Metrics
def
uid_regex
def
uid_regex
base_url
=
@project
.
grafana_integration
.
grafana_url
.
chomp
(
'/'
)
base_url
=
@project
.
grafana_integration
.
grafana_url
.
chomp
(
'/'
)
%r{
(
#{
Regexp
.
escape
(
base_url
)
}
\/
d
\/
(?<uid>
\w
+)
\/
)}x
%r{
^(
#{
Regexp
.
escape
(
base_url
)
}
\/
d
\/
(?<uid>.
+)
\/
)}x
end
end
end
end
...
...
changelogs/unreleased/sy-grafana-fix-uid.yml
0 → 100644
View file @
7d447cc5
---
title
:
Accept user-defined dashboard uids in Grafana embeds
merge_request
:
20486
author
:
type
:
fixed
spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb
View file @
7d447cc5
...
@@ -175,3 +175,64 @@ describe Metrics::Dashboard::GrafanaMetricEmbedService do
...
@@ -175,3 +175,64 @@ describe Metrics::Dashboard::GrafanaMetricEmbedService do
end
end
end
end
end
end
describe
Metrics
::
Dashboard
::
GrafanaUidParser
do
let_it_be
(
:grafana_integration
)
{
create
(
:grafana_integration
)
}
let_it_be
(
:project
)
{
grafana_integration
.
project
}
subject
{
described_class
.
new
(
grafana_url
,
project
).
parse
}
context
'with a Grafana-defined uid'
do
let
(
:grafana_url
)
{
grafana_integration
.
grafana_url
+
'/d/XDaNK6amz/?panelId=1'
}
it
{
is_expected
.
to
eq
'XDaNK6amz'
}
end
context
'with a user-defined uid'
do
let
(
:grafana_url
)
{
grafana_integration
.
grafana_url
+
'/d/pgbouncer-main/pgbouncer-overview?panelId=1'
}
it
{
is_expected
.
to
eq
'pgbouncer-main'
}
end
context
'when a uid is not present'
do
let
(
:grafana_url
)
{
grafana_integration
.
grafana_url
}
it
{
is_expected
.
to
be
nil
}
end
context
'when the url starts with unrelated content'
do
let
(
:grafana_url
)
{
'js:'
+
grafana_integration
.
grafana_url
}
it
{
is_expected
.
to
be
nil
}
end
end
describe
Metrics
::
Dashboard
::
DatasourceNameParser
do
include
GrafanaApiHelpers
let
(
:grafana_url
)
{
valid_grafana_dashboard_link
(
'https://gitlab.grafana.net'
)
}
let
(
:grafana_dashboard
)
{
JSON
.
parse
(
fixture_file
(
'grafana/dashboard_response.json'
),
symbolize_names:
true
)
}
subject
{
described_class
.
new
(
grafana_url
,
grafana_dashboard
).
parse
}
it
{
is_expected
.
to
eq
'GitLab Omnibus'
}
context
'when the panelId is missing from the url'
do
let
(
:grafana_url
)
{
'https:/gitlab.grafana.net/d/jbdbks/'
}
it
{
is_expected
.
to
be
nil
}
end
context
'when the panel is not present'
do
# We're looking for panelId of 8, but only 6 is present
let
(
:grafana_dashboard
)
{
{
dashboard:
{
panels:
[{
id:
6
}]
}
}
}
it
{
is_expected
.
to
be
nil
}
end
context
'when the dashboard panel does not have a datasource'
do
let
(
:grafana_dashboard
)
{
{
dashboard:
{
panels:
[{
id:
8
}]
}
}
}
it
{
is_expected
.
to
be
nil
}
end
end
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