Commit eca96b50 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'change-tier-eeu-environment-alerts' into 'master'

[RUN AS-IF-FOSS] Fix the tier of environment alerts feature

See merge request gitlab-org/gitlab!41855
parents e3ed74b5 f7e24cbf
......@@ -71,8 +71,6 @@ class EnvironmentEntity < Grape::Entity
can?(current_user, :destroy_environment, environment)
end
expose :has_opened_alert?, if: -> (*) { can_read_alert_management_alert? }, expose_nil: false, as: :has_opened_alert
private
alias_method :environment, :object
......@@ -93,10 +91,6 @@ class EnvironmentEntity < Grape::Entity
can?(current_user, :read_pod_logs, environment.project)
end
def can_read_alert_management_alert?
can?(current_user, :read_alert_management_alert, environment.project)
end
def cluster_platform_kubernetes?
deployment_platform && deployment_platform.is_a?(Clusters::Platforms::Kubernetes)
end
......
---
title: Fix the tier of environment alerts feature
merge_request: 41855
author:
type: fixed
......@@ -134,6 +134,7 @@ class License < ApplicationRecord
prometheus_alerts
pseudonymizer
release_evidence_test_artifacts
environment_alerts
report_approver_rules
requirements
sast
......
......@@ -7,6 +7,7 @@ module EE
prepended do
expose :rollout_status, if: -> (*) { can_read_deploy_board? }, using: ::RolloutStatusEntity
expose :has_opened_alert?, if: -> (*) { can_read_alert_management_alert? }, expose_nil: false, as: :has_opened_alert
end
private
......@@ -14,5 +15,10 @@ module EE
def can_read_deploy_board?
can?(current_user, :read_deploy_board, environment.project)
end
def can_read_alert_management_alert?
can?(current_user, :read_alert_management_alert, environment.project) &&
environment.project.feature_available?(:environment_alerts)
end
end
end
......@@ -182,4 +182,53 @@ RSpec.describe 'Environments page', :js do
end
end
end
context 'when environment has an open alert' do
let!(:alert) do
create(:alert_management_alert, :triggered, :prometheus,
title: 'HTTP Error Rate', project: project,
environment: environment, prometheus_alert: prometheus_alert)
end
let!(:prometheus_alert) do
create(:prometheus_alert, project: project, environment: environment,
prometheus_metric: prometheus_metric)
end
let!(:prometheus_metric) do
create(:prometheus_metric, project: project, unit: '%')
end
before do
stub_licensed_features(environment_alerts: true)
end
it 'shows the open alert for the environment row' do
visit project_environments_path(project)
within(find('div[data-testid="alert"]')) do
expect(page).to have_content('Critical')
expect(page).to have_content('HTTP Error Rate exceeded 1.0%')
expect(page).to have_link('View Details', href: alert.present.details_url)
end
# and it's not shown when the alert is resolved.
alert.resolve!
visit project_environments_path(project)
expect(page).not_to have_css('div[data-testid="alert"]')
end
context 'when user does not have a license for the feature' do
before do
stub_licensed_features(environment_alerts: false)
end
it 'does not show the open alert for the environment row' do
visit project_environments_path(project)
expect(page).not_to have_css('div[data-testid="alert"]')
end
end
end
end
......@@ -16,6 +16,42 @@ RSpec.describe EnvironmentEntity do
describe '#as_json' do
subject { entity.as_json }
context 'with alert' do
let!(:environment) { create(:environment, project: project) }
let!(:prometheus_alert) { create(:prometheus_alert, project: project, environment: environment) }
let!(:alert) { create(:alert_management_alert, :triggered, :prometheus, project: project, environment: environment, prometheus_alert: prometheus_alert) }
before do
stub_licensed_features(environment_alerts: true)
end
it 'exposes active alert flag' do
project.add_maintainer(user)
expect(subject[:has_opened_alert]).to eq(true)
end
context 'when user does not have permission to read alert' do
it 'does not expose active alert flag' do
project.add_reporter(user)
expect(subject[:has_opened_alert]).to be_nil
end
end
context 'when license is insufficient' do
before do
stub_licensed_features(environment_alerts: false)
end
it 'does not expose active alert flag' do
project.add_maintainer(user)
expect(subject[:has_opened_alert]).to be_nil
end
end
end
context 'when deploy_boards are available' do
before do
stub_licensed_features(deploy_board: true)
......
......@@ -82,26 +82,6 @@ RSpec.describe EnvironmentEntity do
end
end
context 'with alert' do
let!(:environment) { create(:environment, project: project) }
let!(:prometheus_alert) { create(:prometheus_alert, project: project, environment: environment) }
let!(:alert) { create(:alert_management_alert, :triggered, :prometheus, project: project, environment: environment, prometheus_alert: prometheus_alert) }
it 'exposes active alert flag' do
project.add_maintainer(user)
expect(subject[:has_opened_alert]).to eq(true)
end
context 'when user does not have permission to read alert' do
it 'does not expose active alert flag' do
project.add_reporter(user)
expect(subject[:has_opened_alert]).to be_nil
end
end
end
context 'pod_logs' do
context 'with reporter access' do
before do
......
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