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

Lucas Mazza

August 25, 2018
Tweet

More Decks by Lucas Mazza

Other Decks in Technology

Transcript

  1. 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. ”
  2. “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/
  3. “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
  4. “Feature Toggles are a powerful technique, allowing teams to modify

    system behavior without changing code.” https://martinfowler.com/articles/feature-toggles.html
  5. 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
  6. 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
  7. 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)
  8. 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")
  9. 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
  10. % 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
  11. UI

  12. UI

  13. 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
  14. “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
  15. configurações da app não são toggles toggle ou regra de

    negócio? qual a diferença entre manter vs remover?
  16. 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?