Commit 6df280ba authored by Michael Kozono's avatar Michael Kozono

Merge branch '330300-rename-prometheus-integration' into 'master'

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

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