Skip to content
Snippets Groups Projects
Commit c67c7053 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason
Browse files

Use cluster integrations by default

We are removing one-click applications from GitLab but leaving the
integrations for Prometheus and Elastic Stack.

We have code in place that keeps the integration in sync with the
corresponding cluster application, and have backfilled the
ingtegrations, so we can now use them as a source of truth.

See

- Backfill Prometheus: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61502
- Backfill Elastic Stack: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61521
- Deprecation Epic: https://gitlab.com/groups/gitlab-org/-/epics/4280
parent 9ea42ff2
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 49 deletions
Loading
Loading
@@ -49,7 +49,7 @@ def invocation_metrics(environment_scope, name)
 
def has_prometheus?(environment_scope)
finders_for_scope(environment_scope).any? do |finder|
finder.cluster.application_prometheus_available?
finder.cluster.integration_prometheus_available?
end
end
 
Loading
Loading
Loading
Loading
@@ -74,7 +74,6 @@ def environment_metrics_data(environment, project = nil)
'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project),
'current_environment_name' => environment.name,
'has_metrics' => "#{environment.has_metrics?}",
'prometheus_status' => "#{environment.prometheus_status}",
'environment_state' => "#{environment.state}"
}
end
Loading
Loading
Loading
Loading
@@ -141,13 +141,13 @@ def api_groups
end
 
def install_knative_metrics
return [] unless cluster.application_prometheus_available?
return [] unless cluster.application_prometheus&.available?
 
[Gitlab::Kubernetes::KubectlCmd.apply_file(METRICS_CONFIG)]
end
 
def delete_knative_istio_metrics
return [] unless cluster.application_prometheus_available?
return [] unless cluster.application_prometheus&.available?
 
[Gitlab::Kubernetes::KubectlCmd.delete("--ignore-not-found", "-f", METRICS_CONFIG)]
end
Loading
Loading
Loading
Loading
@@ -104,8 +104,8 @@ def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateNam
delegate :available?, to: :application_helm, prefix: true, allow_nil: true
delegate :available?, to: :application_ingress, prefix: true, allow_nil: true
delegate :available?, to: :application_knative, prefix: true, allow_nil: true
delegate :available?, to: :application_elastic_stack, prefix: true, allow_nil: true
delegate :available?, to: :integration_elastic_stack, prefix: true, allow_nil: true
delegate :available?, to: :integration_prometheus, prefix: true, allow_nil: true
delegate :external_ip, to: :application_ingress, prefix: true, allow_nil: true
delegate :external_hostname, to: :application_ingress, prefix: true, allow_nil: true
 
Loading
Loading
@@ -142,7 +142,7 @@ def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateNam
scope :with_available_elasticstack, -> { joins(:application_elastic_stack).merge(::Clusters::Applications::ElasticStack.available) }
scope :with_available_cilium, -> { joins(:application_cilium).merge(::Clusters::Applications::Cilium.available) }
scope :distinct_with_deployed_environments, -> { joins(:environments).merge(::Deployment.success).distinct }
scope :preload_elasticstack, -> { preload(:application_elastic_stack) }
scope :preload_elasticstack, -> { preload(:integration_elastic_stack) }
scope :preload_environments, -> { preload(:environments) }
 
scope :managed, -> { where(managed: true) }
Loading
Loading
@@ -325,7 +325,7 @@ def kubeclient
end
 
def elastic_stack_adapter
application_elastic_stack || integration_elastic_stack
integration_elastic_stack
end
 
def elasticsearch_client
Loading
Loading
@@ -333,11 +333,7 @@ def elasticsearch_client
end
 
def elastic_stack_available?
if application_elastic_stack_available? || integration_elastic_stack_available?
true
else
false
end
!!integration_elastic_stack_available?
end
 
def kubernetes_namespace_for(environment, deployable: environment.last_deployable)
Loading
Loading
@@ -391,12 +387,8 @@ def serverless_domain
end
end
 
def application_prometheus_available?
integration_prometheus&.available? || application_prometheus&.available?
end
def prometheus_adapter
integration_prometheus || application_prometheus
integration_prometheus
end
 
private
Loading
Loading
Loading
Loading
@@ -335,10 +335,6 @@ def metrics
prometheus_adapter.query(:environment, self) if has_metrics_and_can_query?
end
 
def prometheus_status
deployment_platform&.cluster&.application_prometheus&.status_name
end
def additional_metrics(*args)
return unless has_metrics_and_can_query?
 
Loading
Loading
Loading
Loading
@@ -117,8 +117,8 @@ def prometheus_available?
return false if template?
return false unless project
 
project.all_clusters.enabled.eager_load(:application_prometheus).any? do |cluster|
cluster.application_prometheus&.available?
project.all_clusters.enabled.eager_load(:integration_prometheus).any? do |cluster|
cluster.integration_prometheus_available?
end
end
 
Loading
Loading
# frozen_string_literal: true
 
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Clusters
module Applications
class ScheduleUpdateService
Loading
Loading
@@ -7,14 +8,14 @@ class ScheduleUpdateService
 
attr_accessor :application, :project
 
def initialize(application, project)
@application = application
def initialize(cluster_prometheus_adapter, project)
@application = cluster_prometheus_adapter&.cluster&.application_prometheus
@project = project
end
 
def execute
return unless application
return unless application.managed_prometheus?
return if application.externally_installed?
 
if recently_scheduled?
worker_class.perform_in(BACKOFF_DELAY, application.name, application.id, project.id, Time.current)
Loading
Loading
Loading
Loading
@@ -105,9 +105,9 @@ def find_cluster_integration(project)
 
cluster = alert.environment.deployment_platform&.cluster
return unless cluster&.enabled?
return unless cluster.application_prometheus_available?
return unless cluster.integration_prometheus_available?
 
cluster.application_prometheus || cluster.integration_prometheus
cluster.integration_prometheus
end
 
def find_alert(project, metric)
Loading
Loading
# frozen_string_literal: true
 
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Prometheus
class CreateDefaultAlertsService < BaseService
include Gitlab::Utils::StrongMemoize
Loading
Loading
@@ -53,12 +54,12 @@ def create_alerts
end
 
def schedule_prometheus_update
return unless prometheus_application
return unless prometheus_adapter
 
::Clusters::Applications::ScheduleUpdateService.new(prometheus_application, project).execute
::Clusters::Applications::ScheduleUpdateService.new(prometheus_adapter, project).execute
end
 
def prometheus_application
def prometheus_adapter
environment.cluster_prometheus_adapter
end
 
Loading
Loading
%section.settings.no-animate.expanded.cluster-health-graphs.qa-cluster-health-section#cluster-health
- if @cluster&.application_prometheus_available?
- if @cluster&.integration_prometheus_available?
#prometheus-graphs{ data: @cluster.health_data(clusterable) }
 
- else
Loading
Loading
Loading
Loading
@@ -60,9 +60,9 @@ def serialize_environments(environments, request, response)
end
 
def prometheus_adapter
return unless cluster&.application_prometheus_available?
return unless cluster&.integration_prometheus_available?
 
cluster.application_prometheus
cluster.integration_prometheus
end
end
end
Loading
Loading
Loading
Loading
@@ -78,7 +78,7 @@
 
context 'for GitLab embedded cluster health metrics' do
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url)
stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body)
Loading
Loading
Loading
Loading
@@ -43,9 +43,9 @@
end
 
before do
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: prd_cluster, alert_manager_token: token)
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: stg_cluster, alert_manager_token: nil)
end
 
Loading
Loading
Loading
Loading
@@ -112,7 +112,7 @@
context 'with environment missing external_url' do
before do
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client
:integration_elastic_stack, :elasticsearch_client
) { es_client }
 
allow(environment).to receive(:external_url) { nil }
Loading
Loading
@@ -130,10 +130,10 @@
end
 
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client
:integration_elastic_stack, :elasticsearch_client
) { es_client }
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :chart_above_v3?
:integration_elastic_stack, :chart_above_v3?
) { chart_above_v3 }
end
 
Loading
Loading
Loading
Loading
@@ -19,9 +19,6 @@ def prometheus_adapter
end
 
def cluster_prometheus_adapter
application = cluster&.application_prometheus
return application if application&.available?
integration = cluster&.integration_prometheus
integration if integration&.available?
end
Loading
Loading
Loading
Loading
@@ -88,6 +88,7 @@
 
trait :with_installed_prometheus do
application_prometheus factory: %i(clusters_applications_prometheus installed)
integration_prometheus factory: %i(clusters_integrations_prometheus)
end
 
trait :with_all_applications do
Loading
Loading
Loading
Loading
@@ -27,7 +27,7 @@
expect(page).to have_css('.cluster-health-graphs')
end
 
context 'no prometheus installed' do
context 'no prometheus enabled' do
it 'shows install prometheus message' do
visit cluster_path
 
Loading
Loading
@@ -37,9 +37,9 @@
end
end
 
context 'when there is cluster with installed prometheus' do
context 'when there is cluster with enabled prometheus' do
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, enabled: true, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url)
end
 
Loading
Loading
Loading
Loading
@@ -173,7 +173,7 @@
 
allow(Prometheus::ProxyService).to receive(:new).and_call_original
 
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url)
stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body)
Loading
Loading
Loading
Loading
@@ -81,7 +81,7 @@ def upcoming_deployment_content_selector
 
context 'when cluster is not reachable' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let!(:application_prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
let!(:integration_prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
 
before do
allow_next_instance_of(Kubeclient::Client) do |instance|
Loading
Loading
Loading
Loading
@@ -165,7 +165,7 @@
context 'has prometheus' do
let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) }
let!(:knative) { create(:clusters_applications_knative, :installed, cluster: cluster) }
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
let(:finder) { described_class.new(project) }
 
before do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment