Commit 10c819d3 authored by Kirstie Cook's avatar Kirstie Cook Committed by Mayra Cabrera

Expose prometheus state to monitor dashboard

Add tests for presence and absence of cluster and deployment platform
parent 72104c3b
......@@ -34,6 +34,7 @@ module EnvironmentsHelper
"project-path" => project_path(project),
"tags-path" => project_tags_path(project),
"has-metrics" => "#{environment.has_metrics?}",
"prometheus-status" => "#{environment.prometheus_status}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url
}
end
......
......@@ -188,6 +188,10 @@ class Environment < ApplicationRecord
prometheus_adapter.query(:environment, self) if has_metrics?
end
def prometheus_status
deployment_platform&.cluster&.application_prometheus&.status_name
end
def additional_metrics(*args)
return unless has_metrics?
......
---
title: Expose prometheus status to monitor dashboard
merge_request: 18289
author:
type: fixed
......@@ -32,6 +32,7 @@ describe EnvironmentsHelper do
'project-path' => project_path(project),
'tags-path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}",
'external-dashboard-url' => nil
)
end
......
......@@ -727,6 +727,51 @@ describe Environment, :use_clean_rails_memory_store_caching do
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
let(:project) { create(:prometheus_project) }
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