Commit b7467748 authored by Toon Claes's avatar Toon Claes

Treat environments matching `production/*` as Production

For Cycle Analytics, the environment `production` is treated as a
special case, and used to update the `first_deployed_to_production_at`
metric.

With the Review Apps changes, slash syntax is used to group related
environments in the list. This is mostly used for `review/<branch>`
environments, but it's possible for people to have multiple production
environments, and someone might then want to group them like
`production/eu`, `production/us`, or even just make it look prettier
with `production/www.example.com`. In any of these cases, the first
deploy to one of these `production/*` environments now is treated as a
Production deploy.
parent 8ab94120
...@@ -87,7 +87,7 @@ class Environment < ActiveRecord::Base ...@@ -87,7 +87,7 @@ class Environment < ActiveRecord::Base
end end
def update_merge_request_metrics? def update_merge_request_metrics?
self.name == "production" (environment_type || name) == "production"
end end
def first_deployment_for(commit) def first_deployment_for(commit)
......
---
title: Treat environments matching `production/*` as Production
merge_request: 8500
author:
...@@ -50,7 +50,7 @@ exception of the staging and production stages, where only data deployed to ...@@ -50,7 +50,7 @@ exception of the staging and production stages, where only data deployed to
production are measured. production are measured.
Specifically, if your CI is not set up and you have not defined a `production` Specifically, if your CI is not set up and you have not defined a `production`
[environment], then you will not have any data for those stages. or `production/*` [environment], then you will not have any data for those stages.
Below you can see in more detail what the various stages of Cycle Analytics mean. Below you can see in more detail what the various stages of Cycle Analytics mean.
...@@ -61,7 +61,7 @@ Below you can see in more detail what the various stages of Cycle Analytics mean ...@@ -61,7 +61,7 @@ Below you can see in more detail what the various stages of Cycle Analytics mean
| Code | Measures the median time between pushing a first commit (previous stage) and creating a merge request (MR) related to that commit. The key to keep the process tracked is to include the [issue closing pattern] to the description of the merge request (for example, `Closes #xxx`, where `xxx` is the number of the issue related to this merge request). If the issue closing pattern is not present in the merge request description, the MR is not considered to the measurement time of the stage. | | Code | Measures the median time between pushing a first commit (previous stage) and creating a merge request (MR) related to that commit. The key to keep the process tracked is to include the [issue closing pattern] to the description of the merge request (for example, `Closes #xxx`, where `xxx` is the number of the issue related to this merge request). If the issue closing pattern is not present in the merge request description, the MR is not considered to the measurement time of the stage. |
| Test | Measures the median time to run the entire pipeline for that project. It's related to the time GitLab CI takes to run every job for the commits pushed to that merge request defined in the previous stage. It is basically the start->finish time for all pipelines. `master` is not excluded. It does not attempt to track time for any particular stages. | | Test | Measures the median time to run the entire pipeline for that project. It's related to the time GitLab CI takes to run every job for the commits pushed to that merge request defined in the previous stage. It is basically the start->finish time for all pipelines. `master` is not excluded. It does not attempt to track time for any particular stages. |
| Review | Measures the median time taken to review the merge request, between its creation and until it's merged. | | Review | Measures the median time taken to review the merge request, between its creation and until it's merged. |
| Staging | Measures the median time between merging the merge request until the very first deployment to production. It's tracked by the [environment] set to `production` (case-sensitive, `Production` won't work) in your GitLab CI configuration. If there isn't a `production` environment, this is not tracked. | | Staging | Measures the median time between merging the merge request until the very first deployment to production. It's tracked by the [environment] set to `production` or matching `production/*` (case-sensitive, `Production` won't work) in your GitLab CI configuration. If there isn't a production environment, this is not tracked. |
| Production| The sum of all time (medians) taken to run the entire process, from issue creation to deploying the code to production. | | Production| The sum of all time (medians) taken to run the entire process, from issue creation to deploying the code to production. |
--- ---
...@@ -79,10 +79,13 @@ Here's a little explanation of how this works behind the scenes: ...@@ -79,10 +79,13 @@ Here's a little explanation of how this works behind the scenes:
etc. etc.
To sum up, anything that doesn't follow the [GitLab flow] won't be tracked at all. To sum up, anything that doesn't follow the [GitLab flow] won't be tracked at all.
So, if a merge request doesn't close an issue or an issue is not labeled with a So, the Cycle Analytics dashboard won't present any data:
label present in the Issue Board or assigned a milestone or a project has no - For merge requests that do not close an issue.
`production` environment (for staging and production stages), the Cycle Analytics - For issues not labeled with a label present in the Issue Board.
dashboard won't present any data at all. - For issues not assigned a milestone.
- For staging and production stages, if the project has no `production` or `production/*`
environment.
## Example workflow ## Example workflow
......
...@@ -63,6 +63,23 @@ describe Environment, models: true do ...@@ -63,6 +63,23 @@ describe Environment, models: true do
end end
end end
describe '#update_merge_request_metrics?' do
{ 'production' => true,
'production/eu' => true,
'production/www.gitlab.com' => true,
'productioneu' => false,
'Production' => false,
'Production/eu' => false,
'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)
end
end
end
describe '#first_deployment_for' do describe '#first_deployment_for' do
let(:project) { create(:project) } let(:project) { create(:project) }
let!(:deployment) { create(:deployment, environment: environment, ref: commit.parent.id) } let!(:deployment) { create(:deployment, environment: environment, ref: commit.parent.id) }
......
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