Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Feature Toggles! - Ruby

Feature Toggles! - Ruby

Feature toggles são uma técnica muito versátil para ajudar o trabalho de disponibilizar novas funcionalidades em produção sem quebrar a experiência de clientes e fazer entregas graduais, mas acabamos aprendendo sobre toggles de uma forma superficial no dia a dia.

Vamos ver um pouco do passado e presente do uso de features toggles, a sua facilidade de uso graças a gem flipper e considerações a serem feitas sobre como e quando usar toggles na sua aplicação

5a90a67fa1a92e6a4b605cfd8da5e375?s=128

Lucas Mazza

August 18, 2018
Tweet

Transcript

  1. Feature toggles

  2. @lucasmazza https://afterhours.io

  3. https://magnetis.workable.com

  4. Feature Toggles 101

  5. https://martinfowler.com/bliki/FeatureToggle.html

  6. None
  7. None
  8. None
  9. http://code.flickr.net/2009/12/02/flipping-out/ “Flickr is somewhat unique in that it uses a

    code repository with no branches; everything is checked into head, and head is pushed to production several times a day. ”
  10. “Flags allow us to restrict features to certain environments, while

    still using the same code base on all servers.” http://code.flickr.net/2009/12/02/flipping-out/
  11. “How do you use Continuous Integration to keep everyone working

    on the mainline without revealing a half- implemented feature on your releases? ” https://martinfowler.com/bliki/FeatureToggle.html
  12. Trunk based development + Mudanças demoradas = FEATURE TOGGLEs

  13. None
  14. “Feature Toggles are a powerful technique, allowing teams to modify

    system behavior without changing code.” https://martinfowler.com/articles/feature-toggles.html
  15. https://martinfowler.com/articles/feature-toggles.html

  16. release toggles

  17. ↗ ↘ ✅ ➡ ➡

  18. ops toggles

  19. ↗ ↘ ☁ ➡ ➡

  20. http://confreaks.tv/videos/rubyconf2014-easy-rewrites-with-ruby-and-science

  21. permission toggles

  22. None
  23. experiment toggles

  24. https://martinfowler.com/articles/feature-toggles.html

  25. None
  26. NEW_SHINY_THING_ENABLED=1 bin/rails s

  27. # config/toggles.yml development: shiny_new_thing: true production: shiny_new_thing: false

  28. None
  29. jnunemaker/flipper

  30. gem 'flipper' gem 'flipper-redis' gem 'flipper-ui'

  31. # config/initializers/flipper.rb Flipper.configure do |config| config.default do adapter = Flipper::Adapters::Redis.new(Redis.new)

    Flipper.new(adapter) end end
  32. class DashboardsController < ApplicationController def show if Flipper.enabled?(:new_dashboard, current_user) render

    'dashboards/new_dashboard' else render 'dashboards/current_dashboard' end end end
  33. Adapters & Gates & Plugins

  34. ADAPTERS Flipper::Adapters::Memory Flipper::Adapters::Http flipper-activerecord flipper-active_support_cache_store flipper_dalli flipper_mongo flipper_redis flipper_sequel flipper_consul

  35. Gates Boolean Actor Group % of Actors % of Time

  36. boolean gate Flipper.enabled?(:feature_name) # => false Flipper.enable(:feature_name) Flipper.enabled?(:feature_name) # =>

    true
  37. aCTOR gate class User def flipper_id "User:#{to_param}" end end Flipper.enabled?(:feature_just_for_you,

    current_user) Flipper.enable_actor(:feature_just_for_you, User.find(1))
  38. GROUP gate Flipper.register(:staff_users) do |actor| actor.respond_to?(:staff?) && actor.staff? end Flipper.enabled?(:staff_panel,

    current_user) Flipper.enable_group(:staff_panel, :staff_users)
  39. GROUP gate Flipper.register(:staff_users) do |actor| actor.respond_to?(:staff?) && actor.staff? end Flipper.register(:premium_clients)

    do |actor| actor.respond_to?(:subscription) && actor.subscription.plan_name == :premium end
  40. % gates Flipper.enable_percentage_of_actors(:new_search, 33) Flipper.enabled?(:new_search, User.find(1)) # => false Flipper.enabled?(:new_search,

    User.find(2)) # => false Flipper.enabled?(:new_search, User.find(3)) # => true Flipper.enable_percentage_of_time(:v2_header, 50) Flipper.enabled?(:v2_header) # => false Flipper.enabled?(:v2_header) # => true
  41. UI

  42. UI # config/routes.rb Rails.application.routes.draw do mount Flipper::UI.app(Flipper) => ‘/flipper/api’ end

  43. API # config/routes.rb Rails.application.routes.draw do mount Flipper::Api.app(Flipper) => '/flipper' end

  44. None
  45. None
  46. “Release toggles are a useful technique and lots of teams

    use them. However they should be your last choice when you're dealing with putting features into production.” https://martinfowler.com/bliki/FeatureToggle.html
  47. feature toggles são uma ferramenta de disponibilização de software

  48. configurações da app não são toggles

  49. configurações da app não são toggles toggle ou regra de

    negócio?
  50. configurações da app não são toggles toggle ou regra de

    negócio? qual a diferença entre manter vs remover?
  51. configurações da app não são toggles toggle ou regra de

    negócio? qual a diferença entre manter vs remover? será que não é só trauma de deploys ruins?
  52. testes

  53. testes servidores e clientes

  54. testes servidores e clientes bancos de dados e serviços externos

  55. feature toggles eventualmente são débitos técnicos

  56. planejar e priorizar remoções

  57. planejar e priorizar remoções testes de expiração

  58. planejar e priorizar remoções testes de expiração limites de inventário

  59. https://martinfowler.com/articles/feature-toggles.html

  60. None
  61. @lucasmazza https://speakerdeck.com/lucas Obrigado :)