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

Feature Toggles! - Elixir

Feature Toggles! - Elixir

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 ferramentas open source e considerações a serem feitas sobre como e quando usar toggles na sua aplicação

5a90a67fa1a92e6a4b605cfd8da5e375?s=128

Lucas Mazza

August 25, 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 mix phx.server

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

  28. None
  29. jnunemaker/flipper

  30. tompave/fun_with_flags

  31. def deps do [ {:fun_with_flags, "~> 1.0.0"}, {:redix, "~> 0.7"},

    ] end
  32. config :fun_with_flags, :persistence, [adapter: FunWithFlags.Store.Persistent.Redis] config :fun_with_flags, :redis, "redis://locahost:6379/0" config

    :fun_with_flags, :cache, enabled: true, ttl: 900 config :fun_with_flags, :cache_bust_notifications, enabled: true, adapter: FunWithFlags.Notifications.PhoenixPubSub, client: MyApp.PubSub
  33. defmodule MyApp.DashboardController do use MyApp, :controller def show(conn, params) do

    if FunWithFlags.enabled?(:new_dashboard) do render conn, "new_dashboard.html" else render conn, "show.html" end end end
  34. Redis / Ecto + ETS & Pubsub

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

  36. boolean gate FunWithFlags.enabled?(:feature_name) # => false {:ok, true} = FunWithFlags.enable(:feature_name)

    FunWithFlags.enabled?(:feature_name) # => true
  37. aCTOR gate defimpl FunWithFlags.Actor, for: MyApp.User do def id(%{id: id})

    do "user:#{id}" end end FunWithFlags.enabled?(:feature_just_for_you, for: user) {:ok, true} = FunWithFlags.enable(:feature_just_for_you, for_actor: user)
  38. GROUP gate defimpl FunWithFlags.Group, for: MyApp.User do def in?(%{staff: is_staff},

    "staff_users"), do: !!is_staff end FunWithFlags.enabled?(:staff_panel, current_user) FunWithFlags.enable(:staff_panel, for_group: "staff_users")
  39. GROUP gate defimpl FunWithFlags.Group, for: MyApp.User do def in?(%{staff: is_staff},

    "staff_users"), do: !!is_staff end defimpl FunWithFlags.Group, for: MyApp.Client do def in?(%{subscription_plan: "premium"}, "premium_clients"), do: true end
  40. % gates FunWithFlags.enable(:new_search, for_percentage_of: {:actors, 0.33}) FunWithFlags.enabled?(:new_search, for_actor: user_1) #

    => false FunWithFlags.enabled?(:new_search, for_actor: user_2) # => false FunWithFlags.enabled?(:new_search, for_actor: user_3) # => true FunWithFlags.enable(:v2_header, for_percentage_of: {:time, 0.50}) FunWithFlags.enabled?(:v2_header) # => false FunWithFlags.enabled?(:v2_header) # => true
  41. UI

  42. UI

  43. UI defmodule MyApp.Web.Router do use MyApp.Web, :router pipeline :mounted_apps do

    plug :accepts, ["html"] plug :put_secure_browser_headers end scope path: "/feature-flags" do pipe_through :mounted_apps forward "/", FunWithFlags.UI.Router, namespace: "feature-flags" end 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 :)