Slide 1

Slide 1 text

Refactoring GitHub with Science ! #BigRubyConf

Slide 2

Slide 2 text

! Hello, my name is Wynn.

Slide 3

Slide 3 text

! Folks call me @pengwynn.

Slide 4

Slide 4 text

! http://wynn.fm

Slide 5

Slide 5 text

Changing code is EASY! !

Slide 6

Slide 6 text

Changing code with CONFIDENCE isn't. !

Slide 7

Slide 7 text

How do we gain CONFIDENCE? !

Slide 8

Slide 8 text

Write lots of TESTS. ! ❯ testrb test/integration/api/repos_test.rb Loading suite in dotcom mode ... Run options: # Running tests: Finished tests in 30.638101s, 4.7979 tests/s, 64.7886 assertions/s. 147 tests, 1985 assertions, 0 failures, 0 errors, 0 skips ruby -v: ruby 2.1.0p0-github (development) [x86_64-darwin13.0]

Slide 9

Slide 9 text

Use data to inform decisions. !

Slide 10

Slide 10 text

! /graph me -1hr @api.queries.serialized >

Slide 11

Slide 11 text

The Graph Store ! !

Slide 12

Slide 12 text

The Graph Store ! ! There's a graph for that™

Slide 13

Slide 13 text

The Graph Store ! ! There's a graph for that™ …if not, make one.

Slide 14

Slide 14 text

! Built on Graphite.

Slide 15

Slide 15 text

!

Slide 16

Slide 16 text

!

Slide 17

Slide 17 text

! # counter GitHub.stats.increment("the-thing.the-action") ! # gauge GitHub.stats.gauge("the-thing.the-gauge", thing.current_reading) ! # timing GitHub.stats.time("the-thing.the-operation") { the_operation }

Slide 18

Slide 18 text

! # counter GitHub.stats.increment("the-thing.the-action") ! # gauge GitHub.stats.gauge("the-thing.the-gauge", thing.current_reading) ! # timing GitHub.stats.time("the-thing.the-operation") { the_operation }

Slide 19

Slide 19 text

! # counter GitHub.stats.increment("the-thing.the-action") ! # gauge GitHub.stats.gauge("the-thing.the-gauge", thing.current_reading) ! # timing GitHub.stats.time("the-thing.the-operation") { the_operation }

Slide 20

Slide 20 text

Deploy with confidence. " !

Slide 21

Slide 21 text

How# has "'d over the years. !

Slide 22

Slide 22 text

1989 10 PRINT "WYNN" 20 GOTO 10

Slide 23

Slide 23 text

1994

Slide 24

Slide 24 text

1999 !

Slide 25

Slide 25 text

2004 !

Slide 26

Slide 26 text

2009 ! # General configuration settings, required for all recipes! set :application, "project-name" set :domain, "project-domain" set :extra_domains, %w() # Add something like www.project-domain.com role :app, domain role :web, domain role :db, domain, :primary => true ! # set :user, "user" ! # Deployment Settings set :repository, "repository url" set :deploy_to, "/absolute/path/to/location/your/server" set :deploy_via, :checkout set :config_files, %w() ! # SSH Keys for caching (you must generate these first.) ssh_options[:keys] = %w(~/.ssh/mykey1 ~/.ssh/mykey2) ! # Change this to :thin if you want to use Thin instead. set :app_server, :mongrel ! # Change this to :merb if you want to use Merb instead. (experimental) set :app_framework, :rails ! # ============================================================= # Application Server Settings (Thin or Mongrel) # ============================================================= set :app_servers, 1 set :app_server_port, 7007 set :app_environment, 'production' set :app_server_address, '127.0.0.1' set :app_server_conf, "#{shared_path}/config/thin.yml" ! # ============================================================= # Nginx Settings

Slide 27

Slide 27 text

Today !

Slide 28

Slide 28 text

! The GitHub Flow

Slide 29

Slide 29 text

! Start with a Pull Request.

Slide 30

Slide 30 text

!

Slide 31

Slide 31 text

! Create a branch.

Slide 32

Slide 32 text

! Add commits.

Slide 33

Slide 33 text

! Open a pull request.

Slide 34

Slide 34 text

! Discuss and review.

Slide 35

Slide 35 text

! Merge and deploy.

Slide 36

Slide 36 text

! Or deploy and merge. $

Slide 37

Slide 37 text

! %

Slide 38

Slide 38 text

!

Slide 39

Slide 39 text

! The following deployments are based on actual events. Branch names and SHAs have been changed to protect the innocent.

Slide 40

Slide 40 text

! hubot where can I deploy? > Environments for github ----------------------------------------------------- production: unlocked lab-one: locked 6 hours ago by jasonrudolph lab-two: unlocked sekret-lab: unlocked playground: unlocked

Slide 41

Slide 41 text

! hubot deploy github/api-my-feature to production >

Slide 42

Slide 42 text

! hubot deploy github/api-my-feature to production > project

Slide 43

Slide 43 text

! hubot deploy github/api-my-feature to production > branch

Slide 44

Slide 44 text

! hubot deploy github/api-my-feature to production > environment

Slide 45

Slide 45 text

! hubot deploy github/api-my-feature to production > Merge master into api-my-feature for pengwynn - hubot github/github@deadbeef

Slide 46

Slide 46 text

! Get up to date with master. ⏳

Slide 47

Slide 47 text

! Wait on the CI server. '

Slide 48

Slide 48 text

!

Slide 49

Slide 49 text

! hubot tv me >

Slide 50

Slide 50 text

! hubot deploy github/api-my-feature to production > Build #8675309 (deadbeef) of github/api-my-feature was successful (203s)

Slide 51

Slide 51 text

! Release the kraken! (

Slide 52

Slide 52 text

! hubot deploy github/api-my-feature to production > pengwynn is deploying github/api-my-feature (beefdead..deadbeef) to production pengwynn's production deployment of github is NOW )))! (22s)

Slide 53

Slide 53 text

"The first transport is away!"

Slide 54

Slide 54 text

## TODO - [x] Deploy " - [ ] Observe * !

Slide 55

Slide 55 text

!

Slide 56

Slide 56 text

!

Slide 57

Slide 57 text

!

Slide 58

Slide 58 text

!

Slide 59

Slide 59 text

! Problem? ABORT. +

Slide 60

Slide 60 text

! hubot deploy! github > pengwynn is deploying github/master to production

Slide 61

Slide 61 text

! ✨Everything -? MERGE.✨

Slide 62

Slide 62 text

!

Slide 63

Slide 63 text

! > pengwynn: it looks like you merged "api-my-feature" branch into master, so I've unlocked production.

Slide 64

Slide 64 text

! > pengwynn is deploying github/master to production pengwynn is deploying github/master to lab-one pengwynn is deploying github/master to lab-two pengwynn is deploying github/master to sekret-lab

Slide 65

Slide 65 text

Prune with confidence. ✂️ !

Slide 66

Slide 66 text

! “Are we even calling this anywhere?”

Slide 67

Slide 67 text

! Find and remove vestigial code.

Slide 68

Slide 68 text

! GitHub::Backscatter

Slide 69

Slide 69 text

! GitHub::Backscatter not open source, but you can roll your own

Slide 70

Slide 70 text

! *69 for Ruby methods

Slide 71

Slide 71 text

class Foo include GitHub::Backscatter ! def the_method(args) backscatter_measure # ... end end

Slide 72

Slide 72 text

class Foo include GitHub::Backscatter ! def the_method(args) backscatter_measure # ... end end

Slide 73

Slide 73 text

class Foo include GitHub::Backscatter ! def the_method(args) backscatter_measure # ... end end

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

The calls are coming from INSIDE the APP. 0

Slide 76

Slide 76 text

class Foo include GitHub::Backscatter ! def the_method(args) backscatter_measure 1000 # ... end end

Slide 77

Slide 77 text

class Foo include GitHub::Backscatter ! def the_method(args) backscatter_measure 1000 # ... end end trace 1 out of every 1000 calls

Slide 78

Slide 78 text

Experiment with confidence. 1 !

Slide 79

Slide 79 text

! 1

Slide 80

Slide 80 text

! github/dat-science

Slide 81

Slide 81 text

! @jbarnette

Slide 82

Slide 82 text

! @rick

Slide 83

Slide 83 text

!

Slide 84

Slide 84 text

!

Slide 85

Slide 85 text

! Safely observe alternate code paths.

Slide 86

Slide 86 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 87

Slide 87 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 88

Slide 88 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 89

Slide 89 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 90

Slide 90 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 91

Slide 91 text

require "dat/science" ! class MyApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new \ "widget-permissions" do |e| ! e.control { old_method } # old way e.candidate { new_method } # new way end ! experiment.run end end

Slide 92

Slide 92 text

! Fancy a DSL?

Slide 93

Slide 93 text

require "dat/science" ! class MyApp::Widget def allows?(user) science "widget-permissions" do |e| e.control { model.check_user(user).valid? } e.candidate { user.can? :read, model } end end end

Slide 94

Slide 94 text

require "dat/science" ! class MyApp::Widget def allows?(user) science "widget-permissions" do |e| e.control { model.check_user(user).valid? } e.candidate { user.can? :read, model } end end end

Slide 95

Slide 95 text

! Create and run.

Slide 96

Slide 96 text

require "dat/science" ! class Blog::Post def permalink(user) science "permalink" do |e| e.control { post[:permalink] } e.candidate { post.slug } e.comparator {|a, b| a.downcase == b.downcase } end end end

Slide 97

Slide 97 text

require "dat/science" ! class Blog::Post def permalink(user) science "permalink" do |e| e.control { post[:permalink] } e.candidate { post.slug } e.comparator {|a, b| a.downcase == b.downcase } end end end

Slide 98

Slide 98 text

! Ramping up experiments.

Slide 99

Slide 99 text

require "dat/science" ! module Myapp class Experiment < Dat::Science::Experiment def enabled? rand(100) < 10 # Run 10% of the time end end end

Slide 100

Slide 100 text

! jnunemaker/flipper 2

Slide 101

Slide 101 text

require "dat/science" ! module Myapp class Experiment < Dat::Science::Experiment def enabled? MyApp.flipper[name].enabled? end end end

Slide 102

Slide 102 text

! Publishing results.

Slide 103

Slide 103 text

require "dat/science" ! module Myapp class Experiment < Dat::Science::Experiment def publish MyApp.instrument "science.#{event}", payload end end end

Slide 104

Slide 104 text

require "dat/science" ! module Myapp class Experiment < Dat::Science::Experiment def publish MyApp.instrument "science.#{event}", payload end end end

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

! Adding custom context.

Slide 108

Slide 108 text

require "dat/science" ! class Blog::Post def permalink(user) science "permalink" do |e| e.context :post => post e.control { post[:permalink] } e.candidate { post.slug } e.comparator {|a, b| a.downcase == b.downcase } end end end

Slide 109

Slide 109 text

require "dat/science" ! class Blog::Post def permalink(user) science "permalink" do |e| e.context :post => post e.control { post[:permalink] } e.candidate { post.slug } e.comparator {|a, b| a.downcase == b.downcase } end end end

Slide 110

Slide 110 text

Mad science.

Slide 111

Slide 111 text

module GitHub class Experiment < Dat::Science::Experiment class << self # Public: enable mad science mode: returns the candidate values by default # instead of the control. def mad_science=(val) @mad_science = val end ! # Internal: whether or not to always run the candidate instead of the # control. def candidate_instead_of_control? @mad_science end end … end

Slide 112

Slide 112 text

module GitHub class Experiment < Dat::Science::Experiment class << self # Public: enable mad science mode: returns the candidate values by default # instead of the control. def mad_science=(val) @mad_science = val end ! # Internal: whether or not to always run the candidate instead of the # control. def candidate_instead_of_control? @mad_science end end … end

Slide 113

Slide 113 text

! Analyzing results.

Slide 114

Slide 114 text

! github/dat-analysis

Slide 115

Slide 115 text

Thanks, Jim.

Slide 116

Slide 116 text

! EOF