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
8f283c66
Commit
8f283c66
authored
Aug 18, 2020
by
Sarah Yasonik
Committed by
Sean McGivern
Aug 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move gitlab alert-based metric embeds to core
parent
73c1a822
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
85 additions
and
132 deletions
+85
-132
changelogs/unreleased/sy-move-alert-embeds-to-core.yml
changelogs/unreleased/sy-move-alert-embeds-to-core.yml
+5
-0
ee/lib/ee/banzai/filter/inline_metrics_redactor_filter.rb
ee/lib/ee/banzai/filter/inline_metrics_redactor_filter.rb
+0
-20
ee/lib/ee/gitlab/metrics/dashboard/url.rb
ee/lib/ee/gitlab/metrics/dashboard/url.rb
+0
-29
ee/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
.../lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
+0
-30
ee/spec/lib/ee/gitlab/metrics/dashboard/url_spec.rb
ee/spec/lib/ee/gitlab/metrics/dashboard/url_spec.rb
+0
-33
lib/banzai/filter/inline_alert_metrics_filter.rb
lib/banzai/filter/inline_alert_metrics_filter.rb
+0
-0
lib/banzai/filter/inline_metrics_redactor_filter.rb
lib/banzai/filter/inline_metrics_redactor_filter.rb
+4
-2
lib/gitlab/metrics/dashboard/url.rb
lib/gitlab/metrics/dashboard/url.rb
+33
-18
spec/lib/banzai/filter/inline_alert_metrics_filter_spec.rb
spec/lib/banzai/filter/inline_alert_metrics_filter_spec.rb
+0
-0
spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
.../lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
+15
-0
spec/lib/gitlab/metrics/dashboard/url_spec.rb
spec/lib/gitlab/metrics/dashboard/url_spec.rb
+28
-0
No files found.
changelogs/unreleased/sy-move-alert-embeds-to-core.yml
0 → 100644
View file @
8f283c66
---
title
:
Move gitlab-managed alerts embeds to core as documented
merge_request
:
39509
author
:
type
:
fixed
ee/lib/ee/banzai/filter/inline_metrics_redactor_filter.rb
deleted
100644 → 0
View file @
73c1a822
# frozen_string_literal: true
module
EE
module
Banzai
module
Filter
module
InlineMetricsRedactorFilter
extend
::
Gitlab
::
Utils
::
Override
ROUTE
=
::
Banzai
::
Filter
::
InlineMetricsRedactorFilter
::
Route
override
:permissions_by_route
def
permissions_by_route
super
.
concat
([
ROUTE
.
new
(
::
Gitlab
::
Metrics
::
Dashboard
::
Url
.
alert_regex
,
:read_prometheus_alerts
)
])
end
end
end
end
end
ee/lib/ee/gitlab/metrics/dashboard/url.rb
deleted
100644 → 0
View file @
73c1a822
# frozen_string_literal: true
# Manages url matching for metrics dashboards.
module
EE
module
Gitlab
module
Metrics
module
Dashboard
module
Url
# Matches dashboard urls for a metric chart embed
# for a specifc firing GitLab alert
#
# EX - https://<host>/<namespace>/<project>/prometheus/alerts/<alert_id>/metrics_dashboard
def
alert_regex
strong_memoize
(
:alert_regex
)
do
regex_for_project_metrics
(
%r{
/prometheus
/alerts
/(?<alert>
\d
+)
/metrics_dashboard
}x
)
end
end
end
end
end
end
end
ee/spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
deleted
100644 → 0
View file @
73c1a822
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Banzai
::
Filter
::
InlineMetricsRedactorFilter
do
include
FilterSpecHelper
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:input
)
{
%(<div class="js-render-metrics" data-dashboard-url="#{url}"></div>)
}
let
(
:doc
)
{
filter
(
input
)
}
context
'for an alert embed'
do
let_it_be
(
:alert
)
{
create
(
:prometheus_alert
,
project:
project
)
}
let
(
:url
)
do
urls
.
metrics_dashboard_project_prometheus_alert_url
(
project
,
alert
.
prometheus_metric_id
,
environment_id:
alert
.
environment_id
,
embedded:
true
)
end
before
do
stub_licensed_features
(
prometheus_alerts:
true
)
end
it_behaves_like
'redacts the embed placeholder'
it_behaves_like
'retains the embed placeholder when applicable'
end
end
ee/spec/lib/ee/gitlab/metrics/dashboard/url_spec.rb
deleted
100644 → 0
View file @
73c1a822
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Metrics
::
Dashboard
::
Url
do
describe
'#alert_regex'
do
let
(
:url
)
do
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_namespace_project_prometheus_alert_url
(
'foo'
,
'bar'
,
'1'
,
start:
'2020-02-10T12:59:49.938Z'
,
end:
'2020-02-10T20:59:49.938Z'
,
anchor:
"anchor"
)
end
let
(
:expected_params
)
do
{
'url'
=>
url
,
'namespace'
=>
'foo'
,
'project'
=>
'bar'
,
'alert'
=>
'1'
,
'query'
=>
"?end=2020-02-10T20%3A59%3A49.938Z&start=2020-02-10T12%3A59%3A49.938Z"
,
'anchor'
=>
'#anchor'
}
end
subject
{
described_class
.
alert_regex
}
it_behaves_like
'regex which matches url when expected'
end
end
ee/
lib/banzai/filter/inline_alert_metrics_filter.rb
→
lib/banzai/filter/inline_alert_metrics_filter.rb
View file @
8f283c66
File moved
lib/banzai/filter/inline_metrics_redactor_filter.rb
View file @
8f283c66
...
...
@@ -81,6 +81,10 @@ module Banzai
Route
.
new
(
::
Gitlab
::
Metrics
::
Dashboard
::
Url
.
clusters_regex
,
:read_cluster
),
Route
.
new
(
::
Gitlab
::
Metrics
::
Dashboard
::
Url
.
alert_regex
,
:read_prometheus_alerts
)
]
end
...
...
@@ -147,5 +151,3 @@ module Banzai
end
end
end
Banzai
::
Filter
::
InlineMetricsRedactorFilter
.
prepend_if_ee
(
'EE::Banzai::Filter::InlineMetricsRedactorFilter'
)
lib/gitlab/metrics/dashboard/url.rb
View file @
8f283c66
...
...
@@ -43,6 +43,39 @@ module Gitlab
end
end
# Matches dashboard urls for a metric chart embed
# for cluster metrics
#
# EX - https://<host>/<namespace>/<project>/-/clusters/<cluster_id>/?group=Cluster%20Health&title=Memory%20Usage&y_label=Memory%20(GiB)
def
clusters_regex
strong_memoize
(
:clusters_regex
)
do
regex_for_project_metrics
(
%r{
/clusters
/(?<cluster_id>
\d
+)
/?
}x
)
end
end
# Matches dashboard urls for a metric chart embed
# for a specifc firing GitLab alert
#
# EX - https://<host>/<namespace>/<project>/prometheus/alerts/<alert_id>/metrics_dashboard
def
alert_regex
strong_memoize
(
:alert_regex
)
do
regex_for_project_metrics
(
%r{
/prometheus
/alerts
/(?<alert>
\d
+)
/metrics_dashboard
}x
)
end
end
# Parses query params out from full url string into hash.
#
# Ex) 'https://<root>/<project>/<environment>/metrics?title=Title&group=Group'
...
...
@@ -60,22 +93,6 @@ module Gitlab
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_namespace_project_environment_url
(
*
args
)
end
# Matches dashboard urls for a metric chart embed
# for cluster metrics
#
# EX - https://<host>/<namespace>/<project>/-/clusters/<cluster_id>/?group=Cluster%20Health&title=Memory%20Usage&y_label=Memory%20(GiB)
def
clusters_regex
strong_memoize
(
:clusters_regex
)
do
regex_for_project_metrics
(
%r{
/clusters
/(?<cluster_id>
\d
+)
/?
}x
)
end
end
private
def
regex_for_project_metrics
(
path_suffix_pattern
)
...
...
@@ -107,5 +124,3 @@ module Gitlab
end
end
end
Gitlab
::
Metrics
::
Dashboard
::
Url
.
extend_if_ee
(
'::EE::Gitlab::Metrics::Dashboard::Url'
)
ee/
spec/lib/banzai/filter/inline_alert_metrics_filter_spec.rb
→
spec/lib/banzai/filter/inline_alert_metrics_filter_spec.rb
View file @
8f283c66
File moved
spec/lib/banzai/filter/inline_metrics_redactor_filter_spec.rb
View file @
8f283c66
...
...
@@ -74,5 +74,20 @@ RSpec.describe Banzai::Filter::InlineMetricsRedactorFilter do
end
end
end
context
'for an alert embed'
do
let_it_be
(
:alert
)
{
create
(
:prometheus_alert
,
project:
project
)
}
let
(
:url
)
do
urls
.
metrics_dashboard_project_prometheus_alert_url
(
project
,
alert
.
prometheus_metric_id
,
environment_id:
alert
.
environment_id
,
embedded:
true
)
end
it_behaves_like
'redacts the embed placeholder'
it_behaves_like
'retains the embed placeholder when applicable'
end
end
end
spec/lib/gitlab/metrics/dashboard/url_spec.rb
View file @
8f283c66
...
...
@@ -102,6 +102,34 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do
it_behaves_like
'regex which matches url when expected'
end
describe
'#alert_regex'
do
let
(
:url
)
do
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_namespace_project_prometheus_alert_url
(
'foo'
,
'bar'
,
'1'
,
start:
'2020-02-10T12:59:49.938Z'
,
end:
'2020-02-10T20:59:49.938Z'
,
anchor:
"anchor"
)
end
let
(
:expected_params
)
do
{
'url'
=>
url
,
'namespace'
=>
'foo'
,
'project'
=>
'bar'
,
'alert'
=>
'1'
,
'query'
=>
"?end=2020-02-10T20%3A59%3A49.938Z&start=2020-02-10T12%3A59%3A49.938Z"
,
'anchor'
=>
'#anchor'
}
end
subject
{
described_class
.
alert_regex
}
it_behaves_like
'regex which matches url when expected'
end
describe
'#build_dashboard_url'
do
it
'builds the url for the dashboard endpoint'
do
url
=
described_class
.
build_dashboard_url
(
'foo'
,
'bar'
,
1
)
...
...
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