# Feature flags process
> 原文:[https://docs.gitlab.com/ee/development/feature_flags/process.html](https://docs.gitlab.com/ee/development/feature_flags/process.html)
* [Feature flags for user applications](#feature-flags-for-user-applications)
* [Feature flags in GitLab development](#feature-flags-in-gitlab-development)
* [When to use feature flags](#when-to-use-feature-flags)
* [Including a feature behind feature flag in the final release](#including-a-feature-behind-feature-flag-in-the-final-release)
* [The cost of feature flags](#the-cost-of-feature-flags)
# Feature flags process[](#feature-flags-process "Permalink")
## Feature flags for user applications[](#feature-flags-for-user-applications "Permalink")
本文档仅涵盖在 GitLab 本身的开发中使用的功能标志. 可以在[功能标志功能文档中](../../user/project/operations/feature_flags.html)找到已部署的用户应用程序中的[功能标志](../../user/project/operations/feature_flags.html) .
## Feature flags in GitLab development[](#feature-flags-in-gitlab-development "Permalink")
在决定是否应利用功能标志时,应考虑以下重点:
* 默认情况下,功能标志应为**off** .
* 功能标记应在代码库中保留尽可能短的时间,以减少对功能标记记帐的需求.
* 使用功能标记的人员负责与负责的利益相关者清楚地传达功能标记后面的功能状态. 应该使用功能标记名称以及明显需要功能标记的默认状态打开或关闭更新问题描述.
* 合并进行更改以隐藏在功能标记后的请求,或删除现有功能标记(因为认为功能稳定),必须分配〜" feature flag"标签.
* 当功能开发将分散在多个合并请求中时,可以使用以下工作流程:
1. 在第一个合并请求中引入默认情况下**关闭**的功能标志.
2. 通过一个或多个合并请求提交增量更改,以确保只有在功能标记为**on 时**才能访问添加的任何新代码. 您可以在开发过程中在本地 GDK 上保持启用功能标志.
3. When the feature is ready to be tested, enable the feature flag for a specific project and ensure that there are no issues with the implementation.
4. 准备宣布该功能时,创建一个合并请求,以添加有关该功能的[文档](../documentation/feature_flags.html) ,包括[有关功能标志本身的文档](../documentation/feature_flags.html)以及一个 changelog 条目. 在同一合并请求中,要么将功能标记翻转为**默认状态,**要么将其完全删除以启用新行为.
可能会想起功能标记将功能的发布延迟至少一个月(=一个发布). 不是这种情况. 功能标记不必在特定时间段内停留(例如,至少一个版本),而是应该一直停留到功能被认为稳定为止. 稳定意味着它可以在 GitLab.com 上运行,而不会引起任何问题,例如中断.
另请阅读[功能标记](development.html)的[开发指南](development.html) .
### When to use feature flags[](#when-to-use-feature-flags "Permalink")
从 GitLab 11.4 开始,开发人员必须使用功能标志进行不重要的更改. 此类更改包括:
* 新功能(例如,新的合并请求小部件,史诗等).
* 复杂的性能改进,可能需要在生产中进行其他测试,例如重写复杂的查询.
* 对用户界面的侵入性更改,例如新的导航栏或侧边栏的删除.
* 添加了对从第三方服务导入项目的支持.
在所有情况下,进行更改的人员都可以最好地决定是否需要功能标记. 例如,更改按钮的颜色不需要功能标记,而更改导航栏则绝对需要一个功能标记. 如果您不确定是否需要功能部件标志,只需在合并请求中询问一下,那些查看更改的人员可能会为您提供答案.
对 UI 元素使用功能标记时,请确保对基础后端代码*也*使用功能标记(如果有). 这样可以确保在启用该功能之前绝对无法使用该功能.
### Including a feature behind feature flag in the final release[](#including-a-feature-behind-feature-flag-in-the-final-release "Permalink")
为了构建最终版本并向自我管理的用户展示功能,功能标志至少应默认为**on** . 如果认为该功能稳定并且确信删除该功能标志是安全的,请考虑完全删除该功能标志. *强烈*建议在做出此决定之前**,至少在一天的** [**生产中** **全局**启用](./controls.html#enabling-a-feature-for-gitlabcom)功能标志. 在此期间,有时会发现意外的错误.
从首次审查合并请求到将更改部署到 GitLab.com 的过程中,启用默认情况下禁用的功能的过程可能需要 5 到 6 天. 但是,建议将此活动留出 10 到 14 天的时间,以解决无法预料的问题.
功能标记必须[根据其状态(启用/禁用)进行记录](../documentation/feature_flags.html) ,并且当状态更改时, **必须相应**地更新文档.
**注意:**请注意,合并功能标记的更改后不久,此类操作可使功能在 GitLab.com 上可用.
更改默认状态或删除功能标志必须在每月的 22 号之前*(至少在* 3-4 个工作日之前)进行,以便将更改包含在最终的自我管理版本中.
除此之外,功能标志后面的功能应:
* 在所有 GitLab.com 环境中运行足够长的时间. 该时间段取决于功能标志后面的功能,但是通常经验法则是 2-4 个工作日应该足以收集足够的反馈.
* 在上述时间段内,该功能应向 GitLab.com 计划内的所有用户公开. 将功能暴露给较小的百分比或仅将一组用户公开可能不会暴露出足够多的信息来帮助您确定功能稳定性.
尽管很少使用,但即使使用了功能标志,发行经理也可能决定拒绝选择或还原稳定分支中的更改. 如果更改被认为是有问题的,过于侵入性的,或者只是没有足够的时间来正确衡量更改在 GitLab.com 上的行为,则可能有必要.
### The cost of feature flags[](#the-cost-of-feature-flags "Permalink")
阅读以上内容时,可能会想起此过程会增加很多工作. 幸运的是,事实并非如此,我们将说明原因. 在此示例中,我们将工作成本指定为一个数字,范围从 0 到无穷大. 数量越大,工作越昂贵. 成本并*没有*转化时间,这只是相对于另一个测量一个变化的复杂性的一种方式.
假设我们正在构建一个新功能,并确定此功能的成本为 10.我们还确定,在不同位置添加功能标志检查的成本为 1.如果不使用功能标志,并且我们的功能按预期工作,我们的总费用为 10.这是最好的情况. 最佳情况下的优化肯定会导致麻烦,而最坏情况下的优化几乎总是更好.
为了说明这一点,假设我们的功能导致停机,并且没有立即解决的方法. 这意味着我们必须采取以下步骤来解决停机问题:
1. 还原发行版.
2. 根据所做的更改,执行可能需要的所有清理.
3. 恢复提交,确保" master"分支保持稳定. 如果解决问题可能需要几天甚至几周的时间,那么这尤其必要.
4. 选择还原提交到适当的稳定分支中,以确保在问题解决之前我们不会阻止任何将来的发行.
如历史所示,这些步骤耗时,复杂,通常涉及许多开发人员,而且最糟糕的是:在解决问题之前,我们的用户使用 GitLab.com 的体验将很糟糕.
现在,我们假设所有这些的关联成本为 10.这意味着在最坏的情况下(我们应该对其进行优化),我们的总成本现在为 20.
如果我们使用了功能标记,情况将会大不相同. 我们不需要还原版本,并且由于默认情况下功能标记是禁用的,因此我们不需要还原并选择任何 Git 提交. 实际上,我们要做的就是禁用该功能,在最坏的情况下,执行清理. 假设这是 2 的成本.在这种情况下,我们的最佳案例成本是 11:构建功能部件的成本为 10:添加功能标志的成本为 1\. 现在最坏的情况是 13:
* 10 构建功能.
* 1 添加功能标志.
* 2 禁用并清理.
在这里,我们可以看到,在最佳情况下,与不使用功能标记相比,所需的工作仅多一点. 同时,还原变更的过程已大大便宜了.
In other words, feature flags do not slow down the development process. Instead, they speed up the process as managing incidents now becomes *much* easier. Once continuous deployments are easier to perform, the time to iterate on a feature is reduced even further, as you no longer need to wait weeks before your changes are available on GitLab.com.
- GitLab Docs
- Installation
- Requirements
- GitLab cloud native Helm Chart
- Install GitLab with Docker
- Installation from source
- Install GitLab on Microsoft Azure
- Installing GitLab on Google Cloud Platform
- Installing GitLab on Amazon Web Services (AWS)
- Analytics
- Code Review Analytics
- Productivity Analytics
- Value Stream Analytics
- Kubernetes clusters
- Adding and removing Kubernetes clusters
- Adding EKS clusters
- Adding GKE clusters
- Group-level Kubernetes clusters
- Instance-level Kubernetes clusters
- Canary Deployments
- Cluster Environments
- Deploy Boards
- GitLab Managed Apps
- Crossplane configuration
- Cluster management project (alpha)
- Kubernetes Logs
- Runbooks
- Serverless
- Deploying AWS Lambda function using GitLab CI/CD
- Securing your deployed applications
- Groups
- Contribution Analytics
- Custom group-level project templates
- Epics
- Manage epics
- Group Import/Export
- Insights
- Issues Analytics
- Iterations
- Public access
- SAML SSO for GitLab.com groups
- SCIM provisioning using SAML SSO for GitLab.com groups
- Subgroups
- Roadmap
- Projects
- GitLab Secure
- Security Configuration
- Container Scanning
- Dependency Scanning
- Dependency List
- Static Application Security Testing (SAST)
- Secret Detection
- Dynamic Application Security Testing (DAST)
- GitLab Security Dashboard
- Offline environments
- Standalone Vulnerability pages
- Security scanner integration
- Badges
- Bulk editing issues and merge requests at the project level
- Code Owners
- Compliance
- License Compliance
- Compliance Dashboard
- Create a project
- Description templates
- Deploy Keys
- Deploy Tokens
- File finder
- Project integrations
- Integrations
- Atlassian Bamboo CI Service
- Bugzilla Service
- Custom Issue Tracker service
- Discord Notifications service
- Enabling emails on push
- GitHub project integration
- Hangouts Chat service
- Atlassian HipChat
- Irker IRC Gateway
- GitLab Jira integration
- Mattermost Notifications Service
- Mattermost slash commands
- Microsoft Teams service
- Mock CI Service
- Prometheus integration
- Redmine Service
- Slack Notifications Service
- Slack slash commands
- GitLab Slack application
- Webhooks
- YouTrack Service
- Insights
- Issues
- Crosslinking Issues
- Design Management
- Confidential issues
- Due dates
- Issue Boards
- Issue Data and Actions
- Labels
- Managing issues
- Milestones
- Multiple Assignees for Issues
- Related issues
- Service Desk
- Sorting and ordering issue lists
- Issue weight
- Associate a Zoom meeting with an issue
- Merge requests
- Allow collaboration on merge requests across forks
- Merge Request Approvals
- Browser Performance Testing
- How to create a merge request
- Cherry-pick changes
- Code Quality
- Load Performance Testing
- Merge Request dependencies
- Fast-forward merge requests
- Merge when pipeline succeeds
- Merge request conflict resolution
- Reverting changes
- Reviewing and managing merge requests
- Squash and merge
- Merge requests versions
- Draft merge requests
- Members of a project
- Migrating projects to a GitLab instance
- Import your project from Bitbucket Cloud to GitLab
- Import your project from Bitbucket Server to GitLab
- Migrating from ClearCase
- Migrating from CVS
- Import your project from FogBugz to GitLab
- Gemnasium
- Import your project from GitHub to GitLab
- Project importing from GitLab.com to your private GitLab instance
- Import your project from Gitea to GitLab
- Import your Jira project issues to GitLab
- Migrating from Perforce Helix
- Import Phabricator tasks into a GitLab project
- Import multiple repositories by uploading a manifest file
- Import project from repo by URL
- Migrating from SVN to GitLab
- Migrating from TFVC to Git
- Push Options
- Releases
- Repository
- Branches
- Git Attributes
- File Locking
- Git file blame
- Git file history
- Repository mirroring
- Protected branches
- Protected tags
- Push Rules
- Reduce repository size
- Signing commits with GPG
- Syntax Highlighting
- GitLab Web Editor
- Web IDE
- Requirements Management
- Project settings
- Project import/export
- Project access tokens (Alpha)
- Share Projects with other Groups
- Snippets
- Static Site Editor
- Wiki
- Project operations
- Monitor metrics for your CI/CD environment
- Set up alerts for Prometheus metrics
- Embedding metric charts within GitLab-flavored Markdown
- Embedding Grafana charts
- Using the Metrics Dashboard
- Dashboard YAML properties
- Metrics dashboard settings
- Panel types for dashboards
- Using Variables
- Templating variables for metrics dashboards
- Prometheus Metrics library
- Monitoring AWS Resources
- Monitoring HAProxy
- Monitoring Kubernetes
- Monitoring NGINX
- Monitoring NGINX Ingress Controller
- Monitoring NGINX Ingress Controller with VTS metrics
- Alert Management
- Error Tracking
- Tracing
- Incident Management
- GitLab Status Page
- Feature Flags
- GitLab CI/CD
- GitLab CI/CD pipeline configuration reference
- GitLab CI/CD include examples
- Introduction to CI/CD with GitLab
- Getting started with GitLab CI/CD
- How to enable or disable GitLab CI/CD
- Using SSH keys with GitLab CI/CD
- Migrating from CircleCI
- Migrating from Jenkins
- Auto DevOps
- Getting started with Auto DevOps
- Requirements for Auto DevOps
- Customizing Auto DevOps
- Stages of Auto DevOps
- Upgrading PostgreSQL for Auto DevOps
- Cache dependencies in GitLab CI/CD
- GitLab ChatOps
- Cloud deployment
- Docker integration
- Building Docker images with GitLab CI/CD
- Using Docker images
- Building images with kaniko and GitLab CI/CD
- GitLab CI/CD environment variables
- Predefined environment variables reference
- Where variables can be used
- Deprecated GitLab CI/CD variables
- Environments and deployments
- Protected Environments
- GitLab CI/CD Examples
- Test a Clojure application with GitLab CI/CD
- Using Dpl as deployment tool
- Testing a Phoenix application with GitLab CI/CD
- End-to-end testing with GitLab CI/CD and WebdriverIO
- DevOps and Game Dev with GitLab CI/CD
- Deploy a Spring Boot application to Cloud Foundry with GitLab CI/CD
- How to deploy Maven projects to Artifactory with GitLab CI/CD
- Testing PHP projects
- Running Composer and NPM scripts with deployment via SCP in GitLab CI/CD
- Test and deploy Laravel applications with GitLab CI/CD and Envoy
- Test and deploy a Python application with GitLab CI/CD
- Test and deploy a Ruby application with GitLab CI/CD
- Test and deploy a Scala application to Heroku
- GitLab CI/CD for external repositories
- Using GitLab CI/CD with a Bitbucket Cloud repository
- Using GitLab CI/CD with a GitHub repository
- GitLab Pages
- GitLab Pages
- GitLab Pages domain names, URLs, and baseurls
- Create a GitLab Pages website from scratch
- Custom domains and SSL/TLS Certificates
- GitLab Pages integration with Let's Encrypt
- GitLab Pages Access Control
- Exploring GitLab Pages
- Incremental Rollouts with GitLab CI/CD
- Interactive Web Terminals
- Optimizing GitLab for large repositories
- Metrics Reports
- CI/CD pipelines
- Pipeline Architecture
- Directed Acyclic Graph
- Multi-project pipelines
- Parent-child pipelines
- Pipelines for Merge Requests
- Pipelines for Merged Results
- Merge Trains
- Job artifacts
- Pipeline schedules
- Pipeline settings
- Triggering pipelines through the API
- Review Apps
- Configuring GitLab Runners
- GitLab CI services examples
- Using MySQL
- Using PostgreSQL
- Using Redis
- Troubleshooting CI/CD
- GitLab Package Registry
- GitLab Container Registry
- Dependency Proxy
- GitLab Composer Repository
- GitLab Conan Repository
- GitLab Maven Repository
- GitLab NPM Registry
- GitLab NuGet Repository
- GitLab PyPi Repository
- API Docs
- API resources
- .gitignore API
- GitLab CI YMLs API
- Group and project access requests API
- Appearance API
- Applications API
- Audit Events API
- Avatar API
- Award Emoji API
- Project badges API
- Group badges API
- Branches API
- Broadcast Messages API
- Project clusters API
- Group clusters API
- Instance clusters API
- Commits API
- Container Registry API
- Custom Attributes API
- Dashboard annotations API
- Dependencies API
- Deploy Keys API
- Deployments API
- Discussions API
- Dockerfiles API
- Environments API
- Epics API
- Events
- Feature Flags API
- Feature flag user lists API
- Freeze Periods API
- Geo Nodes API
- Group Activity Analytics API
- Groups API
- Import API
- Issue Boards API
- Group Issue Boards API
- Issues API
- Epic Issues API
- Issues Statistics API
- Jobs API
- Keys API
- Labels API
- Group Labels API
- License
- Licenses API
- Issue links API
- Epic Links API
- Managed Licenses API
- Markdown API
- Group and project members API
- Merge request approvals API
- Merge requests API
- Project milestones API
- Group milestones API
- Namespaces API
- Notes API
- Notification settings API
- Packages API
- Pages domains API
- Pipeline schedules API
- Pipeline triggers API
- Pipelines API
- Project Aliases API
- Project import/export API
- Project repository storage moves API
- Project statistics API
- Project templates API
- Projects API
- Protected branches API
- Protected tags API
- Releases API
- Release links API
- Repositories API
- Repository files API
- Repository submodules API
- Resource label events API
- Resource milestone events API
- Resource weight events API
- Runners API
- SCIM API
- Search API
- Services API
- Application settings API
- Sidekiq Metrics API
- Snippets API
- Project snippets
- Application statistics API
- Suggest Changes API
- System hooks API
- Tags API
- Todos API
- Users API
- Project-level Variables API
- Group-level Variables API
- Version API
- Vulnerabilities API
- Vulnerability Findings API
- Wikis API
- GraphQL API
- Getting started with GitLab GraphQL API
- GraphQL API Resources
- API V3 to API V4
- Validate the .gitlab-ci.yml (API)
- User Docs
- Abuse reports
- User account
- Active sessions
- Deleting a User account
- Permissions
- Personal access tokens
- Profile preferences
- Threads
- GitLab and SSH keys
- GitLab integrations
- Git
- GitLab.com settings
- Infrastructure as code with Terraform and GitLab
- GitLab keyboard shortcuts
- GitLab Markdown
- AsciiDoc
- GitLab Notification Emails
- GitLab Quick Actions
- Autocomplete characters
- Reserved project and group names
- Search through GitLab
- Advanced Global Search
- Advanced Syntax Search
- Time Tracking
- GitLab To-Do List
- Administrator Docs
- Reference architectures
- Reference architecture: up to 1,000 users
- Reference architecture: up to 2,000 users
- Reference architecture: up to 3,000 users
- Reference architecture: up to 5,000 users
- Reference architecture: up to 10,000 users
- Reference architecture: up to 25,000 users
- Reference architecture: up to 50,000 users
- Troubleshooting a reference architecture set up
- Working with the bundled Consul service
- Configuring PostgreSQL for scaling
- Configuring GitLab application (Rails)
- Load Balancer for multi-node GitLab
- Configuring a Monitoring node for Scaling and High Availability
- NFS
- Working with the bundled PgBouncer service
- Configuring Redis for scaling
- Configuring Sidekiq
- Admin Area settings
- Continuous Integration and Deployment Admin settings
- Custom instance-level project templates
- Diff limits administration
- Enable and disable GitLab features deployed behind feature flags
- Geo nodes Admin Area
- GitLab Pages administration
- Health Check
- Job logs
- Labels administration
- Log system
- PlantUML & GitLab
- Repository checks
- Repository storage paths
- Repository storage types
- Account and limit settings
- Service templates
- System hooks
- Changing your time zone
- Uploads administration
- Abuse reports
- Activating and deactivating users
- Audit Events
- Blocking and unblocking users
- Broadcast Messages
- Elasticsearch integration
- Gitaly
- Gitaly Cluster
- Gitaly reference
- Monitoring GitLab
- Monitoring GitLab with Prometheus
- Performance Bar
- Usage statistics
- Object Storage
- Performing Operations in GitLab
- Cleaning up stale Redis sessions
- Fast lookup of authorized SSH keys in the database
- Filesystem Performance Benchmarking
- Moving repositories managed by GitLab
- Run multiple Sidekiq processes
- Sidekiq MemoryKiller
- Switching to Puma
- Understanding Unicorn and unicorn-worker-killer
- User lookup via OpenSSH's AuthorizedPrincipalsCommand
- GitLab Package Registry administration
- GitLab Container Registry administration
- Replication (Geo)
- Geo database replication
- Geo with external PostgreSQL instances
- Geo configuration
- Using a Geo Server
- Updating the Geo nodes
- Geo with Object storage
- Docker Registry for a secondary node
- Geo for multiple nodes
- Geo security review (Q&A)
- Location-aware Git remote URL with AWS Route53
- Tuning Geo
- Removing secondary Geo nodes
- Geo data types support
- Geo Frequently Asked Questions
- Geo Troubleshooting
- Geo validation tests
- Disaster Recovery (Geo)
- Disaster recovery for planned failover
- Bring a demoted primary node back online
- Automatic background verification
- Rake tasks
- Back up and restore GitLab
- Clean up
- Namespaces
- Maintenance Rake tasks
- Geo Rake Tasks
- GitHub import
- Import bare repositories
- Integrity check Rake task
- LDAP Rake tasks
- Listing repository directories
- Praefect Rake tasks
- Project import/export administration
- Repository storage Rake tasks
- Generate sample Prometheus data
- Uploads migrate Rake tasks
- Uploads sanitize Rake tasks
- User management
- Webhooks administration
- X.509 signatures
- Server hooks
- Static objects external storage
- Updating GitLab
- GitLab release and maintenance policy
- Security
- Password Storage
- Custom password length limits
- Restrict allowed SSH key technologies and minimum length
- Rate limits
- Webhooks and insecure internal web services
- Information exclusivity
- How to reset your root password
- How to unlock a locked user from the command line
- User File Uploads
- How we manage the TLS protocol CRIME vulnerability
- User email confirmation at sign-up
- Security of running jobs
- Proxying assets
- CI/CD Environment Variables
- Contributor and Development Docs
- Contribute to GitLab
- Community members & roles
- Implement design & UI elements
- Issues workflow
- Merge requests workflow
- Code Review Guidelines
- Style guides
- GitLab Architecture Overview
- CI/CD development documentation
- Database guides
- Database Review Guidelines
- Database Review Guidelines
- Migration Style Guide
- What requires downtime?
- Understanding EXPLAIN plans
- Rake tasks for developers
- Mass inserting Rails models
- GitLab Documentation guidelines
- Documentation Style Guide
- Documentation structure and template
- Documentation process
- Documentation site architecture
- Global navigation
- GitLab Docs monthly release process
- Telemetry Guide
- Usage Ping Guide
- Snowplow Guide
- Experiment Guide
- Feature flags in development of GitLab
- Feature flags process
- Developing with feature flags
- Feature flag controls
- Document features deployed behind feature flags
- Frontend Development Guidelines
- Accessibility & Readability
- Ajax
- Architecture
- Axios
- Design Patterns
- Frontend Development Process
- DropLab
- Emojis
- Filter
- Frontend FAQ
- GraphQL
- Icons and SVG Illustrations
- InputSetter
- Performance
- Principles
- Security
- Tooling
- Vuex
- Vue
- Geo (development)
- Geo self-service framework (alpha)
- Gitaly developers guide
- GitLab development style guides
- API style guide
- Go standards and style guidelines
- GraphQL API style guide
- Guidelines for shell commands in the GitLab codebase
- HTML style guide
- JavaScript style guide
- Migration Style Guide
- Newlines style guide
- Python Development Guidelines
- SCSS style guide
- Shell scripting standards and style guidelines
- Sidekiq debugging
- Sidekiq Style Guide
- SQL Query Guidelines
- Vue.js style guide
- Instrumenting Ruby code
- Testing standards and style guidelines
- Flaky tests
- Frontend testing standards and style guidelines
- GitLab tests in the Continuous Integration (CI) context
- Review Apps
- Smoke Tests
- Testing best practices
- Testing levels
- Testing Rails migrations at GitLab
- Testing Rake tasks
- End-to-end Testing
- Beginner's guide to writing end-to-end tests
- End-to-end testing Best Practices
- Dynamic Element Validation
- Flows in GitLab QA
- Page objects in GitLab QA
- Resource class in GitLab QA
- Style guide for writing end-to-end tests
- Testing with feature flags
- Translate GitLab to your language
- Internationalization for GitLab
- Translating GitLab
- Proofread Translations
- Merging translations from CrowdIn
- Value Stream Analytics development guide
- GitLab subscription
- Activate GitLab EE with a license