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

Lucas Mazza

August 18, 2018
Tweet

More Decks by Lucas Mazza

Other Decks in Technology

Transcript

  1. Feature toggles

    View full-size slide

  2. @lucasmazza
    https://afterhours.io

    View full-size slide

  3. https://magnetis.workable.com

    View full-size slide

  4. Feature Toggles 101

    View full-size slide

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

    View full-size slide

  6. 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. ”

    View full-size slide

  7. “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/

    View full-size slide

  8. “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

    View full-size slide

  9. Trunk based development
    +
    Mudanças demoradas
    =
    FEATURE TOGGLEs

    View full-size slide

  10. “Feature Toggles are a powerful
    technique, allowing teams to modify
    system behavior without changing
    code.”
    https://martinfowler.com/articles/feature-toggles.html

    View full-size slide

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

    View full-size slide

  12. release toggles

    View full-size slide









  13. View full-size slide









  14. View full-size slide

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

    View full-size slide

  16. permission toggles

    View full-size slide

  17. experiment toggles

    View full-size slide

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

    View full-size slide

  19. NEW_SHINY_THING_ENABLED=1 bin/rails s

    View full-size slide

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

    View full-size slide

  21. jnunemaker/flipper

    View full-size slide

  22. gem 'flipper'
    gem 'flipper-redis'
    gem 'flipper-ui'

    View full-size slide

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

    View full-size slide

  24. class DashboardsController < ApplicationController
    def show
    if Flipper.enabled?(:new_dashboard, current_user)
    render 'dashboards/new_dashboard'
    else
    render 'dashboards/current_dashboard'
    end
    end
    end

    View full-size slide

  25. Adapters &
    Gates &
    Plugins

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  29. 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))

    View full-size slide

  30. 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)

    View full-size slide

  31. 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

    View full-size slide

  32. % 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  35. “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

    View full-size slide

  36. feature toggles são uma ferramenta
    de disponibilização de software

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  40. 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?

    View full-size slide

  41. testes
    servidores e clientes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  44. planejar e priorizar remoções

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  48. @lucasmazza
    https://speakerdeck.com/lucas
    Obrigado :)

    View full-size slide