Skip to content

Instantly share code, notes, and snippets.

View dwbutler's full-sized avatar

David Butler dwbutler

View GitHub Profile
@dwbutler
dwbutler / constant.rb
Created January 4, 2017 15:37
Check where a constant got changed
class Config
CONSTANT = 1
def CONSTANT=(val)
fail
end
end
config = Config.new
config.CONSTANT = 2
@dwbutler
dwbutler / 1. Running logstash
Last active April 29, 2017 06:05
LogStashLogger TCP downage error handling
$ logstash -f samples/tcp.conf
Settings: Default pipeline workers: 8
Pipeline main started
{"message":"\"2017-04-28T22:44:30.424-07:00\"","@timestamp":"2017-04-29T05:44:30.424Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.528-07:00\"","@timestamp":"2017-04-29T05:44:30.528Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.633-07:00\"","@timestamp":"2017-04-29T05:44:30.633Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.737-07:00\"","@timestamp":"2017-04-29T05:44:30.737Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.842-07:00\"","@timestamp":"2017-04-29T05:44:30.842Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.947-07:00\"","@timestamp":"2017-04-29T05:44:30.9
@dwbutler
dwbutler / sync.rake
Last active May 8, 2018 20:54
Sync Heroku prod data to another environment
namespace :sync do
desc "Run production sync"
task run: [
:set_app,
:maint_on,
:scale_down,
:cancel_backup,
:delete_database,
:create_production_fork,
:migrate,
@dwbutler
dwbutler / post_mortem.md
Created May 18, 2018 05:15
Postgres Downtime Post Mortem

Written by David. Much thanks to Lukasz for technical and moral support, and helping me grep the Papertrail logs.

All times are in EST.

  • Downtime window: 8:00 AM - 8:25 AM
  • Total downtime: 25 minutes

TL;DR

Heroku PGBackups was running during a database migration, and was unexpectedly holding a lock. Postgres stopped serving any queries until the backup was canceled.

@dwbutler
dwbutler / post_mortem.md
Created May 18, 2018 05:25
Downtime Post Mortem
  • Downtime window: 4:41 PM EST - 4:55 PM EST
  • Total downtime: 14 minutes

"Bob" (backend engineer) was the developer on call during this incident. All names have been changed to protect the innocent. :)

Summary

Bad code which prevented server startup was deployed to production. It had not been manually tested in a dev environment, but had passed all unit and

@dwbutler
dwbutler / heroku_slug_cleanup.rake
Created August 23, 2018 16:27
Automatically clean up Heroku slug
CLEANUP_THRESHOLD = 250 * 1_024_000 # 250 megabytes
# See https://robots.thoughtbot.com/how-to-reduce-a-large-heroku-compiled-slug-size
desc "Clean up the Heroku repo to reduce compiled slug size"
task cleanup: :set_app do
force = ENV.fetch('FORCE_CLEANUP', false)
if force || slug_size > CLEANUP_THRESHOLD
puts "Heroku compiled slug size exceeds 250 MB. Cleaning up the Heroku repo."
install_heroku_plugin('heroku-repo')
_execute heroku_command("repo:gc")
@dwbutler
dwbutler / private_protected.rb
Last active September 3, 2018 07:59
Demonstrates behavior of private and protected methods in child classes in Ruby (including some surprising behavior and pitfalls)
# Tested in Ruby 1.8.7
class ParentClass
def call_private_good
# Private methods can only be called without an explicit receiver
private_test
end
def call_private_bad
# Calling a private method with an explicit receiver (self) will fail