Skip to content
Snippets Groups Projects
Commit a807a8c7 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Fix obsolete production identifier

This commit replace the obsolete production identifier
by the new environment tier feature.
parent bbe3dfc3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -226,7 +226,7 @@ def includes_commit?(commit)
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)
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -251,10 +249,6 @@ def last_deployed_at
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
Loading
Loading
---
title: Fix inconsistent production environment definition on VSA
merge_request: 57557
author:
type: fixed
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -808,4 +808,30 @@
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
Loading
Loading
@@ -302,6 +302,8 @@
'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]
Loading
Loading
@@ -315,6 +317,12 @@
'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]
Loading
Loading
@@ -444,31 +452,6 @@
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 }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment