Best practices-for-production-environments

  • 2,856 views
Uploaded on

 

More in: Engineering , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,856
On Slideshare
0
From Embeds
0
Number of Embeds
12

Actions

Shares
Downloads
18
Comments
0
Likes
6

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Best Practices for Production Environments
  • 2. These slides may not make much sense without a narrative! For the proper article, see
 http://peter.bourgon.org/go-in-production

  • 3. Some Go
 Projects Bazooka Traffic tier Media streaming Search & Explore glue Prometheus Stream backend* HLS implementation** Many others…
  • 4. Dev environment Repo structure Formatting and style Configuration Logging and telemetry Validation and testing Dependency management ᕕ( ᐛ )ᕗ Build and deploy
  • 5. Dev environment
  • 6. Single GOPATH for all projects Work in $GOPATH/src/github.com/soundcloud/foo vim, Sublime Text, emacs—no IDEs
  • 7. Repo structure
  • 8. github.com/soundcloud/whatever/
 README.md
 Makefile
 main.go
 support.go
 
 
 
 

  • 9. github.com/soundcloud/whatever/
 README.md
 Makefile
 main.go
 support.go
 foo/
 foo.go
 bar.go
 

  • 10. github.com/soundcloud/whatever/
 README.md
 Makefile
 whatever-server/
 main.go
 whatever-worker/
 main.go
 foo/
 foo.go
 bar.go
  • 11. Formatting and style
  • 12. go fmt Google’s Code Review Guidelines Avoid named return parameters Avoid make and new (unless you know sizes) Use struct{} for sentinel value: sets, signal chans Break long lines on parameters
  • 13. func process(dst io.Writer, readTimeout, 
 writeTimeout time.Duration, allowInvalid bool,
 max int, src <-chan util.Job) {
 // ...
 }
  • 14. func process(
 dst io.Writer,
 readTimeout, writeTimeout time.Duration,
 allowInvalid bool,
 max int,
 src <-chan util.Job,
 ) {
 // ...
 }
  • 15. f := foo.New(foo.Config{
 “zombo.com”,
 conference.KeyPair{
 Key: “gophercon”, // String value
 Value: 2014,
 },
 os.Stdout,
 })
  • 16. Configuration
  • 17. package flag
  • 18. func main() {
 var (
 foo = flag.String(“foo”, “doch”, “...”)
 bar = flag.Int(“bar”, 34, “...”)
 )
 flag.Parse()
 // ...
 }
  • 19. Logging and telemetry
  • 20. Logging and telemetry
  • 21. package log
  • 22. Logging and telemetry
  • 23. Push
 model Pull
 model vs. Graphite
 Statsd
 AirBrake expvar
 Prometheus
 others?
  • 24. Testing and validation
  • 25. Testing and validation
  • 26. package testing ☞reflect.DeepEqual☜
  • 27. // +build integration
 
 var fooAddr = flag.String(...)
 
 func TestFoo(t *testing.T) {
 f, err := newFoo(*fooAddr)
 // ...
 }
  • 28. Testing and validation
  • 29. Save Build onon go fmt goimports or go vet golint go test and and maybe Deploy on go test 
 -tags=integration gocov?
  • 30. YAGNI
  • 31. Dependency management
  • 32. How important is your project? go get -d & hope! VENDOR Eh Very ☞ ☞ import proxy?
  • 33. VENDOR submodules with subtrees with a tool with ✖✖✖ means copy your dependencies
  • 34. Binary VENDOR Library _vendor
 subdirectory Blessed build, with
 prefixed GOPATH + vendor
 subdirectory Rewrite your
 imports + ☞ ☞
  • 35. Build and deploy
  • 36. Build and deploy
  • 37. Development “Official” ☞ go build ☞ make
  • 38. GOVER=go1.2.1 ! STAGE=.stage GOPATH=$(CURDIR)/$(STAGE)/gopath GOROOT=$(CURDIR)/$(STAGE)/go GOCC=$(GOROOT)/bin/go GO=TMPDIR=/tmp GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC) ! OS=$(shell uname) ARCH=$(shell uname -m) GOOS=$(subst Darwin,darwin,$(subst Linux,linux,$(OS))) GOARCH=$(subst x86_64,amd64,$(ARCH)) GOPKG=$(subst darwin-amd64,darwin-amd64-osx10.8,$(GOVER).$(GOOS)-$(GOARCH).tar.gz) ! PKGBASE=github.com/soundcloud/goku PKGPATH=$(GOPATH)/src/$(PKGBASE) ! all: build ! build: $(GOCC) $(PKGPATH) GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-server build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-walker build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C reader build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C writer build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C gap-backfill build ! clean: GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-server clean
  • 39. Build and deploy
  • 40. StatefulStateless Any/no model12-Factor model ProvisionedScaled vs. Containers Containers? MySQL, RedisRequest router
  • 41. $ git push bazooka master
 $ bazooka scale -r <new> -n 4 ...
 $ # validate
 $ bazooka scale -r <old> -n 0 ... Deploying
 stateless
 services
  • 42. Embrace simplicity
  • 43. Thanks! ! Peter Bourgon @peterbourgon Questions?