Commit fc967011 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'show-prometheus-is-updating' into 'master'

Expose prometheus status to monitor dashboard

See merge request gitlab-org/gitlab!18289
parents 72104c3b 10c819d3
...@@ -34,6 +34,7 @@ module EnvironmentsHelper ...@@ -34,6 +34,7 @@ module EnvironmentsHelper
"project-path" => project_path(project), "project-path" => project_path(project),
"tags-path" => project_tags_path(project), "tags-path" => project_tags_path(project),
"has-metrics" => "#{environment.has_metrics?}", "has-metrics" => "#{environment.has_metrics?}",
"prometheus-status" => "#{environment.prometheus_status}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url "external-dashboard-url" => project.metrics_setting_external_dashboard_url
} }
end end
......
...@@ -188,6 +188,10 @@ class Environment < ApplicationRecord ...@@ -188,6 +188,10 @@ class Environment < ApplicationRecord
prometheus_adapter.query(:environment, self) if has_metrics? prometheus_adapter.query(:environment, self) if has_metrics?
end end
def prometheus_status
deployment_platform&.cluster&.application_prometheus&.status_name
end
def additional_metrics(*args) def additional_metrics(*args)
return unless has_metrics? return unless has_metrics?
......
---
title: Expose prometheus status to monitor dashboard
merge_request: 18289
author:
type: fixed
...@@ -32,6 +32,7 @@ describe EnvironmentsHelper do ...@@ -32,6 +32,7 @@ describe EnvironmentsHelper do
'project-path' => project_path(project), 'project-path' => project_path(project),
'tags-path' => project_tags_path(project), 'tags-path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}", 'has-metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}",
'external-dashboard-url' => nil 'external-dashboard-url' => nil
) )
end end
......
...@@ -727,6 +727,51 @@ describe Environment, :use_clean_rails_memory_store_caching do ...@@ -727,6 +727,51 @@ describe Environment, :use_clean_rails_memory_store_caching do
end end
end end
describe '#prometheus_status' do
context 'when a cluster is present' do
context 'when a deployment platform is present' do
let(:cluster) { create(:cluster, :provided_by_user, :project) }
let(:environment) { create(:environment, project: cluster.project) }
subject { environment.prometheus_status }
context 'when the prometheus application status is :updating' do
let!(:prometheus) { create(:clusters_applications_prometheus, :updating, cluster: cluster) }
it { is_expected.to eq(:updating) }
end
context 'when the prometheus application state is :updated' do
let!(:prometheus) { create(:clusters_applications_prometheus, :updated, cluster: cluster) }
it { is_expected.to eq(:updated) }
end
context 'when the prometheus application is not installed' do
it { is_expected.to be_nil }
end
end
context 'when a deployment platform is not present' do
let(:cluster) { create(:cluster, :project) }
let(:environment) { create(:environment, project: cluster.project) }
subject { environment.prometheus_status }
it { is_expected.to be_nil }
end
end
context 'when a cluster is not present' do
let(:project) { create(:project, :stubbed_repository) }
let(:environment) { create(:environment, project: project) }
subject { environment.prometheus_status }
it { is_expected.to be_nil }
end
end
describe '#additional_metrics' do describe '#additional_metrics' do
let(:project) { create(:prometheus_project) } let(:project) { create(:prometheus_project) }
let(:metric_params) { [] } let(:metric_params) { [] }
......
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