Feature Flag
know more from here: https://www.youtube.com/watch?v=WMRjj06R6jg&list=UUkQX1tChV7Z7l1LFF4L9j_g
Feature flag: a way if exposing features to a sub-sent of your user base.
Release early, release often
Continuous integration is all about the entire team committing to master daily.
Small changes, shipped to production quickly, rather than living on feature branches, increase the velocity of new features and bug fixes reaching your customers.
But with most changes merged directly to master, how can you build new features with the confidence that shipping them won't have any impact on your customers, and only make it available once you're confident it's ready for prime time?
In a feature branch world, your new feature would be in the works for a while, changes are continuously merged in from master, making sure not to break anything.
But you won't know until it's finally merged and deployed to production whether your changes work.
How can you continuously ship new features to production with the confidence of not impacting your customers?
The answer is: feature flags.
A feature flag is a branching point that your code can utilize to determine whether or not a feature should be made available to one or more customers.
The original approach was made popular by the fine folks at Flickr. They needed a means to disable features when something is broken in production, to reduce the load on the database or on other parts of the system.
But feature flags can be used for much more than just disabling features in production.
Enable a feature only for a specific number of users, or even just for yourself to try it out in isolation.
Trial a new feature for a sample set of customers to compare how they're using it compared to the previous version of the feature.
This allows you to run experiments with actual users before you put it live. You can collect feedback and iterate based on real production usage.
Enable it for your team to try out and give feedback on. At GitHub, this is known as staff mode. Next time you see a hubber in the wild, peek at their version of GitHub, I'm sure you'll notice some subtle differences.
Enable a feature for a specific set of users, or just your team for them to try it out before it's rolled out for everyone.
When a feature finally is rolled out for everyone, you can decide case by case on whether you want to leave a global feature flag so you can disable a new feature in the future.
The three use cases can even be put together. First you roll out a new feature for yourself, so you can try it out in production. Next you enable it for your team, and then you enable if for a subset of users. Finally, you make it available for everyone.
How do I implement feature flags?
At the core, feature flags are simple configuration settings with Boolean values.
if Travis::Application.config.features.repository_settings?
# code to handle settings
end
This example uses a Rails built-in means to manage application configuration, storing flags as simple true/false key value pairs.
For a Rails project, you can store this configuration in an initializer file.
# config/initializers/features.rb
Travis::Application.config.features = {
repository_settings: true
}
For every new feature, you can add the setting here, leaving all of them in one place to find, disable and enable them easily. All it takes is one change and a redeploy to enable or disable a feature.
This mechanism allows you to only fully disable or enable something, and only with redeploying the entire app, which can sometimes be burdensome. It also lacks the finesse to enable features for specific users or groups of users.
Flagging features at runtime
A more dynamic approach is to store the feature configuration in either an ephemeral or permanent storage, like Redis or your database, respectively.
Assuming your code continuously checks feature flags at runtime, all it takes is changing a value in the central configuration service and it can have an immediate affect on the running application without requiring a restart.
James Golick's rollout is a popular library to implement dynamic feature flags for Ruby applications. It allows you to enable features for specific users, groups of users, a percentage of users, or disable and enable them entirely. Hey, that library covers all of our bases!
Not coincidentally, it's the one we're using for Travis CI.
Rather than store the data in a configuration file, you can store them in Redis, or any supported key value store. Instead of asking the application's configuration, you ask rollout whether a feature is enabled.
if rollout.active?(:repository_settings, current_user)
# settings logic goes here
end
Enabling a feature for a user is just as simple.
rollout.activate_user(:repository_settings, User.find_by_login('roidrage'))
You can segment users into groups as well, based on the flags a specific users. Our friends at Librato use a mechanism similar to this for segmenting out users they'd like to test new features before they're available for everyone, the beta list if you will.
rollout.define_group(:beta_testers) do |user|
user.beta?
end
Document feature flags
When feature flags are collected using a centralized store like Redis, it gets harder to track which flags are available, what their defaults should be, and which features they affect.
Make sure to keep simple documentation around where you collect feature flags to make sure the right ones are changed at the right time.
Feature flags at Travis CI
We're using rollout for our feature flags, but we've added a few more things that we need. Some features on Travis CI are only made available for certain repositories or certain accounts and all of their respective repositories.
Most of our feature flags are built for production runtime though. We have means to enable build scheduling, for instance during a maintenance, without taking down the entire process. That way we can still process actively running builds without scheduling new ones.
We've used feature flips to migrate to different implementations of something too. Originally, our user synchronization went through RabbitMQ and was handled by the same process that handles scheduling builds.
As we switched over to a process based on Sidekiq, we enabled our own users first to make sure the process works, before we finally enabled it for everyone. We eventually moved the feature flip, as the code that originally handled this part was deleted as well.
We're also using them to enable custom subscription plans for some of our customers.
Ship with confidence
Feature flags are very handy to roll out new features gradually, but they also give you higher control over your system running in production as well.
New features, even in raw shape, can be put to use and test in the production environment as soon as something is ready for trying out, and without impacting users unless you choose to.
On top of that, they give you a means to disable certain features during a production incident.
Is your project using feature flags or a similar means? Feel free to share your experiences in the comments.
Feature Flag的更多相关文章
- 给你的 ASP.NET Core 程序插上 Feature Flag 的翅膀
前言 我们知道,目前大多数应用程序在正式发布到生产环境之前都会经历多个不同的测试环境,通过让应用程序在多个不同的环境中运行来及时发现并解决问题,避免在线上发生不必要的损失.这是对于整个软件的发布流程来 ...
- Sentry 开发者贡献指南 - Feature Flag
功能 flag 在 Sentry 的代码库中声明. 对于自托管用户,这些标志然后通过 sentry.conf.py 进行配置. 对于 Sentry 的 SaaS 部署,Flagr 用于在生产中配置标志 ...
- 基于Feature Flag的下一代开发模式
渐进式发布(Progressive Delivery)被认为是持续发布(Continous Delivery)的下一代形态,其专注于增强发布过程控制与降低发布风险,最终提高整体收益.国际科技巨头比如A ...
- 微软Azure配置中心 App Configuration (二):Feature Flag 功能开关特性
写在前面 Web服务开发过程中我们经常有这样的需求: 某些功能我必须我修改了配置才启用,比如新用户注册送券等: 某个功能需到特定的时间才启用,过后就失效,比如春节活动等: 某些功能,我想先对10%的用 ...
- 【亲述】Uber容错设计与多机房容灾方案 - 高可用架构系列
此文是根据赵磊在[QCON高可用架构群]中的分享内容整理而成.转载请事先联系赵磊及相关编辑. 赵磊,Uber高级工程师,08年上海交通大学毕业,曾就职于微软,后加入Facebook主要负责Messen ...
- 使用Trello实现敏捷项目管理
使用Trello实现敏捷项目管理 作者 侯伯薇 发布于 五月 24, 2012 | 1 讨论 新浪微博腾讯微 ...
- 八卦某 G 的前端开发方式及流程
他山之石,可以攻玉. 话说本人从毕业到现在一直在某 B 公司工作,前些年折腾过不少开发方式和工具,但总觉得或许有更好的方案,所以很好奇其它公司内部是如何工作的,我曾经浏览过某 Y 公司内部无所不包 ...
- Package org.xml.sax Description
This package provides the core SAX APIs. Some SAX1 APIs are deprecated to encourage integration(集成:综 ...
- Linux 内核使用的 GNU C 扩展
gcc核心扩展linuxforum(转)=========================== Linux 内核使用的 GNU C 扩展 =========================== GNC ...
随机推荐
- JS函数式编程【译】2.1 函数式编程语言
- Fedora 19 vim c语言开发环境
1. Fedora 19 居然没有自带 gcc 和 g++: sudo yum -y install gcc gcc-c++ 2. 安装 vim 和 cvim 插件: sudo yum -y vim ...
- MySQL中,把varchar类型转为date类型
如下表: 先使用str_to_date函数,将其varchar类型转为日期类型,然后从小到大排序 语法:select str_to_date(class_time,'%Y%m%d %H:%i:%s') ...
- 双机倒换(NewStartHA,SKYbility,hacmp,hp unix双机)
1.Suse linux (NewStartHA): # cli cli:~>service-migrate Select service to migrate: ...
- zedboard之ubuntu环境变量设置
在Ubuntu中有如下几个文件可以设置环境变量 1./etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. ...
- Android开发面试题(一)
1.String和StringBuffer有什么本质区别? 本质区别:String字符串不可变,每次修改字符串必须要重新赋值(生成新的对象)才能修改:StringBuffer字符串可变,可以直接对字符 ...
- eclipse安装pydev插件
打开Eclipse,找到Help菜单栏,进入Install New Software…选项. 点击work with:输入框的旁边点击Add…,Name可以随便输入,Location是http://p ...
- javascript中出现identifier starts immediately after numeric literal错误原因以及解决方法
javascript遇到参数是字符型和数字型组合的参数就会出现这种错误,例如alert(1);可以正確輸出alert(str);就會報錯alert("str");可以正確輸出.
- SharePoint 2010/SharePoint 2013 Custom Action: 基于Site Collection 滚动文字的通知.
应用场景: 有时候我们的站点需要在每个页面实现滚动文字的通知,怎么在不修改Master Page的情况下实现这个功能?我们可以使用Javascript 和 Custom Action 来实现. 创建一 ...
- mysql存储过程中字符串参数单引号
注意:存储过程中单引号 ,四个单引号 SET @sql = CONCAT('select user_id into ',m_user_id,' from go_user where mobile = ...