debian-mirror-gitlab/spec/lib/gitlab/metrics/dashboard/url_spec.rb

214 lines
5.6 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Metrics::Dashboard::Url do
2020-05-24 23:13:21 +05:30
include Gitlab::Routing.url_helpers
2020-03-13 15:44:24 +05:30
describe '#metrics_regex' do
2020-11-24 15:15:51 +05:30
let(:environment_id) { 1 }
2020-05-24 23:13:21 +05:30
let(:url_params) do
[
2019-10-12 21:52:04 +05:30
'foo',
'bar',
2020-11-24 15:15:51 +05:30
environment_id,
2020-05-24 23:13:21 +05:30
{
start: '2019-08-02T05:43:09.000Z',
dashboard: 'config/prometheus/common_metrics.yml',
group: 'awesome group',
anchor: 'title'
}
]
2019-12-26 22:10:19 +05:30
end
2019-09-30 21:07:59 +05:30
2019-12-26 22:10:19 +05:30
let(:expected_params) do
{
2019-09-30 21:07:59 +05:30
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'environment' => '1',
2019-10-12 21:52:04 +05:30
'query' => '?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z',
2019-09-30 21:07:59 +05:30
'anchor' => '#title'
}
end
2020-03-13 15:44:24 +05:30
subject { described_class.metrics_regex }
2019-09-30 21:07:59 +05:30
2020-11-24 15:15:51 +05:30
context 'for /-/environments/:environment_id/metrics route' do
2020-05-24 23:13:21 +05:30
let(:url) { metrics_namespace_project_environment_url(*url_params) }
it_behaves_like 'regex which matches url when expected'
end
2020-11-24 15:15:51 +05:30
context 'for /-/metrics?environment=:environment_id route' do
let(:url) { namespace_project_metrics_dashboard_url(*url_params) }
let(:url_params) do
[
'namespace1',
'project1',
{
environment: environment_id,
start: '2019-08-02T05:43:09.000Z',
dashboard: 'config/prometheus/common_metrics.yml',
group: 'awesome group',
anchor: 'title'
}
]
end
let(:expected_params) do
{
'url' => url,
'namespace' => 'namespace1',
'project' => 'project1',
'environment' => "#{environment_id}",
'query' => "?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&environment=#{environment_id}&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z",
'anchor' => '#title'
}
end
it_behaves_like 'regex which matches url when expected'
end
2020-05-24 23:13:21 +05:30
context 'for metrics_dashboard route' do
let(:url) { metrics_dashboard_namespace_project_environment_url(*url_params) }
it_behaves_like 'regex which matches url when expected'
end
2019-12-26 22:10:19 +05:30
end
2019-09-30 21:07:59 +05:30
2020-07-28 23:09:34 +05:30
describe '#clusters_regex' do
2020-11-24 15:15:51 +05:30
let(:url) { Gitlab::Routing.url_helpers.namespace_project_cluster_url(*url_params) }
let(:url_params) do
[
2020-07-28 23:09:34 +05:30
'foo',
'bar',
'1',
2020-11-24 15:15:51 +05:30
{
group: 'Cluster Health',
title: 'Memory Usage',
y_label: 'Memory 20(GiB)',
anchor: 'title'
}
]
2020-07-28 23:09:34 +05:30
end
let(:expected_params) do
{
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'cluster_id' => '1',
'query' => '?group=Cluster+Health&title=Memory+Usage&y_label=Memory+20%28GiB%29',
'anchor' => '#title'
}
end
subject { described_class.clusters_regex }
it_behaves_like 'regex which matches url when expected'
2020-11-24 15:15:51 +05:30
context 'for metrics_dashboard route' do
let(:url) do
metrics_dashboard_namespace_project_cluster_url(
*url_params, cluster_type: :project, embedded: true, format: :json
)
end
let(:expected_params) do
{
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'cluster_id' => '1',
'query' => '?cluster_type=project&embedded=true',
'anchor' => nil
}
end
it_behaves_like 'regex which matches url when expected'
end
2020-07-28 23:09:34 +05:30
end
2019-12-26 22:10:19 +05:30
describe '#grafana_regex' do
let(:url) do
2020-05-24 23:13:21 +05:30
namespace_project_grafana_api_metrics_dashboard_url(
2019-12-26 22:10:19 +05:30
'foo',
'bar',
start: '2019-08-02T05:43:09.000Z',
dashboard: 'config/prometheus/common_metrics.yml',
group: 'awesome group',
anchor: 'title'
)
end
2019-09-30 21:07:59 +05:30
2019-12-26 22:10:19 +05:30
let(:expected_params) do
{
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'query' => '?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z',
'anchor' => '#title'
}
2019-09-30 21:07:59 +05:30
end
2019-12-26 22:10:19 +05:30
subject { described_class.grafana_regex }
2019-09-30 21:07:59 +05:30
2020-03-13 15:44:24 +05:30
it_behaves_like 'regex which matches url when expected'
2019-09-30 21:07:59 +05:30
end
2020-10-24 23:57:45 +05:30
describe '#alert_regex' do
2020-11-24 15:15:51 +05:30
let(:url) { Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url(*url_params) }
let(:url_params) do
[
2020-10-24 23:57:45 +05:30
'foo',
'bar',
'1',
2020-11-24 15:15:51 +05:30
{
start: '2020-02-10T12:59:49.938Z',
end: '2020-02-10T20:59:49.938Z',
anchor: "anchor"
}
]
2020-10-24 23:57:45 +05:30
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'
2020-11-24 15:15:51 +05:30
it_behaves_like 'regex which matches url when expected' do
let(:url) { Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url(*url_params, format: :json) }
let(:expected_params) do
{
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'alert' => '1',
'query' => nil,
'anchor' => nil
}
end
end
2020-10-24 23:57:45 +05:30
end
2019-09-30 21:07:59 +05:30
describe '#build_dashboard_url' do
it 'builds the url for the dashboard endpoint' do
url = described_class.build_dashboard_url('foo', 'bar', 1)
2020-03-13 15:44:24 +05:30
expect(url).to match described_class.metrics_regex
2019-09-30 21:07:59 +05:30
end
end
end