Commit f1abb555 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'fix-obsolte-production-identifier' into 'master'

Fix inconsistent production environment definition on VSA

See merge request gitlab-org/gitlab!57557
parents 671b0149 a807a8c7
......@@ -226,7 +226,7 @@ class Deployment < ApplicationRecord
end
def update_merge_request_metrics!
return unless environment.update_merge_request_metrics? && success?
return unless environment.production? && success?
merge_requests = project.merge_requests
.joins(:metrics)
......
......@@ -11,8 +11,6 @@ class Environment < ApplicationRecord
self.reactive_cache_hard_limit = 10.megabytes
self.reactive_cache_work_type = :external_dependency
PRODUCTION_ENVIRONMENT_IDENTIFIERS = %w[prod production].freeze
belongs_to :project, required: true
use_fast_destroy :all_deployments
......@@ -251,10 +249,6 @@ class Environment < ApplicationRecord
last_deployment.try(:created_at)
end
def update_merge_request_metrics?
PRODUCTION_ENVIRONMENT_IDENTIFIERS.include?(folder_name.downcase)
end
def ref_path
"refs/#{Repository::REF_ENVIRONMENTS}/#{slug}"
end
......
---
title: Fix inconsistent production environment definition on VSA
merge_request: 57557
author:
type: fixed
......@@ -103,14 +103,8 @@ In short, the Value Stream Analytics dashboard tracks data related to [GitLab fl
## How the production environment is identified
Value Stream Analytics identifies production environments by looking for project [environments](../../ci/yaml/README.md#environment) with a name matching any of these patterns:
- `prod` or `prod/*`
- `production` or `production/*`
These patterns are not case-sensitive.
You can change the name of a project environment in your GitLab CI/CD configuration.
Value Stream Analytics identifies production environments based on
[the deployment tier of environments](../../ci/environments/index.md#deployment-tier-of-environments).
## Example workflow
......
......@@ -808,4 +808,30 @@ RSpec.describe Deployment do
end
end
end
describe '#update_merge_request_metrics!' do
let_it_be(:project) { create(:project, :repository) }
let(:environment) { build(:environment, environment_tier, project: project) }
let!(:deployment) { create(:deployment, :success, project: project, environment: environment) }
let!(:merge_request) { create(:merge_request, :simple, :merged_last_month, project: project) }
context 'with production environment' do
let(:environment_tier) { :production }
it 'updates merge request metrics for production-grade environment' do
expect { deployment.update_merge_request_metrics! }
.to change { merge_request.reload.metrics.first_deployed_to_production_at }
.from(nil).to(deployment.reload.finished_at)
end
end
context 'with staging environment' do
let(:environment_tier) { :staging }
it 'updates merge request metrics for production-grade environment' do
expect { deployment.update_merge_request_metrics! }
.not_to change { merge_request.reload.metrics.first_deployed_to_production_at }
end
end
end
end
......@@ -302,6 +302,8 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'testing' | described_class.tiers[:testing]
'testing-prd' | described_class.tiers[:testing]
'acceptance-testing' | described_class.tiers[:testing]
'production-test' | described_class.tiers[:testing]
'test-production' | described_class.tiers[:testing]
'QC' | described_class.tiers[:testing]
'gstg' | described_class.tiers[:staging]
'staging' | described_class.tiers[:staging]
......@@ -315,6 +317,12 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'gprd-cny' | described_class.tiers[:production]
'production' | described_class.tiers[:production]
'Production' | described_class.tiers[:production]
'PRODUCTION' | described_class.tiers[:production]
'Production/eu' | described_class.tiers[:production]
'production/eu' | described_class.tiers[:production]
'PRODUCTION/EU' | described_class.tiers[:production]
'productioneu' | described_class.tiers[:production]
'production/www.gitlab.com' | described_class.tiers[:production]
'prod' | described_class.tiers[:production]
'PROD' | described_class.tiers[:production]
'Live' | described_class.tiers[:production]
......@@ -444,31 +452,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end
end
describe '#update_merge_request_metrics?' do
{
'gprd' => false,
'prod' => true,
'prod-test' => false,
'PROD' => true,
'production' => true,
'production-test' => false,
'PRODUCTION' => true,
'production/eu' => true,
'PRODUCTION/EU' => true,
'production/www.gitlab.com' => true,
'productioneu' => false,
'Production' => true,
'Production/eu' => true,
'test-production' => false
}.each do |name, expected_value|
it "returns #{expected_value} for #{name}" do
env = create(:environment, name: name)
expect(env.update_merge_request_metrics?).to eq(expected_value), "Expected the name '#{name}' to result in #{expected_value}, but it didn't."
end
end
end
describe '#environment_type' do
subject { environment.environment_type }
......
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