Commit 4c29172f authored by Vitali Tatarintev's avatar Vitali Tatarintev

Move Prometheus clusters related classes to CE

Contributes to migration of Prometheus alerts to Core
parent e3f7cdda
...@@ -35,6 +35,16 @@ module Clusters ...@@ -35,6 +35,16 @@ module Clusters
.perform_async(application.cluster_id, ::PrometheusService.to_param) # rubocop:disable CodeReuse/ServiceClass .perform_async(application.cluster_id, ::PrometheusService.to_param) # rubocop:disable CodeReuse/ServiceClass
end end
end end
after_transition any => :updating do |application|
application.update(last_update_started_at: Time.now)
end
end
def updated_since?(timestamp)
last_update_started_at &&
last_update_started_at > timestamp &&
!update_errored?
end end
def chart def chart
...@@ -148,5 +158,3 @@ module Clusters ...@@ -148,5 +158,3 @@ module Clusters
end end
end end
end end
Clusters::Applications::Prometheus.prepend_if_ee('EE::Clusters::Applications::Prometheus')
...@@ -325,6 +325,13 @@ ...@@ -325,6 +325,13 @@
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
:idempotent: :idempotent:
- :name: gcp_cluster:cluster_update_app
:feature_category: :kubernetes_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
- :name: gcp_cluster:cluster_upgrade_app - :name: gcp_cluster:cluster_upgrade_app
:feature_category: :kubernetes_management :feature_category: :kubernetes_management
:has_external_dependencies: true :has_external_dependencies: true
...@@ -339,6 +346,13 @@ ...@@ -339,6 +346,13 @@
:resource_boundary: :cpu :resource_boundary: :cpu
:weight: 1 :weight: 1
:idempotent: :idempotent:
- :name: gcp_cluster:cluster_wait_for_app_update
:feature_category: :kubernetes_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
- :name: gcp_cluster:cluster_wait_for_ingress_ip_address - :name: gcp_cluster:cluster_wait_for_ingress_ip_address
:feature_category: :kubernetes_management :feature_category: :kubernetes_management
:has_external_dependencies: true :has_external_dependencies: true
......
...@@ -339,6 +339,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -339,6 +339,13 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
namespace :prometheus do namespace :prometheus do
resources :alerts, constraints: { id: /\d+/ }, only: [:index, :create, :show, :update, :destroy] do
post :notify, on: :collection
member do
get :metrics_dashboard
end
end
resources :metrics, constraints: { id: %r{[^\/]+} }, only: [:index, :new, :create, :edit, :update, :destroy] do resources :metrics, constraints: { id: %r{[^\/]+} }, only: [:index, :new, :create, :edit, :update, :destroy] do
get :active_common, on: :collection get :active_common, on: :collection
end end
......
# frozen_string_literal: true
require 'securerandom'
module EE
module Clusters
module Applications
module Prometheus
extend ActiveSupport::Concern
prepended do
state_machine :status do
after_transition any => :updating do |application|
application.update(last_update_started_at: Time.now)
end
end
end
def updated_since?(timestamp)
last_update_started_at &&
last_update_started_at > timestamp &&
!update_errored?
end
end
end
end
end
...@@ -199,20 +199,6 @@ ...@@ -199,20 +199,6 @@
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 2 :weight: 2
:idempotent: :idempotent:
- :name: gcp_cluster:cluster_update_app
:feature_category: :kubernetes_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
- :name: gcp_cluster:cluster_wait_for_app_update
:feature_category: :kubernetes_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
- :name: geo:geo_batch_project_registry - :name: geo:geo_batch_project_registry
:feature_category: :geo_replication :feature_category: :geo_replication
:has_external_dependencies: :has_external_dependencies:
......
...@@ -129,13 +129,6 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -129,13 +129,6 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
namespace :prometheus do namespace :prometheus do
resources :alerts, constraints: { id: /\d+/ }, only: [:index, :create, :show, :update, :destroy] do
post :notify, on: :collection
member do
get :metrics_dashboard
end
end
resources :metrics, constraints: { id: %r{[^\/]+} }, only: [] do resources :metrics, constraints: { id: %r{[^\/]+} }, only: [] do
post :validate_query, on: :collection post :validate_query, on: :collection
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe Clusters::Applications::Prometheus do
describe 'transition to updating' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
subject { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
it 'sets last_update_started_at to now' do
Timecop.freeze do
expect { subject.make_updating }.to change { subject.reload.last_update_started_at }.to be_within(1.second).of(Time.now)
end
end
end
describe '#updated_since?' do
let(:cluster) { create(:cluster) }
let(:prometheus_app) { build(:clusters_applications_prometheus, cluster: cluster) }
let(:timestamp) { Time.now - 5.minutes }
around do |example|
Timecop.freeze { example.run }
end
before do
prometheus_app.last_update_started_at = Time.now
end
context 'when app does not have status failed' do
it 'returns true when last update started after the timestamp' do
expect(prometheus_app.updated_since?(timestamp)).to be true
end
it 'returns false when last update started before the timestamp' do
expect(prometheus_app.updated_since?(Time.now + 5.minutes)).to be false
end
end
context 'when app has status failed' do
it 'returns false when last update started after the timestamp' do
prometheus_app.status = 6
expect(prometheus_app.updated_since?(timestamp)).to be false
end
end
end
end
...@@ -39,6 +39,19 @@ describe Clusters::Applications::Prometheus do ...@@ -39,6 +39,19 @@ describe Clusters::Applications::Prometheus do
end end
end end
describe 'transition to updating' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
subject { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
it 'sets last_update_started_at to now' do
Timecop.freeze do
expect { subject.make_updating }.to change { subject.reload.last_update_started_at }.to be_within(1.second).of(Time.now)
end
end
end
describe '#can_uninstall?' do describe '#can_uninstall?' do
let(:prometheus) { create(:clusters_applications_prometheus) } let(:prometheus) { create(:clusters_applications_prometheus) }
...@@ -331,6 +344,38 @@ describe Clusters::Applications::Prometheus do ...@@ -331,6 +344,38 @@ describe Clusters::Applications::Prometheus do
end end
end end
describe '#updated_since?' do
let(:cluster) { create(:cluster) }
let(:prometheus_app) { build(:clusters_applications_prometheus, cluster: cluster) }
let(:timestamp) { Time.now - 5.minutes }
around do |example|
Timecop.freeze { example.run }
end
before do
prometheus_app.last_update_started_at = Time.now
end
context 'when app does not have status failed' do
it 'returns true when last update started after the timestamp' do
expect(prometheus_app.updated_since?(timestamp)).to be true
end
it 'returns false when last update started before the timestamp' do
expect(prometheus_app.updated_since?(Time.now + 5.minutes)).to be false
end
end
context 'when app has status failed' do
it 'returns false when last update started after the timestamp' do
prometheus_app.status = 6
expect(prometheus_app.updated_since?(timestamp)).to be false
end
end
end
describe 'alert manager token' do describe 'alert manager token' do
subject { create(:clusters_applications_prometheus) } subject { create(:clusters_applications_prometheus) }
......
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