Commit 9b9f094c authored by Markus Koller's avatar Markus Koller Committed by Michael Kozono

Rename Prometheus project integration association [RUN AS-IF-FOSS]

parent 15ee1a41
......@@ -9,8 +9,8 @@ class Projects::ServicesController < Projects::ApplicationController
before_action :ensure_service_enabled
before_action :integration
before_action :web_hook_logs, only: [:edit, :update]
before_action :set_deprecation_notice_for_prometheus_service, only: [:edit, :update]
before_action :redirect_deprecated_prometheus_service, only: [:update]
before_action :set_deprecation_notice_for_prometheus_integration, only: [:edit, :update]
before_action :redirect_deprecated_prometheus_integration, only: [:update]
respond_to :html
......@@ -104,11 +104,11 @@ class Projects::ServicesController < Projects::ApplicationController
.merge(errors: integration.errors.as_json)
end
def redirect_deprecated_prometheus_service
def redirect_deprecated_prometheus_integration
redirect_to edit_project_service_path(project, integration) if integration.is_a?(::Integrations::Prometheus) && Feature.enabled?(:settings_operations_prometheus_service, project)
end
def set_deprecation_notice_for_prometheus_service
def set_deprecation_notice_for_prometheus_integration
return if !integration.is_a?(::Integrations::Prometheus) || !Feature.enabled?(:settings_operations_prometheus_service, project)
operations_link_start = "<a href=\"#{project_settings_operations_path(project)}\">"
......
......@@ -23,7 +23,7 @@ module Mutations
def resolve(args)
project = authorized_find!(args[:project_path])
return integration_exists if project.prometheus_service
return integration_exists if project.prometheus_integration
result = ::Projects::Operations::UpdateService.new(
project,
......@@ -32,7 +32,7 @@ module Mutations
**token_attributes
).execute
response(project.prometheus_service, result)
response(project.prometheus_integration, result)
end
private
......
......@@ -34,7 +34,7 @@ module Resolvers
def prometheus_integrations
return [] unless prometheus_integrations_allowed?
Array(project.prometheus_service)
Array(project.prometheus_integration)
end
def http_integrations
......
......@@ -12,10 +12,10 @@ module Types
authorize :admin_project
alias_method :prometheus_service, :object
alias_method :prometheus_integration, :object
def name
prometheus_service.title
prometheus_integration.title
end
def type
......@@ -23,15 +23,15 @@ module Types
end
def token
prometheus_service.project&.alerting_setting&.token
prometheus_integration.project&.alerting_setting&.token
end
def url
prometheus_service.project && notify_project_prometheus_alerts_url(prometheus_service.project, format: :json)
prometheus_integration.project && notify_project_prometheus_alerts_url(prometheus_integration.project, format: :json)
end
def active
prometheus_service.manual_configuration?
prometheus_integration.manual_configuration?
end
end
end
......
......@@ -79,7 +79,7 @@ module EnvironmentsHelper
end
def has_managed_prometheus?(project)
project.prometheus_service&.prometheus_available? == true
project.prometheus_integration&.prometheus_available? == true
end
def metrics_dashboard_base_path(environment, project)
......
......@@ -3,8 +3,8 @@
module OperationsHelper
include Gitlab::Utils::StrongMemoize
def prometheus_service
strong_memoize(:prometheus_service) do
def prometheus_integration
strong_memoize(:prometheus_integration) do
@project.find_or_initialize_service(::Integrations::Prometheus.to_param)
end
end
......@@ -14,11 +14,11 @@ module OperationsHelper
templates = setting.available_issue_templates.map { |t| { key: t.key, name: t.name } }
{
'prometheus_activated' => prometheus_service.manual_configuration?.to_s,
'prometheus_form_path' => scoped_integration_path(prometheus_service),
'prometheus_activated' => prometheus_integration.manual_configuration?.to_s,
'prometheus_form_path' => scoped_integration_path(prometheus_integration),
'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(@project),
'prometheus_authorization_key' => @project.alerting_setting&.token,
'prometheus_api_url' => prometheus_service.api_url,
'prometheus_api_url' => prometheus_integration.api_url,
'prometheus_url' => notify_project_prometheus_alerts_url(@project, format: :json),
'alerts_setup_url' => help_page_path('operations/incident_management/integrations.md', anchor: 'configuration'),
'alerts_usage_url' => project_alert_management_index_path(@project),
......
......@@ -29,13 +29,13 @@ module Projects::AlertManagementHelper
private
def has_managed_prometheus?(project)
project.prometheus_service&.prometheus_available? == true
project.prometheus_integration&.prometheus_available? == true
end
def alert_management_enabled?(project)
!!(
project.alert_management_alerts.any? ||
project.prometheus_service_active? ||
project.prometheus_integration_active? ||
AlertManagement::HttpIntegrationsFinder.new(project, active: true).execute.any?
)
end
......
......@@ -23,7 +23,7 @@ module Clusters
after_destroy do
run_after_commit do
deactivate_project_services
deactivate_project_integrations
end
end
......@@ -32,9 +32,9 @@ module Clusters
run_after_commit do
if enabled
activate_project_services
activate_project_integrations
else
deactivate_project_services
deactivate_project_integrations
end
end
end
......@@ -45,12 +45,12 @@ module Clusters
private
def activate_project_services
def activate_project_integrations
::Clusters::Applications::ActivateServiceWorker
.perform_async(cluster_id, ::Integrations::Prometheus.to_param)
end
def deactivate_project_services
def deactivate_project_integrations
::Clusters::Applications::DeactivateServiceWorker
.perform_async(cluster_id, ::Integrations::Prometheus.to_param)
end
......
......@@ -49,7 +49,7 @@ class Integration < ApplicationRecord
hangouts_chat
irker
jenkins jira
packagist pipelines_email pivotaltracker pushover
packagist pipelines_email pivotaltracker prometheus pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
redmine
slack slack_slash_commands
......
......@@ -182,7 +182,7 @@ class Project < ApplicationRecord
has_one :packagist_integration, class_name: 'Integrations::Packagist'
has_one :pipelines_email_integration, class_name: 'Integrations::PipelinesEmail'
has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker'
has_one :prometheus_service, class_name: 'Integrations::Prometheus', inverse_of: :project
has_one :prometheus_integration, class_name: 'Integrations::Prometheus', inverse_of: :project
has_one :pushover_integration, class_name: 'Integrations::Pushover'
has_one :redmine_integration, class_name: 'Integrations::Redmine'
has_one :slack_integration, class_name: 'Integrations::Slack'
......@@ -400,7 +400,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :error_tracking_setting, update_only: true
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :grafana_integration, update_only: true, allow_destroy: true
accepts_nested_attributes_for :prometheus_service, update_only: true
accepts_nested_attributes_for :prometheus_integration, update_only: true
accepts_nested_attributes_for :alerting_setting, update_only: true
delegate :feature_available?, :builds_enabled?, :wiki_enabled?,
......@@ -439,7 +439,7 @@ class Project < ApplicationRecord
delegate :allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline?,
:allow_merge_on_skipped_pipeline=, :has_confluence?, :allow_editing_commit_messages?,
to: :project_setting
delegate :active?, to: :prometheus_service, allow_nil: true, prefix: true
delegate :active?, to: :prometheus_integration, allow_nil: true, prefix: true
delegate :log_jira_dvcs_integration_usage, :jira_dvcs_server_last_sync_at, :jira_dvcs_cloud_last_sync_at, to: :feature_usage
......
......@@ -111,7 +111,7 @@ module Projects
if Feature.enabled?(:projects_post_creation_worker, current_user, default_enabled: :yaml)
Projects::PostCreationWorker.perform_async(@project.id)
else
create_prometheus_service
create_prometheus_integration
end
create_readme if @initialize_with_readme
......@@ -192,7 +192,7 @@ module Projects
end
# Deprecated: https://gitlab.com/gitlab-org/gitlab/-/issues/326665
def create_prometheus_service
def create_prometheus_integration
service = @project.find_or_initialize_service(::Integrations::Prometheus.to_param)
# If the service has already been inserted in the database, that
......@@ -202,12 +202,12 @@ module Projects
if service.prometheus_available?
service.save!
else
@project.prometheus_service = nil
@project.prometheus_integration = nil
end
rescue ActiveRecord::RecordInvalid => e
Gitlab::ErrorTracking.track_exception(e, extra: { project_id: project.id })
@project.prometheus_service = nil
@project.prometheus_integration = nil
end
def set_project_name_from_path
......
......@@ -105,7 +105,7 @@ module Projects
service = project.find_or_initialize_service(::Integrations::Prometheus.to_param)
service.assign_attributes(attrs)
{ prometheus_service_attributes: service.attributes.except(*%w(id project_id created_at updated_at)) }
{ prometheus_integration_attributes: service.attributes.except(*%w(id project_id created_at updated_at)) }
end
def incident_management_setting_params
......
......@@ -10,4 +10,4 @@
= render 'projects/settings/operations/incidents'
= render 'projects/settings/operations/grafana_integration'
= render_if_exists 'projects/settings/operations/status_page'
= render 'projects/settings/operations/prometheus', service: prometheus_service if Feature.enabled?(:settings_operations_prometheus_service)
= render 'projects/settings/operations/prometheus', service: prometheus_integration if Feature.enabled?(:settings_operations_prometheus_service)
......@@ -10,18 +10,18 @@ module Clusters
loggable_arguments 1
def perform(cluster_id, service_name)
def perform(cluster_id, integration_name)
cluster = Clusters::Cluster.find_by_id(cluster_id)
raise cluster_missing_error(service_name) unless cluster
raise cluster_missing_error(integration_name) unless cluster
service = "#{service_name}_service".to_sym
cluster.all_projects.with_service(service).find_each do |project|
project.public_send(service).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend
integration = ::Project.integration_association_name(integration_name).to_sym
cluster.all_projects.with_service(integration).find_each do |project|
project.public_send(integration).update!(active: false) # rubocop:disable GitlabSecurity/PublicSend
end
end
def cluster_missing_error(service)
ActiveRecord::RecordNotFound.new("Can't deactivate #{service} services, host cluster not found! Some inconsistent records may be left in database.")
def cluster_missing_error(integration_name)
ActiveRecord::RecordNotFound.new("Can't deactivate #{integration_name} integrations, host cluster not found! Some inconsistent records may be left in database.")
end
end
end
......
......@@ -15,12 +15,12 @@ module Projects
return unless project
create_prometheus_service(project)
create_prometheus_integration(project)
end
private
def create_prometheus_service(project)
def create_prometheus_integration(project)
service = project.find_or_initialize_service(::Integrations::Prometheus.to_param)
# If the service has already been inserted in the database, that
......
......@@ -28,7 +28,7 @@ use with Prometheus webhooks. If you have manual configuration enabled, an
This section contains the needed **URL** and **Authorization Key**. The
**Reset Key** button invalidates the key and generates a new one.
![Prometheus service configuration of Alerts](img/prometheus_service_alerts.png)
![Prometheus integration configuration of Alerts](img/prometheus_integration_alerts.png)
To send GitLab alert notifications, copy the **URL** and **Authorization Key** into the
[`webhook_configs`](https://prometheus.io/docs/alerting/latest/configuration/#webhook_config)
......
......@@ -152,7 +152,7 @@ module EE
scope :with_security_reports_stored, -> { where('EXISTS (?)', ::Vulnerabilities::Finding.scoped_project.select(1)) }
scope :with_security_reports, -> { where('EXISTS (?)', ::Ci::JobArtifact.security_reports.scoped_project.select(1)) }
scope :with_github_service_pipeline_events, -> { joins(:github_service).merge(::Integrations::Github.pipeline_hooks) }
scope :with_active_prometheus_service, -> { joins(:prometheus_service).merge(::Integrations::Prometheus.active) }
scope :with_active_prometheus_integration, -> { joins(:prometheus_integration).merge(::Integrations::Prometheus.active) }
scope :with_enabled_incident_sla, -> { joins(:incident_management_setting).where(project_incident_management_settings: { sla_timer: true }) }
scope :mirrored_with_enabled_pipelines, -> do
joins(:project_feature).mirror.where(mirror_trigger_builds: true,
......@@ -160,7 +160,7 @@ module EE
end
scope :with_slack_integration, -> { joins(:slack_integration) }
scope :with_slack_slash_commands_integration, -> { joins(:slack_slash_commands_integration) }
scope :with_prometheus_service, -> { joins(:prometheus_service) }
scope :with_prometheus_integration, -> { joins(:prometheus_integration) }
scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted }
scope :not_aimed_for_deletion, -> { where(marked_for_deletion_at: nil) }
scope :with_repos_templates, -> { where(namespace_id: ::Gitlab::CurrentSettings.current_application_settings.custom_project_templates_group_id) }
......
......@@ -15,7 +15,7 @@ RSpec.describe 'Prometheus custom metrics', :js do
before do
stub_request(:get, prometheus_query_with_time_url('avg(metric)', Time.now.utc))
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
create(:prometheus_integration, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
visit_project_integration('Prometheus')
end
......
......@@ -261,7 +261,7 @@ RSpec.describe Gitlab::UsageData do
project = create(:project, creator: user)
create(:integrations_slack, project: project)
create(:slack_slash_commands_integration, project: project)
create(:prometheus_service, project: project)
create(:prometheus_integration, project: project)
end
expect(described_class.usage_activity_by_stage_configure({})).to include(
......@@ -465,7 +465,7 @@ RSpec.describe Gitlab::UsageData do
user = create(:user, dashboard: 'operations')
project = create(:project, creator: user)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:prometheus_integration, project: project)
create(:project_incident_management_setting, :sla_enabled, project: project)
end
......
......@@ -305,13 +305,13 @@ RSpec.describe Project do
end
end
describe '.with_active_prometheus_service' do
describe '.with_active_prometheus_integration' do
it 'returns the correct project' do
project_with_active_prometheus_service = create(:prometheus_project)
project_without_active_prometheus_service = create(:project)
project_with_active_prometheus_integration = create(:prometheus_project)
project_without_active_prometheus_integration = create(:project)
expect(described_class.with_active_prometheus_service).to include(project_with_active_prometheus_service)
expect(described_class.with_active_prometheus_service).not_to include(project_without_active_prometheus_service)
expect(described_class.with_active_prometheus_integration).to include(project_with_active_prometheus_integration)
expect(described_class.with_active_prometheus_integration).not_to include(project_without_active_prometheus_integration)
end
end
......
......@@ -28,7 +28,7 @@ RSpec.describe 'getting Alert Management HTTP Integrations' do
let_it_be(:maintainer) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
let_it_be(:other_project_http_integration) { create(:alert_management_http_integration) }
......
......@@ -7,7 +7,7 @@ RSpec.describe 'getting Alert Management Integrations' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
......@@ -79,13 +79,13 @@ RSpec.describe 'getting Alert Management Integrations' do
'apiUrl' => nil
},
{
'id' => GitlabSchema.id_from_object(prometheus_service).to_s,
'id' => GitlabSchema.id_from_object(prometheus_integration).to_s,
'type' => 'PROMETHEUS',
'name' => 'Prometheus',
'active' => prometheus_service.manual_configuration?,
'active' => prometheus_integration.manual_configuration?,
'token' => project_alerting_setting.token,
'url' => "http://localhost/#{project.full_path}/prometheus/alerts/notify.json",
'apiUrl' => prometheus_service.api_url
'apiUrl' => prometheus_integration.api_url
}
)
end
......
......@@ -8,7 +8,7 @@ RSpec.describe NetworkPolicyMetricsWorker, :clean_gitlab_redis_shared_state do
let!(:cluster) { create(:cluster, :with_installed_helm, :provided_by_gcp, :project) }
let!(:cilium_application) { create(:clusters_applications_cilium, :installed, cluster: cluster) }
let!(:prometheus_application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
let!(:prometheus_service) { create(:prometheus_service, project: cluster.projects.first) }
let!(:prometheus_integration) { create(:prometheus_integration, project: cluster.projects.first) }
let(:client) { instance_double('Gitlab::PrometheusClient') }
let(:query_response) do
......@@ -45,8 +45,8 @@ RSpec.describe NetworkPolicyMetricsWorker, :clean_gitlab_redis_shared_state do
end
end
context 'with prometheus service on another project' do
let!(:prometheus_service_without_cilium) { create(:prometheus_service) }
context 'with prometheus integration on another project' do
let!(:prometheus_integration_without_cilium) { create(:prometheus_integration) }
it 'does not count projects without cilium' do
worker.perform
......@@ -58,7 +58,7 @@ RSpec.describe NetworkPolicyMetricsWorker, :clean_gitlab_redis_shared_state do
context 'with Prometheus client error' do
let!(:cluster2) { create(:cluster, :with_installed_helm, :provided_by_gcp, :project) }
let!(:cilium_application2) { create(:clusters_applications_cilium, :installed, cluster: cluster2) }
let!(:prometheus_service2) { create(:prometheus_service, project: cluster2.projects.first) }
let!(:prometheus_integration2) { create(:prometheus_integration, project: cluster2.projects.first) }
before do
idx = 0
......@@ -75,10 +75,10 @@ RSpec.describe NetworkPolicyMetricsWorker, :clean_gitlab_redis_shared_state do
context 'with unconfigured adapter' do
let!(:cluster2) { create(:cluster, :with_installed_helm, :provided_by_gcp, :project) }
let!(:cilium_application2) { create(:clusters_applications_cilium, :installed, cluster: cluster2) }
let!(:prometheus_service2) { create(:prometheus_service, project: cluster2.projects.first) }
let!(:prometheus_integration2) { create(:prometheus_integration, project: cluster2.projects.first) }
before do
prometheus_service.update_attribute(:api_url, 'invalid_url')
prometheus_integration.update_attribute(:api_url, 'invalid_url')
end
it 'adds usage of the rest' do
......
......@@ -109,7 +109,7 @@ module Gitlab
service = result[:project].find_or_initialize_service('prometheus')
unless service.update(prometheus_service_attributes)
unless service.update(prometheus_integration_attributes)
log_error('Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}' % { errors: service.errors.full_messages })
return error(_('Could not save prometheus manual configuration'))
end
......@@ -156,7 +156,7 @@ module Gitlab
::Gitlab::Prometheus::Internal.uri
end
def prometheus_service_attributes
def prometheus_integration_attributes
{
api_url: internal_prometheus_server_address_uri,
manual_configuration: true,
......
......@@ -258,8 +258,8 @@ RSpec.describe Projects::ServicesController do
end
end
context 'Prometheus service' do
let!(:service) { create(:prometheus_service, project: project) }
context 'Prometheus integration' do
let!(:service) { create(:prometheus_integration, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do
......@@ -276,8 +276,8 @@ RSpec.describe Projects::ServicesController do
expect(controller).to set_flash.now[:alert].to(expected_alert)
end
it 'does not modify service' do
expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_service.reload.attributes }
it 'does not modify integration' do
expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_integration.reload.attributes }
end
end
......@@ -286,8 +286,8 @@ RSpec.describe Projects::ServicesController do
stub_feature_flags(settings_operations_prometheus_service: false)
end
it 'modifies service' do
expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_service.reload.attributes }
it 'modifies integration' do
expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_integration.reload.attributes }
end
end
end
......
......@@ -27,7 +27,7 @@ FactoryBot.define do
end
end
factory :prometheus_service, class: 'Integrations::Prometheus' do
factory :prometheus_integration, class: 'Integrations::Prometheus' do
project
active { true }
properties do
......
......@@ -413,7 +413,7 @@ FactoryBot.define do
factory :prometheus_project, parent: :project do
after :create do |project|
project.create_prometheus_service(
project.create_prometheus_integration(
active: true,
properties: {
api_url: 'https://prometheus.example.com/',
......
......@@ -18,7 +18,7 @@ FactoryBot.define do
create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3, total_issue_count: 3)
create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3)
create(:jira_import_state, :scheduled, project: projects[1], label: jira_label)
create(:prometheus_service, project: projects[1])
create(:prometheus_integration, project: projects[1])
create(:service, project: projects[1], type: 'JenkinsService', active: true)
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true)
......
......@@ -50,7 +50,7 @@ RSpec.describe 'Alert Management index', :js do
end
context 'when the prometheus integration is enabled' do
let_it_be(:integration) { create(:prometheus_service, project: project) }
let_it_be(:integration) { create(:prometheus_integration, project: project) }
it_behaves_like 'alert page with title, filtered search, and table'
end
......
......@@ -10,7 +10,7 @@ RSpec.describe 'Prometheus external alerts', :js do
context 'with manual configuration' do
before do
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
create(:prometheus_integration, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
end
it 'shows the Alerts section' do
......
......@@ -7,7 +7,7 @@ RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :con
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'services-project') }
let!(:service) { create(:prometheus_service, project: project) }
let!(:integration) { create(:prometheus_integration, project: project) }
let(:user) { project.owner }
render_views
......@@ -28,7 +28,7 @@ RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :con
get :edit, params: {
namespace_id: namespace,
project_id: project,
id: service.to_param
id: integration.to_param
}
expect(response).to be_successful
......
......@@ -19,7 +19,7 @@ RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Create do
end
context 'when Prometheus Integration already exists' do
let_it_be(:existing_integration) { create(:prometheus_service, project: project) }
let_it_be(:existing_integration) { create(:prometheus_integration, project: project) }
it 'returns errors' do
expect(resolve).to eq(
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Mutations::AlertManagement::PrometheusIntegration::ResetToken do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
let_it_be(:integration) { create(:prometheus_integration, project: project) }
let(:args) { { id: GitlabSchema.id_from_object(integration) } }
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Update do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
let_it_be(:integration) { create(:prometheus_integration, project: project) }
let(:args) { { id: GitlabSchema.id_from_object(integration), active: false, api_url: 'http://new-url.com' } }
......
......@@ -9,7 +9,7 @@ RSpec.describe Resolvers::AlertManagement::HttpIntegrationsResolver do
let_it_be(:developer) { create(:user) }
let_it_be(:maintainer) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:prometheus_integration) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
let_it_be(:other_proj_integration) { create(:alert_management_http_integration) }
......
......@@ -8,11 +8,11 @@ RSpec.describe Resolvers::AlertManagement::IntegrationsResolver do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:project2) { create(:project) }
let_it_be(:prometheus_integration) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
let_it_be(:other_proj_integration) { create(:alert_management_http_integration, project: project2) }
let_it_be(:other_proj_prometheus_integration) { create(:prometheus_service, project: project2) }
let_it_be(:other_proj_prometheus_integration) { create(:prometheus_integration, project: project2) }
let(:params) { {} }
......
......@@ -17,7 +17,7 @@ RSpec.describe GitlabSchema.types['AlertManagementPrometheusIntegration'] do
end
end
let_it_be_with_reload(:integration) { create(:prometheus_service) }
let_it_be_with_reload(:integration) { create(:prometheus_integration) }
let_it_be(:user) { create(:user, maintainer_projects: [integration.project]) }
it_behaves_like 'has field with value', 'name' do
......@@ -50,7 +50,7 @@ RSpec.describe GitlabSchema.types['AlertManagementPrometheusIntegration'] do
describe 'a group integration' do
let_it_be(:group) { create(:group) }
let_it_be(:integration) { create(:prometheus_service, project: nil, group: group) }
let_it_be(:integration) { create(:prometheus_integration, project: nil, group: group) }
# Since it is impossible to authorize the parent here, given that the
# project is nil, all fields should be redacted:
......
......@@ -122,7 +122,7 @@ RSpec.describe EnvironmentsHelper do
end
context 'has_managed_prometheus' do
context 'without prometheus service' do
context 'without prometheus integration' do
it "doesn't have managed prometheus" do
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
......@@ -130,12 +130,12 @@ RSpec.describe EnvironmentsHelper do
end
end
context 'with prometheus service' do
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
context 'with prometheus integration' do
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
context 'when manual prometheus service is active' do
context 'when manual prometheus integration is active' do
it "doesn't have managed prometheus" do
prometheus_service.update!(manual_configuration: true)
prometheus_integration.update!(manual_configuration: true)
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
......@@ -143,9 +143,9 @@ RSpec.describe EnvironmentsHelper do
end
end
context 'when prometheus service is inactive' do
context 'when prometheus integration is inactive' do
it "doesn't have managed prometheus" do
prometheus_service.update!(manual_configuration: false)
prometheus_integration.update!(manual_configuration: false)
expect(metrics_data).to include(
'has_managed_prometheus' => 'false'
......
......@@ -20,19 +20,19 @@ RSpec.describe OperationsHelper do
allow(helper).to receive(:can?).with(user, :admin_operations, project) { true }
end
context 'initial service configuration' do
let_it_be(:prometheus_service) { ::Integrations::Prometheus.new(project: project) }
context 'initial integration configuration' do
let_it_be(:prometheus_integration) { ::Integrations::Prometheus.new(project: project) }
before do
allow(project).to receive(:find_or_initialize_service).and_call_original
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return(prometheus_service)
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return(prometheus_integration)
end
it 'returns the correct values' do
expect(subject).to eq(
'alerts_setup_url' => help_page_path('operations/incident_management/integrations.md', anchor: 'configuration'),
'alerts_usage_url' => project_alert_management_index_path(project),
'prometheus_form_path' => project_service_path(project, prometheus_service),
'prometheus_form_path' => project_service_path(project, prometheus_integration),
'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(project),
'prometheus_authorization_key' => nil,
'prometheus_api_url' => nil,
......@@ -53,15 +53,15 @@ RSpec.describe OperationsHelper do
end
context 'with external Prometheus configured' do
let_it_be(:prometheus_service, reload: true) do
create(:prometheus_service, project: project)
let_it_be(:prometheus_integration, reload: true) do
create(:prometheus_integration, project: project)
end
context 'with external Prometheus enabled' do
it 'returns the correct values' do
expect(subject).to include(
'prometheus_activated' => 'true',
'prometheus_api_url' => prometheus_service.api_url
'prometheus_api_url' => prometheus_integration.api_url
)
end
end
......@@ -71,7 +71,7 @@ RSpec.describe OperationsHelper do
it 'returns the correct values' do
expect(subject).to include(
'prometheus_activated' => 'false',
'prometheus_api_url' => prometheus_service.api_url
'prometheus_api_url' => prometheus_integration.api_url
)
end
end
......@@ -79,11 +79,11 @@ RSpec.describe OperationsHelper do
let(:cluster_managed) { false }
before do
allow(prometheus_service)
allow(prometheus_integration)
.to receive(:prometheus_available?)
.and_return(cluster_managed)
prometheus_service.update!(manual_configuration: false)
prometheus_integration.update!(manual_configuration: false)
end
include_examples 'Prometheus is disabled'
......@@ -101,7 +101,7 @@ RSpec.describe OperationsHelper do
it 'returns the correct values' do
expect(subject).to include(
'prometheus_authorization_key' => project_alerting_setting.token,
'prometheus_api_url' => prometheus_service.api_url
'prometheus_api_url' => prometheus_integration.api_url
)
end
end
......
......@@ -41,12 +41,12 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
context 'with prometheus service' do
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
context 'with prometheus integration' do
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
context 'when manual prometheus service is active' do
context 'when manual prometheus integration is active' do
it "enables alert management and doesn't show managed prometheus" do
prometheus_service.update!(manual_configuration: true)
prometheus_integration.update!(manual_configuration: true)
expect(data).to include(
'alert-management-enabled' => 'true'
......@@ -69,9 +69,9 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
context 'when prometheus service is inactive' do
context 'when prometheus integration is inactive' do
it 'disables alert management and hides managed prometheus' do
prometheus_service.update!(manual_configuration: false)
prometheus_integration.update!(manual_configuration: false)
expect(data).to include(
'alert-management-enabled' => 'false'
......@@ -83,7 +83,7 @@ RSpec.describe Projects::AlertManagementHelper do
end
end
context 'without prometheus service' do
context 'without prometheus integration' do
it "doesn't have managed prometheus" do
expect(data).to include(
'has-managed-prometheus' => 'false'
......
......@@ -63,11 +63,11 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
application_setting.update(allow_local_requests_from_web_hooks_and_services: true)
end
shared_examples 'has prometheus service' do |server_address|
shared_examples 'has prometheus integration' do |server_address|
it do
expect(result[:status]).to eq(:success)
prometheus = project.prometheus_service
prometheus = project.prometheus_integration
expect(prometheus).not_to eq(nil)
expect(prometheus.api_url).to eq(server_address)
expect(prometheus.active).to eq(true)
......@@ -75,7 +75,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
end
end
it_behaves_like 'has prometheus service', 'http://localhost:9090'
it_behaves_like 'has prometheus integration', 'http://localhost:9090'
it 'is idempotent' do
result1 = subject.execute
......@@ -134,7 +134,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
expect(application_setting.reload.self_monitoring_project_id).to eq(project.id)
end
it 'creates a Prometheus service' do
it 'creates a Prometheus integration' do
expect(result[:status]).to eq(:success)
integrations = result[:project].reload.integrations
......@@ -193,12 +193,12 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
end
end
context 'when local requests from hooks and services are not allowed' do
context 'when local requests from hooks and integrations are not allowed' do
before do
application_setting.update(allow_local_requests_from_web_hooks_and_services: false)
end
it_behaves_like 'has prometheus service', 'http://localhost:9090'
it_behaves_like 'has prometheus integration', 'http://localhost:9090'
end
context 'with non default prometheus address' do
......@@ -211,18 +211,18 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
}
end
it_behaves_like 'has prometheus service', 'https://localhost:9090'
it_behaves_like 'has prometheus integration', 'https://localhost:9090'
context 'with :9090 symbol' do
let(:server_address) { :':9090' }
it_behaves_like 'has prometheus service', 'http://localhost:9090'
it_behaves_like 'has prometheus integration', 'http://localhost:9090'
end
context 'with 0.0.0.0:9090' do
let(:server_address) { '0.0.0.0:9090' }
it_behaves_like 'has prometheus service', 'http://localhost:9090'
it_behaves_like 'has prometheus integration', 'http://localhost:9090'
end
end
......@@ -233,7 +233,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
it 'does not fail' do
expect(result).to include(status: :success)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......@@ -244,7 +244,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
it 'does not fail' do
expect(result).to include(status: :success)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......@@ -258,7 +258,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
it 'does not configure prometheus' do
expect(result).to include(status: :success)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......@@ -267,7 +267,7 @@ RSpec.describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService
it 'does not configure prometheus' do
expect(result).to include(status: :success)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......
......@@ -373,7 +373,7 @@ project:
- irker_integration
- packagist_integration
- pivotaltracker_integration
- prometheus_service
- prometheus_integration
- flowdock_integration
- assembla_integration
- asana_integration
......
......@@ -9,31 +9,31 @@ RSpec.describe Gitlab::Prometheus::Adapter do
subject { described_class.new(project, cluster) }
describe '#prometheus_adapter' do
context 'prometheus service can execute queries' do
let(:prometheus_service) { double(:prometheus_service, can_query?: true) }
context 'prometheus integration can execute queries' do
let(:prometheus_integration) { double(:prometheus_integration, can_query?: true) }
before do
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_integration
end
it 'return prometheus service as prometheus adapter' do
expect(subject.prometheus_adapter).to eq(prometheus_service)
it 'return prometheus integration as prometheus adapter' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
end
context 'with cluster with prometheus available' do
let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns prometheus service' do
expect(subject.prometheus_adapter).to eq(prometheus_service)
it 'returns prometheus integration' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
end
end
end
context "prometheus service can't execute queries" do
let(:prometheus_service) { double(:prometheus_service, can_query?: false) }
context "prometheus integration can't execute queries" do
let(:prometheus_integration) { double(:prometheus_integration, can_query?: false) }
before do
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_integration
end
context 'with cluster with prometheus disabled' do
......
......@@ -20,7 +20,7 @@ RSpec.describe Clusters::Integrations::Prometheus do
let(:cluster) { create(:cluster, :with_installed_helm) }
it 'deactivates prometheus_service' do
it 'deactivates prometheus_integration' do
expect(Clusters::Applications::DeactivateServiceWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
......@@ -35,7 +35,7 @@ RSpec.describe Clusters::Integrations::Prometheus do
let(:enabled) { true }
context 'when no change to enabled status' do
it 'does not touch project services' do
it 'does not touch project integrations' do
integration # ensure integration exists before we set the expectations
expect(Clusters::Applications::DeactivateServiceWorker)
......@@ -51,7 +51,7 @@ RSpec.describe Clusters::Integrations::Prometheus do
context 'when enabling' do
let(:enabled) { false }
it 'deactivates prometheus_service' do
it 'deactivates prometheus_integration' do
expect(Clusters::Applications::ActivateServiceWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
......@@ -62,7 +62,7 @@ RSpec.describe Clusters::Integrations::Prometheus do
context 'when disabling' do
let(:enabled) { true }
it 'activates prometheus_service' do
it 'activates prometheus_integration' do
expect(Clusters::Applications::DeactivateServiceWorker)
.to receive(:perform_async).with(cluster.id, 'prometheus')
......
......@@ -7,7 +7,7 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
let(:project) { create(:prometheus_project) }
let(:service) { project.prometheus_service }
let(:integration) { project.prometheus_integration }
let(:described_class) do
Class.new do
......@@ -29,10 +29,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
context 'with valid data' do
subject { service.query(:validate, query) }
subject { integration.query(:validate, query) }
before do
stub_reactive_cache(service, validation_respone, validation_query, query)
stub_reactive_cache(integration, validation_respone, validation_query, query)
end
it 'returns query data' do
......@@ -49,10 +49,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
context 'with valid data' do
subject { service.query(:environment, environment) }
subject { integration.query(:environment, environment) }
before do
stub_reactive_cache(service, prometheus_data, environment_query, environment.id)
stub_reactive_cache(integration, prometheus_data, environment_query, environment.id)
end
it 'returns reactive data' do
......@@ -66,11 +66,11 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
let(:prometheus_client) { double(:prometheus_client, label_values: nil) }
context 'with valid data' do
subject { service.query(:matched_metrics) }
subject { integration.query(:matched_metrics) }
before do
allow(service).to receive(:prometheus_client).and_return(prometheus_client)
synchronous_reactive_cache(service)
allow(integration).to receive(:prometheus_client).and_return(prometheus_client)
synchronous_reactive_cache(integration)
end
it 'returns reactive data' do
......@@ -89,10 +89,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
context 'with valid data' do
subject { service.query(:deployment, deployment) }
subject { integration.query(:deployment, deployment) }
before do
stub_reactive_cache(service, prometheus_data, deployment_query, deployment.id)
stub_reactive_cache(integration, prometheus_data, deployment_query, deployment.id)
end
it 'returns reactive data' do
......@@ -111,10 +111,10 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
context 'with valid data' do
subject { service.query(:additional_metrics_environment, environment, *time_window) }
subject { integration.query(:additional_metrics_environment, environment, *time_window) }
before do
stub_reactive_cache(service, prometheus_data, additional_metrics_environment_query, environment.id, *time_window)
stub_reactive_cache(integration, prometheus_data, additional_metrics_environment_query, environment.id, *time_window)
end
it 'returns reactive data' do
......@@ -128,21 +128,21 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
let(:environment) { create(:environment, slug: 'env-slug') }
before do
service.manual_configuration = true
service.active = true
integration.manual_configuration = true
integration.active = true
end
subject do
service.calculate_reactive_cache(environment_query.name, environment.id)
integration.calculate_reactive_cache(environment_query.name, environment.id)
end
around do |example|
freeze_time { example.run }
end
context 'when service is inactive' do
context 'when integration is inactive' do
before do
service.active = false
integration.active = false
end
it { is_expected.to be_nil }
......@@ -168,7 +168,7 @@ RSpec.describe PrometheusAdapter, :use_clean_rails_memory_store_caching do
end
describe '#build_query_args' do
subject { service.build_query_args(*args) }
subject { integration.build_query_args(*args) }
context 'when active record models are included' do
let(:args) { [double(:environment, id: 12)] }
......
......@@ -15,35 +15,35 @@ RSpec.describe DeploymentMetrics do
context 'when deployment is success' do
let(:deployment) { create(:deployment, :success) }
context 'without a monitoring service' do
context 'without a monitoring integration' do
it { is_expected.to be_falsy }
end
context 'with a Prometheus Service' do
let(:prometheus_service) { instance_double(::Integrations::Prometheus, can_query?: true, configured?: true) }
context 'with a Prometheus integration' do
let(:prometheus_integration) { instance_double(::Integrations::Prometheus, can_query?: true, configured?: true) }
before do
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_integration
end
it { is_expected.to be_truthy }
end
context 'with a Prometheus Service that cannot query' do
let(:prometheus_service) { instance_double(::Integrations::Prometheus, configured?: true, can_query?: false) }
context 'with a Prometheus integration that cannot query' do
let(:prometheus_integration) { instance_double(::Integrations::Prometheus, configured?: true, can_query?: false) }
before do
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_integration
end
it { is_expected.to be_falsy }
end
context 'with a Prometheus Service that is not configured' do
let(:prometheus_service) { instance_double(::Integrations::Prometheus, configured?: false, can_query?: false) }
context 'with a Prometheus integration that is not configured' do
let(:prometheus_integration) { instance_double(::Integrations::Prometheus, configured?: false, can_query?: false) }
before do
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
allow(deployment.project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_integration
end
it { is_expected.to be_falsy }
......
......@@ -341,36 +341,36 @@ RSpec.describe Integration do
describe '.build_from_integration' do
context 'when integration is invalid' do
let(:integration) do
build(:prometheus_service, :template, active: true, properties: {})
let(:template_integration) do
build(:prometheus_integration, :template, active: true, properties: {})
.tap { |integration| integration.save!(validate: false) }
end
it 'sets service to inactive' do
service = described_class.build_from_integration(integration, project_id: project.id)
it 'sets integration to inactive' do
integration = described_class.build_from_integration(template_integration, project_id: project.id)
expect(service).to be_valid
expect(service.active).to be false
expect(integration).to be_valid
expect(integration.active).to be false
end
end
context 'when integration is an instance-level integration' do
let(:integration) { create(:jira_integration, :instance) }
let(:instance_integration) { create(:jira_integration, :instance) }
it 'sets inherit_from_id from integration' do
service = described_class.build_from_integration(integration, project_id: project.id)
integration = described_class.build_from_integration(instance_integration, project_id: project.id)
expect(service.inherit_from_id).to eq(integration.id)
expect(integration.inherit_from_id).to eq(instance_integration.id)
end
end
context 'when integration is a group-level integration' do
let(:integration) { create(:jira_integration, group: group, project: nil) }
let(:group_integration) { create(:jira_integration, group: group, project: nil) }
it 'sets inherit_from_id from integration' do
service = described_class.build_from_integration(integration, project_id: project.id)
integration = described_class.build_from_integration(group_integration, project_id: project.id)
expect(service.inherit_from_id).to eq(integration.id)
expect(integration.inherit_from_id).to eq(group_integration.id)
end
end
......@@ -531,9 +531,9 @@ RSpec.describe Integration do
describe '.create_from_active_default_integrations' do
context 'with an active integration template' do
let_it_be(:template_integration) { create(:prometheus_service, :template, api_url: 'https://prometheus.template.com/') }
let_it_be(:template_integration) { create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/') }
it 'creates a service from the template' do
it 'creates an integration from the template' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.integrations.size).to eq(1)
......@@ -542,9 +542,9 @@ RSpec.describe Integration do
end
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/') }
let!(:instance_integration) { create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates a service from the instance-level integration' do
it 'creates an integration from the instance-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.integrations.size).to eq(1)
......@@ -553,7 +553,7 @@ RSpec.describe Integration do
end
context 'passing a group' do
it 'creates a service from the instance-level integration' do
it 'creates an integration from the instance-level integration' do
described_class.create_from_active_default_integrations(group, :group_id)
expect(group.reload.integrations.size).to eq(1)
......@@ -563,9 +563,9 @@ RSpec.describe Integration do
end
context 'with an active group-level integration' do
let!(:group_integration) { create(:prometheus_service, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group_integration) { create(:prometheus_integration, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
it 'creates a service from the group-level integration' do
it 'creates an integration from the group-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.integrations.size).to eq(1)
......@@ -576,7 +576,7 @@ RSpec.describe Integration do
context 'passing a group' do
let!(:subgroup) { create(:group, parent: group) }
it 'creates a service from the group-level integration' do
it 'creates an integration from the group-level integration' do
described_class.create_from_active_default_integrations(subgroup, :group_id)
expect(subgroup.reload.integrations.size).to eq(1)
......@@ -586,11 +586,11 @@ RSpec.describe Integration do
end
context 'with an active subgroup' do
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup) { create(:group, parent: group) }
let(:project) { create(:project, group: subgroup) }
it 'creates a service from the subgroup-level integration' do
it 'creates an integration from the subgroup-level integration' do
described_class.create_from_active_default_integrations(project, :project_id, with_templates: true)
expect(project.reload.integrations.size).to eq(1)
......@@ -603,7 +603,7 @@ RSpec.describe Integration do
context 'traversal queries' do
shared_examples 'correct ancestor order' do
it 'creates a service from the subgroup-level integration' do
it 'creates an integration from the subgroup-level integration' do
described_class.create_from_active_default_integrations(sub_subgroup, :group_id)
sub_subgroup.reload
......@@ -613,10 +613,10 @@ RSpec.describe Integration do
expect(sub_subgroup.integrations.first.inherit_from_id).to eq(subgroup_integration.id)
end
context 'having a service inheriting settings' do
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, inherit_from_id: group_integration.id, api_url: 'https://prometheus.subgroup.com/') }
context 'having an integration inheriting settings' do
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, inherit_from_id: group_integration.id, api_url: 'https://prometheus.subgroup.com/') }
it 'creates a service from the group-level integration' do
it 'creates an integration from the group-level integration' do
described_class.create_from_active_default_integrations(sub_subgroup, :group_id)
sub_subgroup.reload
......@@ -658,11 +658,11 @@ RSpec.describe Integration do
let_it_be(:subgroup2) { create(:group, parent: group) }
let_it_be(:project1) { create(:project, group: subgroup1) }
let_it_be(:project2) { create(:project, group: subgroup2) }
let_it_be(:group_integration) { create(:prometheus_service, group: group, project: nil) }
let_it_be(:subgroup_integration1) { create(:prometheus_service, group: subgroup1, project: nil, inherit_from_id: group_integration.id) }
let_it_be(:subgroup_integration2) { create(:prometheus_service, group: subgroup2, project: nil) }
let_it_be(:project_integration1) { create(:prometheus_service, group: nil, project: project1, inherit_from_id: group_integration.id) }
let_it_be(:project_integration2) { create(:prometheus_service, group: nil, project: project2, inherit_from_id: subgroup_integration2.id) }
let_it_be(:group_integration) { create(:prometheus_integration, group: group, project: nil) }
let_it_be(:subgroup_integration1) { create(:prometheus_integration, group: subgroup1, project: nil, inherit_from_id: group_integration.id) }
let_it_be(:subgroup_integration2) { create(:prometheus_integration, group: subgroup2, project: nil) }
let_it_be(:project_integration1) { create(:prometheus_integration, group: nil, project: project1, inherit_from_id: group_integration.id) }
let_it_be(:project_integration2) { create(:prometheus_integration, group: nil, project: project2, inherit_from_id: subgroup_integration2.id) }
it 'returns the groups and projects inheriting from integration ancestors', :aggregate_failures do
expect(described_class.inherited_descendants_from_self_or_ancestors_from(group_integration)).to eq([subgroup_integration1, project_integration1])
......
This diff is collapsed.
......@@ -1563,7 +1563,7 @@ RSpec.describe Project, factory_default: :keep do
end
it 'avoid n + 1' do
expect { described_class.with_service(:prometheus_service).map(&:prometheus_service) }.not_to exceed_query_limit(1)
expect { described_class.with_service(:prometheus_integration).map(&:prometheus_integration) }.not_to exceed_query_limit(1)
end
end
......@@ -3085,8 +3085,8 @@ RSpec.describe Project, factory_default: :keep do
context 'LFS disabled in group' do
before do
stub_lfs_setting(enabled: true)
project.namespace.update_attribute(:lfs_enabled, false)
enable_lfs
end
it_behaves_like 'project overrides group'
......@@ -3094,14 +3094,18 @@ RSpec.describe Project, factory_default: :keep do
context 'LFS enabled in group' do
before do
stub_lfs_setting(enabled: true)
project.namespace.update_attribute(:lfs_enabled, true)
enable_lfs
end
it_behaves_like 'project overrides group'
end
describe 'LFS disabled globally' do
before do
stub_lfs_setting(enabled: false)
end
shared_examples 'it always returns false' do
it do
expect(project.lfs_enabled?).to be_falsey
......@@ -3914,10 +3918,6 @@ RSpec.describe Project, factory_default: :keep do
end
end
def enable_lfs
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
describe '#pages_url' do
let(:group) { create(:group, name: 'Group') }
let(:nested_group) { create(:group, parent: group) }
......@@ -5911,7 +5911,7 @@ RSpec.describe Project, factory_default: :keep do
subject { create(:project) }
before do
create(:prometheus_service, project: subject, api_url: 'https://prometheus.project.com/')
create(:prometheus_integration, project: subject, api_url: 'https://prometheus.project.com/')
end
it 'retrieves the integration' do
......@@ -5921,8 +5921,8 @@ RSpec.describe Project, factory_default: :keep do
context 'with an instance-level and template integrations' do
before do
create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/')
create(:prometheus_service, :template, api_url: 'https://prometheus.template.com/')
create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/')
create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/')
end
it 'builds the service from the instance if exists' do
......@@ -5932,7 +5932,7 @@ RSpec.describe Project, factory_default: :keep do
context 'with an instance-level and template integrations' do
before do
create(:prometheus_service, :template, api_url: 'https://prometheus.template.com/')
create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/')
end
it 'builds the service from the template if instance does not exists' do
......@@ -6623,13 +6623,13 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#prometheus_service_active?' do
describe '#prometheus_integration_active?' do
let(:project) { create(:project) }
subject { project.prometheus_service_active? }
subject { project.prometheus_integration_active? }
before do
create(:prometheus_service, project: project, manual_configuration: manual_configuration)
create(:prometheus_integration, project: project, manual_configuration: manual_configuration)
end
context 'when project has an activated prometheus service' do
......
......@@ -9,8 +9,8 @@ RSpec.describe IntegrationPolicy, :models do
subject(:policy) { Ability.policy_for(user, integration) }
context 'when the integration is a prometheus_service' do
let(:integration) { create(:prometheus_service) }
context 'when the integration is a prometheus_integration' do
let(:integration) { create(:prometheus_integration) }
describe 'rules' do
it { is_expected.to be_disallowed :admin_project }
......
......@@ -7,7 +7,7 @@ RSpec.describe 'Resetting a token on an existing Prometheus Integration' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
let_it_be(:integration) { create(:prometheus_integration, project: project) }
let(:mutation) do
variables = {
......
......@@ -7,7 +7,7 @@ RSpec.describe 'Updating an existing Prometheus Integration' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:integration) { create(:prometheus_service, project: project) }
let_it_be(:integration) { create(:prometheus_integration, project: project) }
let(:mutation) do
variables = {
......
......@@ -7,7 +7,7 @@ RSpec.describe 'getting Alert Management Integrations' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user) }
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let_it_be(:project_alerting_setting) { create(:project_alerting_setting, project: project) }
let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) }
let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) }
......@@ -53,15 +53,15 @@ RSpec.describe 'getting Alert Management Integrations' do
end
context 'when no extra params given' do
let(:http_integration) { integrations.first }
let(:prometheus_integration) { integrations.second }
let(:http_integration_response) { integrations.first }
let(:prometheus_integration_response) { integrations.second }
it_behaves_like 'a working graphql query'
it { expect(integrations.size).to eq(2) }
it 'returns the correct properties of the integrations' do
expect(http_integration).to include(
expect(http_integration_response).to include(
'id' => global_id_of(active_http_integration),
'type' => 'HTTP',
'name' => active_http_integration.name,
......@@ -71,14 +71,14 @@ RSpec.describe 'getting Alert Management Integrations' do
'apiUrl' => nil
)
expect(prometheus_integration).to include(
'id' => global_id_of(prometheus_service),
expect(prometheus_integration_response).to include(
'id' => global_id_of(prometheus_integration),
'type' => 'PROMETHEUS',
'name' => 'Prometheus',
'active' => prometheus_service.manual_configuration?,
'active' => prometheus_integration.manual_configuration?,
'token' => project_alerting_setting.token,
'url' => "http://localhost/#{project.full_path}/prometheus/alerts/notify.json",
'apiUrl' => prometheus_service.api_url
'apiUrl' => prometheus_integration.api_url
)
end
end
......@@ -104,7 +104,7 @@ RSpec.describe 'getting Alert Management Integrations' do
end
context 'when Prometheus Integration ID is given' do
let(:params) { { id: global_id_of(prometheus_service) } }
let(:params) { { id: global_id_of(prometheus_integration) } }
it_behaves_like 'a working graphql query'
......@@ -112,13 +112,13 @@ RSpec.describe 'getting Alert Management Integrations' do
it 'returns the correct properties of the Prometheus Integration' do
expect(integrations.first).to include(
'id' => global_id_of(prometheus_service),
'id' => global_id_of(prometheus_integration),
'type' => 'PROMETHEUS',
'name' => 'Prometheus',
'active' => prometheus_service.manual_configuration?,
'active' => prometheus_integration.manual_configuration?,
'token' => project_alerting_setting.token,
'url' => "http://localhost/#{project.full_path}/prometheus/alerts/notify.json",
'apiUrl' => prometheus_service.api_url
'apiUrl' => prometheus_integration.api_url
)
end
end
......
......@@ -161,7 +161,7 @@ RSpec.describe Groups::CreateService, '#execute' do
let(:created_group) { service.execute }
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/') }
let!(:instance_integration) { create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates a service from the instance-level integration' do
expect(created_group.integrations.count).to eq(1)
......@@ -171,7 +171,7 @@ RSpec.describe Groups::CreateService, '#execute' do
context 'with an active group-level integration' do
let(:service) { described_class.new(user, group_params.merge(parent_id: group.id)) }
let!(:group_integration) { create(:prometheus_service, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group_integration) { create(:prometheus_integration, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let(:group) do
create(:group).tap do |group|
group.add_owner(user)
......@@ -186,7 +186,7 @@ RSpec.describe Groups::CreateService, '#execute' do
context 'with an active subgroup' do
let(:service) { described_class.new(user, group_params.merge(parent_id: subgroup.id)) }
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let(:subgroup) do
create(:group, parent: group).tap do |subgroup|
subgroup.add_owner(user)
......
......@@ -585,29 +585,29 @@ RSpec.describe Projects::CreateService, '#execute' do
end
end
describe 'create service for the project' do
describe 'create integration for the project' do
subject(:project) { create_project(user, opts) }
context 'with an active service template' do
let!(:template_integration) { create(:prometheus_service, :template, api_url: 'https://prometheus.template.com/') }
context 'with an active integration template' do
let!(:template_integration) { create(:prometheus_integration, :template, api_url: 'https://prometheus.template.com/') }
it 'creates a service from the template' do
it 'creates an integration from the template' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(template_integration.api_url)
expect(project.integrations.first.inherit_from_id).to be_nil
end
context 'with an active instance-level integration' do
let!(:instance_integration) { create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/') }
let!(:instance_integration) { create(:prometheus_integration, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates a service from the instance-level integration' do
it 'creates an integration from the instance-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(instance_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(instance_integration.id)
end
context 'with an active group-level integration' do
let!(:group_integration) { create(:prometheus_service, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group_integration) { create(:prometheus_integration, group: group, project: nil, api_url: 'https://prometheus.group.com/') }
let!(:group) do
create(:group).tap do |group|
group.add_owner(user)
......@@ -621,14 +621,14 @@ RSpec.describe Projects::CreateService, '#execute' do
}
end
it 'creates a service from the group-level integration' do
it 'creates an integration from the group-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(group_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(group_integration.id)
end
context 'with an active subgroup' do
let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup_integration) { create(:prometheus_integration, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') }
let!(:subgroup) do
create(:group, parent: group).tap do |subgroup|
subgroup.add_owner(user)
......@@ -642,7 +642,7 @@ RSpec.describe Projects::CreateService, '#execute' do
}
end
it 'creates a service from the subgroup-level integration' do
it 'creates an integration from the subgroup-level integration' do
expect(project.integrations.count).to eq(1)
expect(project.integrations.first.api_url).to eq(subgroup_integration.api_url)
expect(project.integrations.first.inherit_from_id).to eq(subgroup_integration.id)
......@@ -686,7 +686,7 @@ RSpec.describe Projects::CreateService, '#execute' do
create_project(user, opts)
end
context 'when project has access to shared service' do
context 'when project has access to shared integration' do
before do
stub_feature_flags(projects_post_creation_worker: false)
end
......@@ -705,11 +705,11 @@ RSpec.describe Projects::CreateService, '#execute' do
it 'creates Integrations::Prometheus record', :aggregate_failures do
project = create_project(user, opts.merge!(namespace_id: group.id))
service = project.prometheus_service
integration = project.prometheus_integration
expect(service.active).to be true
expect(service.manual_configuration?).to be false
expect(service.persisted?).to be true
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
end
end
......@@ -722,21 +722,21 @@ RSpec.describe Projects::CreateService, '#execute' do
it 'creates Integrations::Prometheus record', :aggregate_failures do
project = create_project(user, opts)
service = project.prometheus_service
integration = project.prometheus_integration
expect(service.active).to be true
expect(service.manual_configuration?).to be false
expect(service.persisted?).to be true
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
end
it 'cleans invalid record and logs warning', :aggregate_failures do
invalid_service_record = build(:prometheus_service, properties: { api_url: nil, manual_configuration: true }.to_json)
allow(::Integrations::Prometheus).to receive(:new).and_return(invalid_service_record)
invalid_integration_record = build(:prometheus_integration, properties: { api_url: nil, manual_configuration: true }.to_json)
allow(::Integrations::Prometheus).to receive(:new).and_return(invalid_integration_record)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(an_instance_of(ActiveRecord::RecordInvalid), include(extra: { project_id: a_kind_of(Integer) }))
project = create_project(user, opts)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......@@ -744,7 +744,7 @@ RSpec.describe Projects::CreateService, '#execute' do
it 'does not persist Integrations::Prometheus record' do
project = create_project(user, opts)
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
end
......
......@@ -378,8 +378,8 @@ RSpec.describe Projects::Operations::UpdateService do
context 'prometheus integration' do
context 'prometheus params were passed into service' do
let(:prometheus_service) do
build_stubbed(:prometheus_service, project: project, properties: {
let(:prometheus_integration) do
build_stubbed(:prometheus_integration, project: project, properties: {
api_url: "http://example.prometheus.com",
manual_configuration: "0"
})
......@@ -400,12 +400,12 @@ RSpec.describe Projects::Operations::UpdateService do
expect(project)
.to receive(:find_or_initialize_service)
.with('prometheus')
.and_return(prometheus_service)
.and_return(prometheus_integration)
expect(Projects::UpdateService).to receive(:new) do |project_arg, user_arg, update_params_hash|
expect(project_arg).to eq project
expect(user_arg).to eq user
expect(update_params_hash[:prometheus_service_attributes]).to include('properties' => { 'api_url' => 'http://new.prometheus.com', 'manual_configuration' => '1' })
expect(update_params_hash[:prometheus_service_attributes]).not_to include(*%w(id project_id created_at updated_at))
expect(update_params_hash[:prometheus_integration_attributes]).to include('properties' => { 'api_url' => 'http://new.prometheus.com', 'manual_configuration' => '1' })
expect(update_params_hash[:prometheus_integration_attributes]).not_to include(*%w(id project_id created_at updated_at))
end.and_return(project_update_service)
expect(project_update_service).to receive(:execute)
......
......@@ -115,7 +115,7 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
let(:alert_manager_token) { token_input }
before do
create(:prometheus_service, project: project)
create(:prometheus_integration, project: project)
if alerting_setting
create(:project_alerting_setting,
......@@ -165,7 +165,7 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
context 'incident settings' do
before do
create(:prometheus_service, project: project)
create(:prometheus_integration, project: project)
create(:project_alerting_setting, project: project, token: token)
end
......@@ -204,7 +204,7 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
let(:process_service) { instance_double(AlertManagement::ProcessPrometheusAlertService) }
before do
create(:prometheus_service, project: project)
create(:prometheus_integration, project: project)
create(:project_alerting_setting, project: project, token: token)
end
......
......@@ -468,41 +468,41 @@ RSpec.describe Projects::UpdateService do
end
end
context 'when updating nested attributes for prometheus service' do
context 'prometheus service exists' do
let(:prometheus_service_attributes) do
attributes_for(:prometheus_service,
context 'when updating nested attributes for prometheus integration' do
context 'prometheus integration exists' do
let(:prometheus_integration_attributes) do
attributes_for(:prometheus_integration,
project: project,
properties: { api_url: "http://new.prometheus.com", manual_configuration: "0" }
)
end
let!(:prometheus_service) do
create(:prometheus_service,
let!(:prometheus_integration) do
create(:prometheus_integration,
project: project,
properties: { api_url: "http://old.prometheus.com", manual_configuration: "0" }
)
end
it 'updates existing record' do
expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) }
.to change { prometheus_service.reload.api_url }
expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
.to change { prometheus_integration.reload.api_url }
.from("http://old.prometheus.com")
.to("http://new.prometheus.com")
end
end
context 'prometheus service does not exist' do
context 'prometheus integration does not exist' do
context 'valid parameters' do
let(:prometheus_service_attributes) do
attributes_for(:prometheus_service,
let(:prometheus_integration_attributes) do
attributes_for(:prometheus_integration,
project: project,
properties: { api_url: "http://example.prometheus.com", manual_configuration: "0" }
)
end
it 'creates new record' do
expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) }
expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
.to change { ::Integrations::Prometheus.where(project: project).count }
.from(0)
.to(1)
......@@ -510,15 +510,15 @@ RSpec.describe Projects::UpdateService do
end
context 'invalid parameters' do
let(:prometheus_service_attributes) do
attributes_for(:prometheus_service,
let(:prometheus_integration_attributes) do
attributes_for(:prometheus_integration,
project: project,
properties: { api_url: nil, manual_configuration: "1" }
)
end
it 'does not create new record' do
expect { update_project(project, user, prometheus_service_attributes: prometheus_service_attributes) }
expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
.not_to change { ::Integrations::Prometheus.where(project: project).count }
end
end
......
......@@ -14,7 +14,7 @@ RSpec.describe 'projects/settings/operations/show' do
create(:project_tracing_setting, project: project)
end
let_it_be(:prometheus_service) { create(:prometheus_service, project: project) }
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
before_all do
project.add_maintainer(user)
......@@ -27,8 +27,8 @@ RSpec.describe 'projects/settings/operations/show' do
.and_return(error_tracking_setting)
allow(view).to receive(:tracing_setting)
.and_return(tracing_setting)
allow(view).to receive(:prometheus_service)
.and_return(prometheus_service)
allow(view).to receive(:prometheus_integration)
.and_return(prometheus_integration)
allow(view).to receive(:current_user).and_return(user)
end
......
......@@ -4,8 +4,8 @@ require 'spec_helper'
RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
context 'cluster exists' do
describe 'prometheus service' do
let(:service_name) { 'prometheus' }
describe 'prometheus integration' do
let(:integration_name) { 'prometheus' }
before do
create(:clusters_integrations_prometheus, cluster: cluster)
......@@ -16,9 +16,9 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'ensures Prometheus service is activated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { project.reload.prometheus_service&.active }.from(nil).to(true)
it 'ensures Prometheus integration is activated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
end
end
......@@ -26,9 +26,9 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
it 'ensures Prometheus service is activated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { project.reload.prometheus_service&.active }.from(nil).to(true)
it 'ensures Prometheus integration is activated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
end
end
......@@ -36,9 +36,9 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :instance) }
it 'ensures Prometheus service is activated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { project.reload.prometheus_service&.active }.from(nil).to(true)
it 'ensures Prometheus integration is activated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
end
end
end
......
......@@ -4,15 +4,15 @@ require 'spec_helper'
RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster exists' do
describe 'prometheus service' do
let(:service_name) { 'prometheus' }
describe 'prometheus integration' do
let(:integration_name) { 'prometheus' }
let!(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
context 'prometheus service exists' do
let!(:prometheus_service) { create(:prometheus_service, project: project, manual_configuration: false, active: true) }
context 'prometheus integration exists' do
let!(:prometheus_integration) { create(:prometheus_integration, project: project, manual_configuration: false, active: true) }
before do
integration.delete # prometheus service before save synchronises active stated with integration existence.
integration.delete # prometheus integration before save synchronises active stated with integration existence.
end
context 'cluster type: group' do
......@@ -20,9 +20,9 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { prometheus_service.reload.active }.from(true).to(false)
it 'ensures Prometheus integration is deactivated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { prometheus_integration.reload.active }.from(true).to(false)
end
end
......@@ -30,9 +30,9 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { prometheus_service.reload.active }.from(true).to(false)
it 'ensures Prometheus integration is deactivated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { prometheus_integration.reload.active }.from(true).to(false)
end
end
......@@ -40,20 +40,20 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :instance) }
it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) }
.to change { prometheus_service.reload.active }.from(true).to(false)
it 'ensures Prometheus integration is deactivated' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { prometheus_integration.reload.active }.from(true).to(false)
end
end
end
context 'prometheus service does not exist' do
context 'prometheus integration does not exist' do
context 'cluster type: project' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
it 'does not raise errors' do
expect { described_class.new.perform(cluster.id, service_name) }.not_to raise_error
expect { described_class.new.perform(cluster.id, integration_name) }.not_to raise_error
end
end
end
......
......@@ -13,16 +13,16 @@ RSpec.describe Projects::PostCreationWorker do
it_behaves_like 'an idempotent worker' do
let(:job_args) { [project.id] }
describe 'Prometheus service' do
describe 'Prometheus integration' do
context 'project is nil' do
let(:job_args) { [nil] }
it 'does not create prometheus service' do
it 'does not create prometheus integration' do
expect { subject }.not_to change { Integration.count }
end
end
context 'when project has access to shared service' do
context 'when project has access to shared integration' do
context 'Prometheus application is shared via group cluster' do
let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster, :group, groups: [group]) }
......@@ -39,10 +39,10 @@ RSpec.describe Projects::PostCreationWorker do
it 'creates an Integrations::Prometheus record', :aggregate_failures do
subject
service = project.prometheus_service
expect(service.active).to be true
expect(service.manual_configuration?).to be false
expect(service.persisted?).to be true
integration = project.prometheus_integration
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
end
end
......@@ -56,20 +56,20 @@ RSpec.describe Projects::PostCreationWorker do
it 'creates an Integrations::Prometheus record', :aggregate_failures do
subject
service = project.prometheus_service
expect(service.active).to be true
expect(service.manual_configuration?).to be false
expect(service.persisted?).to be true
integration = project.prometheus_integration
expect(integration.active).to be true
expect(integration.manual_configuration?).to be false
expect(integration.persisted?).to be true
end
it 'cleans invalid record and logs warning', :aggregate_failures do
invalid_service_record = build(:prometheus_service, properties: { api_url: nil, manual_configuration: true }.to_json)
allow(::Integrations::Prometheus).to receive(:new).and_return(invalid_service_record)
invalid_integration_record = build(:prometheus_integration, properties: { api_url: nil, manual_configuration: true }.to_json)
allow(::Integrations::Prometheus).to receive(:new).and_return(invalid_integration_record)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(an_instance_of(ActiveRecord::RecordInvalid), include(extra: { project_id: a_kind_of(Integer) })).twice
subject
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
......@@ -77,7 +77,7 @@ RSpec.describe Projects::PostCreationWorker do
it 'does not persist an Integrations::Prometheus record' do
subject
expect(project.prometheus_service).to be_nil
expect(project.prometheus_integration).to be_nil
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment