diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /spec/lib/gitlab/metrics | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'spec/lib/gitlab/metrics')
19 files changed, 3 insertions, 1489 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/defaults_spec.rb b/spec/lib/gitlab/metrics/dashboard/defaults_spec.rb deleted file mode 100644 index b8556829a59..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/defaults_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require 'fast_spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Defaults do - it { is_expected.to be_const_defined(:DEFAULT_PANEL_TYPE) } -end diff --git a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb deleted file mode 100644 index d3cb9760052..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb +++ /dev/null @@ -1,178 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_caching do - include MetricsDashboardHelpers - - let_it_be(:project) { create(:project) } - let_it_be(:user) { create(:user) } - let_it_be(:environment) { create(:environment, project: project) } - - before do - project.add_maintainer(user) - end - - describe '.find' do - let(:dashboard_path) { '.gitlab/dashboards/test.yml' } - let(:service_call) { described_class.find(project, user, environment: environment, dashboard_path: dashboard_path) } - - it_behaves_like 'misconfigured dashboard service response', :not_found - - context 'when the dashboard exists' do - let(:project) { project_with_dashboard(dashboard_path) } - - it_behaves_like 'valid dashboard service response' - end - - context 'when the dashboard is configured incorrectly' do - let(:project) { project_with_dashboard(dashboard_path, {}) } - - it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity - end - - context 'when the dashboard contains a metric without a query' do - let(:dashboard) { { 'panel_groups' => [{ 'panels' => [{ 'metrics' => [{ 'id' => 'mock' }] }] }] } } - let(:project) { project_with_dashboard(dashboard_path, dashboard.to_yaml) } - - it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity - end - - context 'when the system dashboard is specified' do - let(:dashboard_path) { system_dashboard_path } - - it_behaves_like 'valid dashboard service response' - end - - context 'when no dashboard is specified' do - let(:service_call) { described_class.find(project, user, environment: environment) } - - it_behaves_like 'valid dashboard service response' - end - - context 'when the dashboard is expected to be embedded' do - let(:service_call) { described_class.find(project, user, **params) } - let(:params) { { environment: environment, embedded: true } } - - it_behaves_like 'valid embedded dashboard service response' - - context 'when params are incomplete' do - let(:params) { { environment: environment, embedded: true, dashboard_path: system_dashboard_path } } - - it_behaves_like 'valid embedded dashboard service response' - end - - context 'when the panel is specified' do - context 'as a custom metric' do - let(:params) do - { - environment: environment, - embedded: true, - dashboard_path: system_dashboard_path, - group: business_metric_title, - title: 'title', - y_label: 'y_label' - } - end - - it_behaves_like 'misconfigured dashboard service response', :not_found - - context 'when the metric exists' do - before do - create(:prometheus_metric, project: project) - end - - it_behaves_like 'valid embedded dashboard service response' - end - end - - context 'as a project-defined panel' do - let(:dashboard_path) { '.gitlab/dashboard/test.yml' } - let(:params) do - { - environment: environment, - embedded: true, - dashboard_path: dashboard_path, - group: 'Group A', - title: 'Super Chart A1', - y_label: 'y_label' - } - end - - it_behaves_like 'misconfigured dashboard service response', :not_found - - context 'when the metric exists' do - let(:project) { project_with_dashboard(dashboard_path) } - - it_behaves_like 'valid embedded dashboard service response' - end - end - end - end - end - - describe '.find_raw' do - let(:dashboard) { load_dashboard_yaml(File.read(Rails.root.join('config', 'prometheus', 'common_metrics.yml'))) } - let(:params) { {} } - - subject { described_class.find_raw(project, **params) } - - it { is_expected.to eq dashboard } - - context 'when the system dashboard is specified' do - let(:params) { { dashboard_path: system_dashboard_path } } - - it { is_expected.to eq dashboard } - end - - context 'when an existing project dashboard is specified' do - let(:dashboard) { load_sample_dashboard } - let(:params) { { dashboard_path: '.gitlab/dashboards/test.yml' } } - let(:project) { project_with_dashboard(params[:dashboard_path]) } - - it { is_expected.to eq dashboard } - end - end - - describe '.find_all_paths' do - let(:all_dashboard_paths) { described_class.find_all_paths(project) } - let(:system_dashboard) { { path: system_dashboard_path, display_name: 'Overview', default: true, system_dashboard: true, out_of_the_box_dashboard: true } } - let(:k8s_pod_health_dashboard) { { path: pod_dashboard_path, display_name: 'K8s pod health', default: false, system_dashboard: false, out_of_the_box_dashboard: true } } - - it 'includes OOTB dashboards by default' do - expect(all_dashboard_paths).to eq([k8s_pod_health_dashboard, system_dashboard]) - end - - context 'when the project contains dashboards' do - let(:dashboard_content) { fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml') } - let(:project) { project_with_dashboards(dashboards) } - - let(:dashboards) do - { - '.gitlab/dashboards/metrics.yml' => dashboard_content, - '.gitlab/dashboards/better_metrics.yml' => dashboard_content - } - end - - it 'includes OOTB and project dashboards' do - project_dashboard1 = { - path: '.gitlab/dashboards/metrics.yml', - display_name: 'metrics.yml', - default: false, - system_dashboard: false, - out_of_the_box_dashboard: false - } - - project_dashboard2 = { - path: '.gitlab/dashboards/better_metrics.yml', - display_name: 'better_metrics.yml', - default: false, - system_dashboard: false, - out_of_the_box_dashboard: false - } - - expect(all_dashboard_paths).to eq([project_dashboard2, k8s_pod_health_dashboard, project_dashboard1, system_dashboard]) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/importer_spec.rb b/spec/lib/gitlab/metrics/dashboard/importer_spec.rb deleted file mode 100644 index 8b705395a2c..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/importer_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Importer do - include MetricsDashboardHelpers - - let_it_be(:dashboard_path) { '.gitlab/dashboards/sample_dashboard.yml' } - let_it_be(:project) { create(:project) } - - before do - allow(subject).to receive(:dashboard_hash).and_return(dashboard_hash) - end - - subject { described_class.new(dashboard_path, project) } - - describe '.execute' do - context 'valid dashboard hash' do - let(:dashboard_hash) { load_sample_dashboard } - - it 'imports metrics to database' do - expect { subject.execute } - .to change { PrometheusMetric.count }.from(0).to(3) - end - end - - context 'invalid dashboard hash' do - let(:dashboard_hash) { {} } - - it 'returns false' do - expect(subject.execute).to be(false) - end - end - end - - describe '.execute!' do - context 'valid dashboard hash' do - let(:dashboard_hash) { load_sample_dashboard } - - it 'imports metrics to database' do - expect { subject.execute } - .to change { PrometheusMetric.count }.from(0).to(3) - end - end - - context 'invalid dashboard hash' do - let(:dashboard_hash) { {} } - - it 'raises error' do - expect { subject.execute! }.to raise_error(Gitlab::Metrics::Dashboard::Validator::Errors::SchemaValidationError, - 'root is missing required keys: dashboard, panel_groups') - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/importers/prometheus_metrics_spec.rb b/spec/lib/gitlab/metrics/dashboard/importers/prometheus_metrics_spec.rb deleted file mode 100644 index bc6cd383758..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/importers/prometheus_metrics_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Importers::PrometheusMetrics do - include MetricsDashboardHelpers - - describe '#execute' do - let(:project) { create(:project) } - let(:dashboard_path) { 'path/to/dashboard.yml' } - let(:prometheus_adapter) { double('adapter', clear_prometheus_reactive_cache!: nil) } - - subject { described_class.new(dashboard_hash, project: project, dashboard_path: dashboard_path) } - - context 'valid dashboard' do - let(:dashboard_hash) { load_sample_dashboard } - - context 'with all new metrics' do - it 'creates PrometheusMetrics' do - expect { subject.execute }.to change { PrometheusMetric.count }.by(3) - end - end - - context 'with existing metrics' do - let(:existing_metric_attributes) do - { - project: project, - identifier: 'metric_b', - title: 'overwrite', - y_label: 'overwrite', - query: 'overwrite', - unit: 'overwrite', - legend: 'overwrite', - dashboard_path: dashboard_path - } - end - - let!(:existing_metric) do - create(:prometheus_metric, existing_metric_attributes) - end - - it 'updates existing PrometheusMetrics' do - subject.execute - - expect(existing_metric.reload.attributes.with_indifferent_access).to include({ - title: 'Super Chart B', - y_label: 'y_label', - query: 'query', - unit: 'unit', - legend: 'Legend Label' - }) - end - - it 'creates new PrometheusMetrics' do - expect { subject.execute }.to change { PrometheusMetric.count }.by(2) - end - - context 'with stale metrics' do - let!(:stale_metric) do - create(:prometheus_metric, - project: project, - identifier: 'stale_metric', - dashboard_path: dashboard_path, - group: 3 - ) - end - - it 'updates existing PrometheusMetrics' do - subject.execute - - expect(existing_metric.reload.attributes.with_indifferent_access).to include({ - title: 'Super Chart B', - y_label: 'y_label', - query: 'query', - unit: 'unit', - legend: 'Legend Label' - }) - end - - it 'deletes stale metrics' do - subject.execute - - expect { stale_metric.reload }.to raise_error(ActiveRecord::RecordNotFound) - end - end - end - end - - context 'invalid dashboard' do - let(:dashboard_hash) { {} } - - it 'returns false' do - expect(subject.execute).to eq(false) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb index 52908a0b339..11b587e4905 100644 --- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb @@ -12,11 +12,6 @@ RSpec.describe Gitlab::Metrics::Dashboard::Processor do describe 'process' do let(:sequence) do [ - Gitlab::Metrics::Dashboard::Stages::CommonMetricsInserter, - Gitlab::Metrics::Dashboard::Stages::CustomMetricsInserter, - Gitlab::Metrics::Dashboard::Stages::CustomMetricsDetailsInserter, - Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter, - Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter, Gitlab::Metrics::Dashboard::Stages::UrlValidator ] end @@ -24,16 +19,6 @@ RSpec.describe Gitlab::Metrics::Dashboard::Processor do let(:process_params) { [project, dashboard_yml, sequence, { environment: environment }] } let(:dashboard) { described_class.new(*process_params).process } - it 'includes an id for each dashboard panel' do - expect(all_panels).to satisfy_all do |panel| - panel[:id].present? - end - end - - it 'includes boolean to indicate if panel group has custom metrics' do - expect(dashboard[:panel_groups]).to all(include( { has_custom_metrics: boolean } )) - end - context 'when the dashboard is not present' do let(:dashboard_yml) { nil } @@ -41,168 +26,5 @@ RSpec.describe Gitlab::Metrics::Dashboard::Processor do expect(dashboard).to be_nil end end - - context 'when dashboard config corresponds to common metrics' do - let!(:common_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') } - - it 'inserts metric ids into the config' do - target_metric = all_metrics.find { |metric| metric[:id] == 'metric_a1' } - - expect(target_metric).to include(:metric_id) - expect(target_metric[:metric_id]).to eq(common_metric.id) - end - end - - context 'when the project has associated metrics' do - let!(:project_response_metric) { create(:prometheus_metric, project: project, group: :response) } - let!(:project_system_metric) { create(:prometheus_metric, project: project, group: :system) } - let!(:project_business_metric) { create(:prometheus_metric, project: project, group: :business) } - - it 'includes project-specific metrics' do - expect(all_metrics).to include get_metric_details(project_system_metric) - expect(all_metrics).to include get_metric_details(project_response_metric) - expect(all_metrics).to include get_metric_details(project_business_metric) - end - - it 'display groups and panels in the order they are defined' do - expected_metrics_order = [ - 'metric_b', - 'metric_a2', - 'metric_a1', - project_business_metric.id, - project_response_metric.id, - project_system_metric.id - ] - actual_metrics_order = all_metrics.map { |m| m[:id] || m[:metric_id] } - - expect(actual_metrics_order).to eq expected_metrics_order - end - - context 'when the project has multiple metrics in the same group' do - let!(:project_response_metric) { create(:prometheus_metric, project: project, group: :response) } - let!(:project_response_metric_2) { create(:prometheus_metric, project: project, group: :response) } - - it 'includes multiple metrics' do - expect(all_metrics).to include get_metric_details(project_response_metric) - expect(all_metrics).to include get_metric_details(project_response_metric_2) - end - end - - context 'when the dashboard should not include project metrics' do - let(:sequence) do - [ - Gitlab::Metrics::Dashboard::Stages::CommonMetricsInserter, - Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter - ] - end - - let(:dashboard) { described_class.new(*process_params).process } - - it 'includes only dashboard metrics' do - metrics = all_metrics.map { |m| m[:id] } - - expect(metrics.length).to be(3) - expect(metrics).to eq %w(metric_b metric_a2 metric_a1) - end - end - - context 'when sample_metrics are requested' do - let(:process_params) { [project, dashboard_yml, sequence, { environment: environment, sample_metrics: true }] } - - it 'includes a sample metrics path for the prometheus endpoint with each metric' do - expect(all_metrics).to satisfy_all do |metric| - metric[:prometheus_endpoint_path] == sample_metrics_path(metric[:id]) - end - end - end - end - - context 'when there are no alerts' do - let!(:persisted_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') } - - it 'does not insert an alert_path' do - target_metric = all_metrics.find { |metric| metric[:metric_id] == persisted_metric.id } - - expect(target_metric).to be_a Hash - expect(target_metric).not_to include(:alert_path) - end - end - - shared_examples_for 'errors with message' do |expected_message| - it 'raises a DashboardLayoutError' do - error_class = Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError - - expect { dashboard }.to raise_error(error_class, expected_message) - end - end - - context 'when the dashboard is missing panel_groups' do - let(:dashboard_yml) { {} } - - it_behaves_like 'errors with message', 'Top-level key :panel_groups must be an array' - end - - context 'when the dashboard contains a panel_group which is missing panels' do - let(:dashboard_yml) { { panel_groups: [{}] } } - - it_behaves_like 'errors with message', 'Each "panel_group" must define an array :panels' - end - - context 'when the dashboard contains a panel which is missing metrics' do - let(:dashboard_yml) { { panel_groups: [{ panels: [{}] }] } } - - it_behaves_like 'errors with message', 'Each "panel" must define an array :metrics' - end - - context 'when the dashboard contains a metric which is missing a query' do - let(:dashboard_yml) { { panel_groups: [{ panels: [{ metrics: [{}] }] }] } } - - it_behaves_like 'errors with message', 'Each "metric" must define one of :query or :query_range' - end - end - - private - - def all_metrics - all_panels.flat_map { |panel| panel[:metrics] } - end - - def all_panels - dashboard[:panel_groups].flat_map { |group| group[:panels] } - end - - def get_metric_details(metric) - { - query_range: metric.query, - unit: metric.unit, - label: metric.legend, - metric_id: metric.id, - prometheus_endpoint_path: prometheus_path(metric.query), - edit_path: edit_metric_path(metric) - } - end - - def prometheus_path(query) - Gitlab::Routing.url_helpers.prometheus_api_project_environment_path( - project, - environment, - proxy_path: :query_range, - query: query - ) - end - - def sample_metrics_path(metric) - Gitlab::Routing.url_helpers.sample_metrics_project_environment_path( - project, - environment, - identifier: metric - ) - end - - def edit_metric_path(metric) - Gitlab::Routing.url_helpers.edit_project_prometheus_metric_path( - project, - metric.id - ) end end diff --git a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb deleted file mode 100644 index 343596af5cf..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb +++ /dev/null @@ -1,148 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::ServiceSelector do - include MetricsDashboardHelpers - - describe '#call' do - let(:arguments) { {} } - - subject { described_class.call(arguments) } - - it { is_expected.to be Metrics::Dashboard::SystemDashboardService } - - context 'when just the dashboard path is provided' do - let(:arguments) { { dashboard_path: '.gitlab/dashboards/test.yml' } } - - it { is_expected.to be Metrics::Dashboard::CustomDashboardService } - - context 'when the path is for the system dashboard' do - let(:arguments) { { dashboard_path: system_dashboard_path } } - - it { is_expected.to be Metrics::Dashboard::SystemDashboardService } - end - - context 'when the path is for the pod dashboard' do - let(:arguments) { { dashboard_path: pod_dashboard_path } } - - it { is_expected.to be Metrics::Dashboard::PodDashboardService } - end - end - - context 'when the embedded flag is provided' do - let(:arguments) { { embedded: true } } - - it { is_expected.to be Metrics::Dashboard::DefaultEmbedService } - - context 'when an incomplete set of dashboard identifiers are provided' do - let(:arguments) { { embedded: true, dashboard_path: '.gitlab/dashboards/test.yml' } } - - it { is_expected.to be Metrics::Dashboard::DefaultEmbedService } - end - - context 'when all the chart identifiers are provided' do - let(:arguments) do - { - embedded: true, - dashboard_path: '.gitlab/dashboards/test.yml', - group: 'Important Metrics', - title: 'Total Requests', - y_label: 'req/sec' - } - end - - it { is_expected.to be Metrics::Dashboard::DynamicEmbedService } - end - - context 'when all chart params expect dashboard_path are provided' do - let(:arguments) do - { - embedded: true, - group: 'Important Metrics', - title: 'Total Requests', - y_label: 'req/sec' - } - end - - it { is_expected.to be Metrics::Dashboard::DynamicEmbedService } - end - - context 'with a system dashboard and "custom" group' do - let(:arguments) do - { - embedded: true, - dashboard_path: system_dashboard_path, - group: business_metric_title, - title: 'Total Requests', - y_label: 'req/sec' - } - end - - it { is_expected.to be Metrics::Dashboard::CustomMetricEmbedService } - end - - context 'with a grafana link' do - let(:arguments) do - { - embedded: true, - grafana_url: 'https://grafana.example.com' - } - end - - it { is_expected.to be Metrics::Dashboard::GrafanaMetricEmbedService } - end - - context 'with the embed defined in the arguments' do - let(:arguments) do - { - embedded: true, - embed_json: '{}' - } - end - - it { is_expected.to be Metrics::Dashboard::TransientEmbedService } - end - - context 'when cluster is provided' do - let(:arguments) { { cluster: "some cluster" } } - - it { is_expected.to be Metrics::Dashboard::ClusterDashboardService } - end - - context 'when cluster is provided and embedded is not true' do - let(:arguments) { { cluster: "some cluster", embedded: 'false' } } - - it { is_expected.to be Metrics::Dashboard::ClusterDashboardService } - end - - context 'when cluster dashboard_path is provided' do - let(:arguments) { { dashboard_path: ::Metrics::Dashboard::ClusterDashboardService::DASHBOARD_PATH } } - - it { is_expected.to be Metrics::Dashboard::ClusterDashboardService } - end - - context 'when cluster is provided and embed params' do - let(:arguments) do - { - cluster: "some cluster", - embedded: 'true', - cluster_type: 'project', - format: :json, - group: 'Food metrics', - title: 'Pizza Consumption', - y_label: 'Slice Count' - } - end - - it { is_expected.to be Metrics::Dashboard::ClusterMetricsEmbedService } - end - - context 'when metrics embed is for an alert' do - let(:arguments) { { embedded: true, prometheus_alert_id: 5 } } - - it { is_expected.to be Metrics::Dashboard::GitlabAlertEmbedService } - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb deleted file mode 100644 index 3cfdfafb0c5..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Stages::GrafanaFormatter do - include GrafanaApiHelpers - - let_it_be(:namespace) { create(:namespace, path: 'foo') } - let_it_be(:project) { create(:project, namespace: namespace, path: 'bar') } - - describe '#transform!' do - let(:grafana_dashboard) { Gitlab::Json.parse(fixture_file('grafana/simplified_dashboard_response.json'), symbolize_names: true) } - let(:datasource) { Gitlab::Json.parse(fixture_file('grafana/datasource_response.json'), symbolize_names: true) } - let(:expected_dashboard) { Gitlab::Json.parse(fixture_file('grafana/expected_grafana_embed.json'), symbolize_names: true) } - - subject(:dashboard) { described_class.new(project, {}, params).transform! } - - let(:params) do - { - grafana_dashboard: grafana_dashboard, - datasource: datasource, - grafana_url: valid_grafana_dashboard_link('https://grafana.example.com') - } - end - - context 'when the query and resources are configured correctly' do - it { is_expected.to eq expected_dashboard } - end - - context 'when a panelId is not included in the grafana_url' do - before do - params[:grafana_url].gsub('&panelId=8', '') - end - - it { is_expected.to eq expected_dashboard } - - context 'when there is also no valid panel in the dashboard' do - before do - params[:grafana_dashboard][:dashboard][:panels] = [] - end - - it 'raises a processing error' do - expect { dashboard }.to raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) - end - end - end - - context 'when an input is invalid' do - before do - params[:datasource][:access] = 'not-proxy' - end - - it 'raises a processing error' do - expect { dashboard }.to raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb deleted file mode 100644 index bb3c8626d32..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter do - include MetricsDashboardHelpers - - let(:project) { build_stubbed(:project) } - let(:environment) { build_stubbed(:environment, project: project) } - - describe '#transform!' do - subject(:transform!) { described_class.new(project, dashboard, environment: environment).transform! } - - let(:dashboard) { load_sample_dashboard.deep_symbolize_keys } - - it 'generates prometheus_endpoint_path without newlines' do - query = 'avg( sum( container_memory_usage_bytes{ container_name!="POD", '\ - 'pod_name=~"^{{ci_environment_slug}}-(.*)", namespace="{{kube_namespace}}" } ) '\ - 'by (job) ) without (job) /1024/1024/1024' - - transform! - - expect(all_metrics[2][:prometheus_endpoint_path]).to eq(prometheus_path(query)) - end - - it 'includes a path for the prometheus endpoint with each metric' do - transform! - - expect(all_metrics).to satisfy_all do |metric| - metric[:prometheus_endpoint_path].present? && !metric[:prometheus_endpoint_path].include?("\n") - end - end - - it 'works when query/query_range is a number' do - query = 2000 - - transform! - - expect(all_metrics[1][:prometheus_endpoint_path]).to eq(prometheus_path(query)) - end - end - - private - - def all_metrics - dashboard[:panel_groups].flat_map do |group| - group[:panels].flat_map { |panel| panel[:metrics] } - end - end - - def prometheus_path(query) - Gitlab::Routing.url_helpers.prometheus_api_project_environment_path( - project, - environment, - proxy_path: :query_range, - query: query - ) - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb deleted file mode 100644 index 7a3a9021f86..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter do - include MetricsDashboardHelpers - - let(:project) { build_stubbed(:project) } - - def fetch_panel_ids(dashboard_hash) - dashboard_hash[:panel_groups].flat_map { |group| group[:panels].flat_map { |panel| panel[:id] } } - end - - describe '#transform!' do - subject(:transform!) { described_class.new(project, dashboard, nil).transform! } - - let(:dashboard) { load_sample_dashboard.deep_symbolize_keys } - - context 'when dashboard panels are present' do - it 'assigns unique ids to each panel using PerformanceMonitoring::PrometheusPanel', :aggregate_failures do - dashboard.fetch(:panel_groups).each do |group| - group.fetch(:panels).each do |panel| - panel_double = instance_double(::PerformanceMonitoring::PrometheusPanel) - - expect(::PerformanceMonitoring::PrometheusPanel).to receive(:new).with(panel).and_return(panel_double) - expect(panel_double).to receive(:id).with(group[:group]).and_return(FFaker::Lorem.unique.characters(125)) - end - end - - transform! - - expect(fetch_panel_ids(dashboard)).not_to include nil - end - end - - context 'when dashboard panels has duplicated ids' do - it 'no panel has assigned id' do - panel_double = instance_double(::PerformanceMonitoring::PrometheusPanel) - allow(::PerformanceMonitoring::PrometheusPanel).to receive(:new).and_return(panel_double) - allow(panel_double).to receive(:id).and_return('duplicated id') - - transform! - - expect(fetch_panel_ids(dashboard)).to all be_nil - expect(fetch_panel_ids(dashboard)).not_to include 'duplicated id' - end - end - - context 'when there are no panels in the dashboard' do - it 'raises a processing error' do - dashboard[:panel_groups][0].delete(:panels) - - expect { transform! }.to( - raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) - ) - end - end - - context 'when there are no panel_groups in the dashboard' do - it 'raises a processing error' do - dashboard.delete(:panel_groups) - - expect { transform! }.to( - raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) - ) - end - end - - context 'when dashboard panels has unknown schema attributes' do - before do - error = ActiveModel::UnknownAttributeError.new(double, 'unknown_panel_attribute') - allow(::PerformanceMonitoring::PrometheusPanel).to receive(:new).and_raise(error) - end - - it 'no panel has assigned id' do - transform! - - expect(fetch_panel_ids(dashboard)).to all be_nil - end - - it 'logs the failure' do - expect(Gitlab::ErrorTracking).to receive(:log_exception) - - transform! - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/track_panel_type_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/track_panel_type_spec.rb deleted file mode 100644 index 60010b9f257..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/stages/track_panel_type_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Stages::TrackPanelType do - include MetricsDashboardHelpers - - let(:project) { build_stubbed(:project) } - let(:environment) { build_stubbed(:environment, project: project) } - - describe '#transform!', :snowplow do - subject { described_class.new(project, dashboard, environment: environment) } - - let(:dashboard) { load_sample_dashboard.deep_symbolize_keys } - - it 'creates tracking event' do - subject.transform! - - expect_snowplow_event( - category: 'MetricsDashboard::Chart', - action: 'chart_rendered', - label: 'area-chart' - ) - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/stages/variable_endpoint_inserter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/variable_endpoint_inserter_spec.rb deleted file mode 100644 index 9303ff981fb..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/stages/variable_endpoint_inserter_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Stages::VariableEndpointInserter do - include MetricsDashboardHelpers - - let(:project) { build_stubbed(:project) } - let(:environment) { build_stubbed(:environment, project: project) } - - describe '#transform!' do - subject(:transform!) { described_class.new(project, dashboard, environment: environment).transform! } - - let(:dashboard) { load_sample_dashboard.deep_symbolize_keys } - - context 'when dashboard variables are present' do - it 'assigns prometheus_endpoint_path to metric_label_values variable type' do - endpoint_path = Gitlab::Routing.url_helpers.prometheus_api_project_environment_path( - project, - environment, - proxy_path: :series, - match: ['backend:haproxy_backend_availability:ratio{env="{{env}}"}'] - ) - - transform! - - expect( - dashboard.dig(:templating, :variables, :metric_label_values_variable, :options) - ).to include(prometheus_endpoint_path: endpoint_path) - end - - it 'does not modify other variable types' do - original_text_variable = dashboard[:templating][:variables][:text_variable_full_syntax].deep_dup - - transform! - - expect(dashboard[:templating][:variables][:text_variable_full_syntax]).to eq(original_text_variable) - end - - context 'when variable does not have the required series_selector' do - it 'adds prometheus_endpoint_path without match parameter' do - dashboard[:templating][:variables][:metric_label_values_variable][:options].delete(:series_selector) - endpoint_path = Gitlab::Routing.url_helpers.prometheus_api_project_environment_path( - project, - environment, - proxy_path: :series - ) - - transform! - - expect( - dashboard.dig(:templating, :variables, :metric_label_values_variable, :options) - ).to include(prometheus_endpoint_path: endpoint_path) - end - end - end - - context 'when no variables are present' do - it 'does not fail' do - dashboard.delete(:templating) - - expect { transform! }.not_to raise_error - end - end - - context 'with no environment' do - subject(:transform!) { described_class.new(project, dashboard, {}).transform! } - - it 'raises error' do - expect { transform! }.to raise_error( - Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError, - 'Environment is required for Stages::VariableEndpointInserter' - ) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics_spec.rb b/spec/lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics_spec.rb deleted file mode 100644 index 3af8b51c889..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/transformers/yml/v1/prometheus_metrics_spec.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Transformers::Yml::V1::PrometheusMetrics do - include MetricsDashboardHelpers - - describe '#execute' do - subject { described_class.new(dashboard_hash) } - - context 'valid dashboard' do - let_it_be(:dashboard_hash) do - { - panel_groups: [{ - panels: [ - { - title: 'Panel 1 title', - y_label: 'Panel 1 y_label', - metrics: [ - { - query_range: 'Panel 1 metric 1 query_range', - unit: 'Panel 1 metric 1 unit', - label: 'Panel 1 metric 1 label', - id: 'Panel 1 metric 1 id' - }, - { - query: 'Panel 1 metric 2 query', - unit: 'Panel 1 metric 2 unit', - label: 'Panel 1 metric 2 label', - id: 'Panel 1 metric 2 id' - } - ] - }, - { - title: 'Panel 2 title', - y_label: 'Panel 2 y_label', - metrics: [{ - query_range: 'Panel 2 metric 1 query_range', - unit: 'Panel 2 metric 1 unit', - label: 'Panel 2 metric 1 label', - id: 'Panel 2 metric 1 id' - }] - } - ] - }] - } - end - - let(:expected_metrics) do - [ - { - title: 'Panel 1 title', - y_label: 'Panel 1 y_label', - query: "Panel 1 metric 1 query_range", - unit: 'Panel 1 metric 1 unit', - legend: 'Panel 1 metric 1 label', - identifier: 'Panel 1 metric 1 id', - group: 3, - common: false - }, - { - title: 'Panel 1 title', - y_label: 'Panel 1 y_label', - query: 'Panel 1 metric 2 query', - unit: 'Panel 1 metric 2 unit', - legend: 'Panel 1 metric 2 label', - identifier: 'Panel 1 metric 2 id', - group: 3, - common: false - }, - { - title: 'Panel 2 title', - y_label: 'Panel 2 y_label', - query: 'Panel 2 metric 1 query_range', - unit: 'Panel 2 metric 1 unit', - legend: 'Panel 2 metric 1 label', - identifier: 'Panel 2 metric 1 id', - group: 3, - common: false - } - ] - end - - it 'returns collection of metrics with correct attributes' do - expect(subject.execute).to match_array(expected_metrics) - end - end - - context 'invalid dashboard' do - let(:dashboard_hash) { {} } - - it 'raises missing attribute error' do - expect { subject.execute }.to raise_error( - ::Gitlab::Metrics::Dashboard::Transformers::Errors::MissingAttribute, "Missing attribute: 'panel_groups'" - ) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/validator/client_spec.rb b/spec/lib/gitlab/metrics/dashboard/validator/client_spec.rb deleted file mode 100644 index 4b07f9dbbab..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/validator/client_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Validator::Client do - include MetricsDashboardHelpers - - let_it_be(:schema_path) { 'lib/gitlab/metrics/dashboard/validator/schemas/dashboard.json' } - - subject { described_class.new(dashboard, schema_path) } - - describe '#execute' do - context 'with no validation errors' do - let(:dashboard) { load_sample_dashboard } - - it 'returns empty array' do - expect(subject.execute).to eq([]) - end - end - - context 'with validation errors' do - let(:dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/invalid_dashboard.yml')) } - - it 'returns array of error objects' do - expect(subject.execute).to include(Gitlab::Metrics::Dashboard::Validator::Errors::SchemaValidationError) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/validator/custom_formats_spec.rb b/spec/lib/gitlab/metrics/dashboard/validator/custom_formats_spec.rb deleted file mode 100644 index 129fb631f3e..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/validator/custom_formats_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Validator::CustomFormats do - describe '#format_handlers' do - describe 'add_to_metric_id_cache' do - it 'adds data to metric id cache' do - subject.format_handlers['add_to_metric_id_cache'].call('metric_id', '_schema') - - expect(subject.metric_ids_cache).to eq(["metric_id"]) - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/validator/errors_spec.rb b/spec/lib/gitlab/metrics/dashboard/validator/errors_spec.rb deleted file mode 100644 index a50c2a506cb..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/validator/errors_spec.rb +++ /dev/null @@ -1,149 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Validator::Errors do - describe Gitlab::Metrics::Dashboard::Validator::Errors::SchemaValidationError do - context 'empty error hash' do - let(:error_hash) { {} } - - it 'uses default error message' do - expect(described_class.new(error_hash).message).to eq('Dashboard failed schema validation') - end - end - - context 'formatted message' do - subject { described_class.new(error_hash).message } - - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => 'schema', - 'details' => details - } - end - - context 'for root object' do - let(:pointer) { '' } - - context 'when required keys are missing' do - let(:type) { 'required' } - let(:details) { { 'missing_keys' => ['one'] } } - - it { is_expected.to eq 'root is missing required keys: one' } - end - - context 'when there is type mismatch' do - %w(null string boolean integer number array object).each do |expected_type| - context "on type: #{expected_type}" do - let(:type) { expected_type } - let(:details) { nil } - - it { is_expected.to eq "'property_name' at root is not of type: #{expected_type}" } - end - end - end - end - - context 'for nested object' do - let(:pointer) { '/nested_objects/0' } - - context 'when required keys are missing' do - let(:type) { 'required' } - let(:details) { { 'missing_keys' => ['two'] } } - - it { is_expected.to eq '/nested_objects/0 is missing required keys: two' } - end - - context 'when there is type mismatch' do - %w(null string boolean integer number array object).each do |expected_type| - context "on type: #{expected_type}" do - let(:type) { expected_type } - let(:details) { nil } - - it { is_expected.to eq "'property_name' at /nested_objects/0 is not of type: #{expected_type}" } - end - end - end - - context 'when data does not match pattern' do - let(:type) { 'pattern' } - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => { 'pattern' => 'aa.*' } - } - end - - it { is_expected.to eq "'property_name' at /nested_objects/0 does not match pattern: aa.*" } - end - - context 'when data does not match format' do - let(:type) { 'format' } - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => { 'format' => 'date-time' } - } - end - - it { is_expected.to eq "'property_name' at /nested_objects/0 does not match format: date-time" } - end - - context 'when data is not const' do - let(:type) { 'const' } - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => { 'const' => 'one' } - } - end - - it { is_expected.to eq "'property_name' at /nested_objects/0 is not: \"one\"" } - end - - context 'when data is not included in enum' do - let(:type) { 'enum' } - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => { 'enum' => %w(one two) } - } - end - - it { is_expected.to eq "'property_name' at /nested_objects/0 is not one of: [\"one\", \"two\"]" } - end - - context 'when data is not included in enum' do - let(:type) { 'unknown' } - let(:error_hash) do - { - 'data' => 'property_name', - 'data_pointer' => pointer, - 'type' => type, - 'schema' => 'schema' - } - end - - it { is_expected.to eq "'property_name' at /nested_objects/0 is invalid: error_type=unknown" } - end - end - end - end - - describe Gitlab::Metrics::Dashboard::Validator::Errors::DuplicateMetricIds do - it 'has custom error message' do - expect(described_class.new.message).to eq('metric_id must be unique across a project') - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/validator/post_schema_validator_spec.rb b/spec/lib/gitlab/metrics/dashboard/validator/post_schema_validator_spec.rb deleted file mode 100644 index e7cb1429ca9..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/validator/post_schema_validator_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Validator::PostSchemaValidator do - describe '#validate' do - context 'with no project and dashboard_path provided' do - context 'unique local metric_ids' do - it 'returns empty array' do - expect(described_class.new(metric_ids: [1, 2, 3]).validate).to eq([]) - end - end - - context 'duplicate local metrics_ids' do - it 'returns error' do - expect(described_class.new(metric_ids: [1, 1]).validate) - .to eq([Gitlab::Metrics::Dashboard::Validator::Errors::DuplicateMetricIds]) - end - end - end - - context 'with project and dashboard_path' do - let(:project) { create(:project) } - - subject do - described_class.new( - project: project, - metric_ids: ['some_identifier'], - dashboard_path: 'test/path.yml' - ).validate - end - - context 'with unique metric identifiers' do - before do - create(:prometheus_metric, - project: project, - identifier: 'some_other_identifier', - dashboard_path: 'test/path.yml' - ) - end - - it 'returns empty array' do - expect(subject).to eq([]) - end - end - - context 'duplicate metric identifiers in database' do - context 'with different dashboard_path' do - before do - create(:prometheus_metric, - project: project, - identifier: 'some_identifier', - dashboard_path: 'some/other/path.yml' - ) - end - - it 'returns error' do - expect(subject).to include(Gitlab::Metrics::Dashboard::Validator::Errors::DuplicateMetricIds) - end - end - - context 'with same dashboard_path' do - before do - create(:prometheus_metric, - project: project, - identifier: 'some_identifier', - dashboard_path: 'test/path.yml' - ) - end - - it 'returns empty array' do - expect(subject).to eq([]) - end - end - end - end - end -end diff --git a/spec/lib/gitlab/metrics/dashboard/validator_spec.rb b/spec/lib/gitlab/metrics/dashboard/validator_spec.rb deleted file mode 100644 index fb55b736354..00000000000 --- a/spec/lib/gitlab/metrics/dashboard/validator_spec.rb +++ /dev/null @@ -1,146 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Metrics::Dashboard::Validator do - include MetricsDashboardHelpers - - let_it_be(:valid_dashboard) { load_sample_dashboard } - let_it_be(:invalid_dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/invalid_dashboard.yml')) } - let_it_be(:duplicate_id_dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/duplicate_id_dashboard.yml')) } - - let_it_be(:project) { create(:project) } - - describe '#validate' do - context 'valid dashboard schema' do - it 'returns true' do - expect(described_class.validate(valid_dashboard)).to be true - end - - context 'with duplicate metric_ids' do - it 'returns false' do - expect(described_class.validate(duplicate_id_dashboard)).to be false - end - end - - context 'with dashboard_path and project' do - subject { described_class.validate(valid_dashboard, dashboard_path: 'test/path.yml', project: project) } - - context 'with no conflicting metric identifiers in db' do - it { is_expected.to be true } - end - - context 'with metric identifier present in current dashboard' do - before do - create(:prometheus_metric, - identifier: 'metric_a1', - dashboard_path: 'test/path.yml', - project: project - ) - end - - it { is_expected.to be true } - end - - context 'with metric identifier present in another dashboard' do - before do - create(:prometheus_metric, - identifier: 'metric_a1', - dashboard_path: 'some/other/dashboard/path.yml', - project: project - ) - end - - it { is_expected.to be false } - end - end - end - - context 'invalid dashboard schema' do - it 'returns false' do - expect(described_class.validate(invalid_dashboard)).to be false - end - end - end - - describe '#validate!' do - shared_examples 'validation failed' do |errors_message| - it 'raises error with corresponding messages', :aggregate_failures do - expect { subject }.to raise_error do |error| - expect(error).to be_kind_of(Gitlab::Metrics::Dashboard::Validator::Errors::InvalidDashboardError) - expect(error.message).to eq(errors_message) - end - end - end - - context 'valid dashboard schema' do - it 'returns true' do - expect(described_class.validate!(valid_dashboard)).to be true - end - - context 'with duplicate metric_ids' do - subject { described_class.validate!(duplicate_id_dashboard) } - - it_behaves_like 'validation failed', 'metric_id must be unique across a project' - end - - context 'with dashboard_path and project' do - subject { described_class.validate!(valid_dashboard, dashboard_path: 'test/path.yml', project: project) } - - context 'with no conflicting metric identifiers in db' do - it { is_expected.to be true } - end - - context 'with metric identifier present in current dashboard' do - before do - create(:prometheus_metric, - identifier: 'metric_a1', - dashboard_path: 'test/path.yml', - project: project - ) - end - - it { is_expected.to be true } - end - - context 'with metric identifier present in another dashboard' do - before do - create(:prometheus_metric, - identifier: 'metric_a1', - dashboard_path: 'some/other/dashboard/path.yml', - project: project - ) - end - - it_behaves_like 'validation failed', 'metric_id must be unique across a project' - end - end - end - - context 'invalid dashboard schema' do - subject { described_class.validate!(invalid_dashboard) } - - context 'wrong property type' do - it_behaves_like 'validation failed', "'this_should_be_a_int' at /panel_groups/0/panels/0/weight is not of type: number" - end - - context 'panel groups missing' do - let_it_be(:invalid_dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/dashboard_missing_panel_groups.yml')) } - - it_behaves_like 'validation failed', 'root is missing required keys: panel_groups' - end - - context 'groups are missing panels and group keys' do - let_it_be(:invalid_dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/dashboard_groups_missing_panels_and_group.yml')) } - - it_behaves_like 'validation failed', '/panel_groups/0 is missing required keys: group' - end - - context 'panel is missing metrics key' do - let_it_be(:invalid_dashboard) { load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/dashboard_panel_is_missing_metrics.yml')) } - - it_behaves_like 'validation failed', '/panel_groups/0/panels/0 is missing required keys: metrics' - end - end - end -end diff --git a/spec/lib/gitlab/metrics/global_search_slis_spec.rb b/spec/lib/gitlab/metrics/global_search_slis_spec.rb index 5248cd08770..68793db6e41 100644 --- a/spec/lib/gitlab/metrics/global_search_slis_spec.rb +++ b/spec/lib/gitlab/metrics/global_search_slis_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Metrics::GlobalSearchSlis do +RSpec.describe Gitlab::Metrics::GlobalSearchSlis, feature_category: :global_search do using RSpec::Parameterized::TableSyntax describe '#initialize_slis!' do @@ -92,6 +92,7 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis do 'basic' | true | 27.538 'advanced' | false | 2.452 'advanced' | true | 15.52 + 'zoekt' | true | 15.52 end with_them do diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb index afb029a96cb..2ec31a5cc3e 100644 --- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb @@ -384,7 +384,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do end it 'does not store DB roles into into RequestStore' do - Gitlab::WithRequestStore.with_request_store do + Gitlab::SafeRequestStore.ensure_request_store do subscriber.sql(event) expect(described_class.db_counter_payload).to include( |