SlideShare a Scribd company logo
1 of 25
Download to read offline
Writing Docker
monitoring agent with Go
ainoya
About me
• Naoki Ainoya( ainoya)
• iOS(new!)/Server/Infra engineer
• Swift/Scala/Go/Docker
• Recruit Marketing Partners Co, Ltd.
A tiny deployment pipeline tool
Written in Go
walter-cd/walter
Open source project
Introduction of Fune
• An event emitter triggered by Docker Event API
• The agent process (fune-agent) communicates with docker
daemon via its socket
• https://github.com/ainoya/fune
Docker daemon
Funeagent
ConttainerA
ConttainerB
ConttainerC
Nginx/Redis
vulcand(etcd)
Slack notification etc..
Listens docker
events API
notifies each containers are
created/died/stopped/started
Emits pluggable
actions
Your
arbitrary docker ecosystem
ECS/k8s/fleet/etc..
Docker Host
Deploy containers
Overview of Fune
• Docker Events API provides a lifecycle of container
as JSON format
• create/start/die/stop
Overview of Fune
fune-agent listens these events
Docker daemon
Funeagent
ConttainerA
ConttainerB
ConttainerC
Listens docker
events API
notifies each containers are
created/died/stopped/started
Your
arbitrary docker ecosystem
ECS/k8s/fleet/etc..
Docker Host
Deploy containers
Overview of Fune
fune-agent emits Action

when received Docker events

from event
Docker daemon
Funeagent
ConttainerA
ConttainerB
Nginx/Redis
vulcand(etcd)
Slack notification etc..
Listens docker
events API
notifies each containers are
created/died/stopped/started
Emits pluggable
actions
Your
arbitrary docker ecosystem
ECS/k8s/fleet/etc..
Docker Host
Deploy containers
Overview of Fune
Docker daemon
Funeagent
ConttainerA
ConttainerB
Nginx/Redis
vulcand(etcd)
Slack notification etc..
Listens docker
events API
notifies each containers are
created/died/stopped/started
Emits pluggable
actions
Your
arbitrary docker ecosystem
ECS/k8s/fleet/etc..
Docker Host
Deploy containers
• Action, for example;
• Set/Del a container information to Redis as
FQDN/IP:Port pair for proxy
• Slack notification
• More details are next time :)
Today I talk about:
• Some tips I learned with writing fune
• Studied a lot of stuffs from coreos/etcd
Setup project
• Standard structure for 

working with Godeps correctly
• /src/github.com/ainoya/fune
./${GOPATH}/src
!"" 9fans.net
#   %"" go
!"" code.google.com
#   %"" p
!"" github.com
#   !"" ainoya/fune
#   !"" barakmich
#   !"" coreos etc...
Godeps for the package
dependencies
• Using Godeps once, all dependencies copied into
directory and rewrite import statement
• Then you need Godeps command only if package
dependency is added
import "github.com/fsouza/go-dockerclient"
// after `Godep save -r ./…`
import "github.com/ainoya/fune/Godeps/_workspace/
src/github.com/fsouza/go-dockerclient"
Godeps for the package
dependencies
• All dependencies are included in git repos
• But it makes dirty commit log!!
• Keep off its dirtiness by split commits :)
How about vendor feature in
go1.5?
• go1.5 vendor feature have some problems yet
• ex) go	
  tool	
  "./…" doesn't works well
• https://github.com/golang/go/issues/11659
• See also ) http://deeeet.com/writing/2015/06/26/golang-dependency-
vendoring/
Write tests
• Rerun automatically if files are changed
• rerun is awesome! (but ruby tool gem)
rerun -x -c -d directory1, directory2,...
—pattern '**/*.{go}' -- go test ./...
Be careful about race condition
• Test with "-­‐race" option if you often use goroutine in your code
• "-­‐cpu	
  N" option may reveal race condition you didn't expected
• I use "go	
  test	
  ./…	
  -­‐race	
  -­‐cpu	
  1,2,4" inside test script
WARNING: DATA RACE
Write by goroutine 8:
sync.raceWrite()
/usr/local/Cellar/go/1.5/libexec/src/sync/race.go:41 +0x2e
sync.(*WaitGroup).Wait()
/usr/local/Cellar/go/1.5/libexec/src/sync/waitgroup.go:124 +0xf9
github.com/ainoya/fune/emitter.TestBroadCast()
/Users/ainoya/.go/src/github.com/ainoya/fune/gopath/src/github.com/
ainoya/fune/emitter/emitter_test.go:57 +0x444
testing.tRunner()
/usr/local/Cellar/go/1.5/libexec/src/testing/testing.go:456 +0xdc
Is Go1.5 compilation time
slower than 1.4?
• "go	
  test" obviously takes time much longer
• It's probably because of GoGo compiler
performance

Ref) Performance section of https://golang.org/doc/go1.5
• It should be improved with Go1.6
Channel tips
• coreos/etcd implements a shutdown feature with
using close(channel)
type	
  Server	
  struct	
  {	
  
	
   name	
  	
  	
  	
  string	
  
	
   channel	
  chan	
  struct{}	
  
	
   done	
  	
  	
  	
  chan	
  struct{}	
  
	
   stop	
  	
  	
  	
  chan	
  struct{}	
  
}	
  
func	
  main()	
  {	
  
	
   done	
  :=	
  make(chan	
  struct{})	
  
	
   stop	
  :=	
  make(chan	
  struct{})	
  
	
   s	
  :=	
  &Server{done:	
  done,	
  stop:	
  stop,	
  
hoge:	
  hoge}	
  
	
   go	
  s.run()	
  
	
   s.channel	
  <-­‐	
  struct{}{}	
  
	
   osutil.RegisterInterrputHandler(s.Stop)	
  
	
   <-­‐s.done	
  
}
func	
  (s	
  *Server)	
  run()	
  {	
  
	
   defer	
  func()	
  {	
  close(s.done)	
  }()	
  
	
   for	
  {	
  
	
   	
   select	
  {	
  
	
   	
   case	
  <-­‐s.channel:	
  
	
   	
   	
   fmt.Println("do	
  something")	
  
	
   	
   case	
  <-­‐s.stop:	
  
	
   	
   	
   return	
  
	
   	
   }	
  
	
   }	
  
}	
  
func	
  (s	
  *S)	
  Stop()	
  {	
  
	
   select	
  {	
  
	
   case	
  s.stop	
  <-­‐	
  struct{}{}:	
  
	
   case	
  <-­‐s.done:	
  
	
   	
   return	
  
	
   }	
  
	
   <-­‐s.done	
  
}	
  
Channel tips
• coreos/etcd implements a shutdown feature with
using close(channel)
type	
  Server	
  struct	
  {	
  
	
   name	
  	
  	
  	
  string	
  
	
   channel	
  chan	
  struct{}	
  
	
   done	
  	
  	
  	
  chan	
  struct{}	
  
	
   stop	
  	
  	
  	
  chan	
  struct{}	
  
}	
  
func	
  main()	
  {	
  
	
   done	
  :=	
  make(chan	
  struct{})	
  
	
   stop	
  :=	
  make(chan	
  struct{})	
  
	
   s	
  :=	
  &Server{done:	
  done,	
  stop:	
  stop,	
  
hoge:	
  hoge}	
  
	
   go	
  s.run()	
  
	
   s.channel	
  <-­‐	
  struct{}{}	
  
	
   osutil.RegisterInterrputHandler(s.Stop)	
  
	
   <-­‐s.done	
  
}
func	
  (s	
  *Server)	
  run()	
  {	
  
	
   defer	
  func()	
  {	
  close(s.done)	
  }()	
  
	
   for	
  {	
  
	
   	
   select	
  {	
  
	
   	
   case	
  <-­‐s.channel:	
  
	
   	
   	
   fmt.Println("do	
  something")	
  
	
   	
   case	
  <-­‐s.stop:	
  
	
   	
   	
   return	
  
	
   	
   }	
  
	
   }	
  
}	
  
func	
  (s	
  *S)	
  Stop()	
  {	
  
	
   select	
  {	
  
	
   case	
  s.stop	
  <-­‐	
  struct{}{}:	
  
	
   case	
  <-­‐s.done:	
  
	
   	
   return	
  
	
   }	
  
	
   <-­‐s.done	
  
}	
  
Channel tips
• coreos/etcd implements a shutdown feature with
using close(channel)
type	
  Server	
  struct	
  {	
  
	
   name	
  	
  	
  	
  string	
  
	
   channel	
  chan	
  struct{}	
  
	
   done	
  	
  	
  	
  chan	
  struct{}	
  
	
   stop	
  	
  	
  	
  chan	
  struct{}	
  
}	
  
func	
  main()	
  {	
  
	
   done	
  :=	
  make(chan	
  struct{})	
  
	
   stop	
  :=	
  make(chan	
  struct{})	
  
	
   s	
  :=	
  &Server{done:	
  done,	
  stop:	
  stop,	
  
hoge:	
  hoge}	
  
	
   go	
  s.run()	
  
	
   s.channel	
  <-­‐	
  struct{}{}	
  
	
   osutil.RegisterInterrputHandler(s.stop)	
  
	
   <-­‐s.done	
  
}
func	
  (s	
  *Server)	
  run()	
  {	
  
	
   defer	
  func()	
  {	
  close(s.done)	
  }()	
  
	
   for	
  {	
  
	
   	
   select	
  {	
  
	
   	
   case	
  <-­‐s.channel:	
  
	
   	
   	
   fmt.Println("do	
  something")	
  
	
   	
   case	
  <-­‐s.stop:	
  
	
   	
   	
   return	
  
	
   	
   }	
  
	
   }	
  
}	
  
func	
  (s	
  *S)	
  Stop()	
  {	
  
	
   select	
  {	
  
	
   case	
  s.stop	
  <-­‐	
  struct{}{}:	
  
	
   case	
  <-­‐s.done:	
  
	
   	
   return	
  
	
   }	
  
	
   <-­‐s.done	
  
}	
  
Channel tips
• coreos/etcd implements a shutdown feature with
using close(channel)
type	
  Server	
  struct	
  {	
  
	
   name	
  	
  	
  	
  string	
  
	
   channel	
  chan	
  struct{}	
  
	
   done	
  	
  	
  	
  chan	
  struct{}	
  
	
   stop	
  	
  	
  	
  chan	
  struct{}	
  
}	
  
func	
  main()	
  {	
  
	
   done	
  :=	
  make(chan	
  struct{})	
  
	
   stop	
  :=	
  make(chan	
  struct{})	
  
	
   s	
  :=	
  &Server{done:	
  done,	
  stop:	
  stop,	
  
hoge:	
  hoge}	
  
	
   go	
  s.run()	
  
	
   s.channel	
  <-­‐	
  struct{}{}	
  
	
   osutil.RegisterInterrputHandler(s.Stop)	
  
	
   <-­‐s.done	
  
}
func	
  (s	
  *Server)	
  run()	
  {	
  
	
   defer	
  func()	
  {	
  close(s.done)	
  }()	
  
	
   for	
  {	
  
	
   	
   select	
  {	
  
	
   	
   case	
  <-­‐s.channel:	
  
	
   	
   	
   fmt.Println("do	
  something")	
  
	
   	
   case	
  <-­‐s.stop:	
  
	
   	
   	
   return	
  
	
   	
   }	
  
	
   }	
  
}	
  
func	
  (s	
  *S)	
  Stop()	
  {	
  
	
   select	
  {	
  
	
   case	
  s.stop	
  <-­‐	
  struct{}{}:	
  
	
   case	
  <-­‐s.done:	
  
	
   	
   return	
  
	
   }	
  
	
   <-­‐s.done	
  
}	
  
Channel tips
• coreos/etcd implements a shutdown feature with
using close(channel)
type	
  Server	
  struct	
  {	
  
	
   name	
  	
  	
  	
  string	
  
	
   channel	
  chan	
  struct{}	
  
	
   done	
  	
  	
  	
  chan	
  struct{}	
  
	
   stop	
  	
  	
  	
  chan	
  struct{}	
  
}	
  
func	
  main()	
  {	
  
	
   done	
  :=	
  make(chan	
  struct{})	
  
	
   stop	
  :=	
  make(chan	
  struct{})	
  
	
   s	
  :=	
  &Server{done:	
  done,	
  stop:	
  stop,	
  
hoge:	
  hoge}	
  
	
   go	
  s.run()	
  
	
   s.channel	
  <-­‐	
  struct{}{}	
  
	
   osutil.RegisterInterrputHandler(s.Stop)	
  
	
   <-­‐s.done	
  
}
func	
  (s	
  *Server)	
  run()	
  {	
  
	
   defer	
  func()	
  {	
  close(s.done)	
  }()	
  
	
   for	
  {	
  
	
   	
   select	
  {	
  
	
   	
   case	
  <-­‐s.channel:	
  
	
   	
   	
   fmt.Println("do	
  something")	
  
	
   	
   case	
  <-­‐s.stop:	
  
	
   	
   	
   return	
  
	
   	
   }	
  
	
   }	
  
}	
  
func	
  (s	
  *S)	
  Stop()	
  {	
  
	
   select	
  {	
  
	
   case	
  s.stop	
  <-­‐	
  struct{}{}:	
  
	
   case	
  <-­‐s.done:	
  
	
   	
   return	
  
	
   }	
  
	
   <-­‐s.done	
  
}	
  
Test goroutine easily
"s.done" channel makes testing goroutine easily
//	
  https://github.com/coreos/etcd/blob/master/etcdserver/
server_test.go#L1031	
  
//	
  TestPublishRetry	
  tests	
  that	
  publish	
  will	
  keep	
  retry	
  until	
  success.	
  
func	
  TestPublishRetry(t	
  *testing.T)	
  {	
  
	
   n	
  :=	
  &nodeRecorder{}	
  
	
   srv	
  :=	
  &EtcdServer{	
  
	
   	
   cfg:	
  	
  	
  	
  	
  	
  &ServerConfig{TickMs:	
  1},	
  
	
   	
   r:	
  	
  	
  	
  	
  	
  	
  	
  raftNode{Node:	
  n},	
  
	
   	
   w:	
  	
  	
  	
  	
  	
  	
  	
  &waitRecorder{},	
  
	
   	
   done:	
  	
  	
  	
  	
  make(chan	
  struct{}),	
  
	
   	
   reqIDGen:	
  idutil.NewGenerator(0,	
  time.Time{}),	
  
	
   }	
  
	
   time.AfterFunc(500*time.Microsecond,	
  func()	
  {	
  close(srv.done)	
  })	
  
	
   srv.publish(10	
  *	
  time.Nanosecond)	
  
Run go as Docker container
• Go single binary with "SCRATCH"
• You can run a go stuff inside extremely simple container!
FROM	
  scratch	
  
EXPOSE	
  8080	
  
COPY	
  your-­‐golang-­‐app	
  /app/your-­‐golang-­‐app	
  
ENV	
  PATH=/app:$PATH	
  
ENTRYPOINT	
  ["/app/your-­‐golang-­‐app"]	
  
CMD	
  ["-­‐some-­‐option=haha"]
Round up
• Learned a lot of stuffs from well-knowned products
(coreos/etcd)
• project structure, test, golang-way
See you next kyobashi.*!
• 9/7: kyobashi.dex
• 9/16: potatotips
• ???: kyobashi.???

More Related Content

What's hot

Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007
 

What's hot (20)

Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
 
GeeCON 2014 - Functional Programming without Lambdas
GeeCON 2014 - Functional Programming without LambdasGeeCON 2014 - Functional Programming without Lambdas
GeeCON 2014 - Functional Programming without Lambdas
 
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
Java/Scala Lab: Руслан Шевченко - Implementation of CSP (Communication Sequen...
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
 
Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)
 
Common mistakes functional java vjug
Common mistakes functional java vjugCommon mistakes functional java vjug
Common mistakes functional java vjug
 
Common mistakes functional java | Oracle Code One 2018
Common mistakes functional java | Oracle Code One 2018Common mistakes functional java | Oracle Code One 2018
Common mistakes functional java | Oracle Code One 2018
 
Transducers in JavaScript
Transducers in JavaScriptTransducers in JavaScript
Transducers in JavaScript
 
Scu scsi-summary
Scu scsi-summaryScu scsi-summary
Scu scsi-summary
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
Flux and InfluxDB 2.0
Flux and InfluxDB 2.0Flux and InfluxDB 2.0
Flux and InfluxDB 2.0
 
Ten common mistakes made with Functional Java JBCNConf18
Ten common mistakes made with Functional Java JBCNConf18Ten common mistakes made with Functional Java JBCNConf18
Ten common mistakes made with Functional Java JBCNConf18
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
Adb instructions
Adb instructionsAdb instructions
Adb instructions
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating language
 
Async data pipelines for client-side JavaScript
Async data pipelines for client-side JavaScriptAsync data pipelines for client-side JavaScript
Async data pipelines for client-side JavaScript
 
Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
 

Viewers also liked

Viewers also liked (20)

このあと滅茶苦茶LGTMした
このあと滅茶苦茶LGTMしたこのあと滅茶苦茶LGTMした
このあと滅茶苦茶LGTMした
 
cert
certcert
cert
 
Performance Monitoring for Docker Environments - Docker Amsterdam June Meetup
Performance Monitoring for Docker Environments - Docker Amsterdam June MeetupPerformance Monitoring for Docker Environments - Docker Amsterdam June Meetup
Performance Monitoring for Docker Environments - Docker Amsterdam June Meetup
 
Gobotについて
GobotについてGobotについて
Gobotについて
 
Discussing the difference between docker dontainers and virtual machines
Discussing the difference between docker dontainers and virtual machinesDiscussing the difference between docker dontainers and virtual machines
Discussing the difference between docker dontainers and virtual machines
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
 
Running Netflix OSS on Docker with Nirmata
Running Netflix OSS on Docker with NirmataRunning Netflix OSS on Docker with Nirmata
Running Netflix OSS on Docker with Nirmata
 
Docker Indy Meetup Monitoring 30-Aug-2016
Docker Indy Meetup Monitoring 30-Aug-2016Docker Indy Meetup Monitoring 30-Aug-2016
Docker Indy Meetup Monitoring 30-Aug-2016
 
Netflix and Containers: Not A Stranger Thing
Netflix and Containers:  Not A Stranger ThingNetflix and Containers:  Not A Stranger Thing
Netflix and Containers: Not A Stranger Thing
 
Microservices with Netflix OSS and Spring Cloud - Dev Day Orange
Microservices with Netflix OSS and Spring Cloud -  Dev Day OrangeMicroservices with Netflix OSS and Spring Cloud -  Dev Day Orange
Microservices with Netflix OSS and Spring Cloud - Dev Day Orange
 
NetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker TalkNetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker Talk
 
Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes
 
Microservices and APIs
Microservices and APIsMicroservices and APIs
Microservices and APIs
 
Real world #microservices with Apache Camel, Fabric8, and OpenShift
Real world #microservices with Apache Camel, Fabric8, and OpenShiftReal world #microservices with Apache Camel, Fabric8, and OpenShift
Real world #microservices with Apache Camel, Fabric8, and OpenShift
 
Goだけでモバイルアプリを作る
Goだけでモバイルアプリを作るGoだけでモバイルアプリを作る
Goだけでモバイルアプリを作る
 
Overseeing Ship's Surveys and Surveyors Globally Using IoT and Docker by Jay ...
Overseeing Ship's Surveys and Surveyors Globally Using IoT and Docker by Jay ...Overseeing Ship's Surveys and Surveyors Globally Using IoT and Docker by Jay ...
Overseeing Ship's Surveys and Surveyors Globally Using IoT and Docker by Jay ...
 
Learning the Alphabet: A/B, CD and [E-Z] in the Docker Datacenter by Brett Ti...
Learning the Alphabet: A/B, CD and [E-Z] in the Docker Datacenter by Brett Ti...Learning the Alphabet: A/B, CD and [E-Z] in the Docker Datacenter by Brett Ti...
Learning the Alphabet: A/B, CD and [E-Z] in the Docker Datacenter by Brett Ti...
 
Securing the Container Pipeline at Salesforce by Cem Gurkok
Securing the Container Pipeline at Salesforce by Cem Gurkok   Securing the Container Pipeline at Salesforce by Cem Gurkok
Securing the Container Pipeline at Salesforce by Cem Gurkok
 
Docker in Production, Look No Hands! by Scott Coulton
Docker in Production, Look No Hands! by Scott CoultonDocker in Production, Look No Hands! by Scott Coulton
Docker in Production, Look No Hands! by Scott Coulton
 
Build Fast, Deploy Fast: Innovating in the Enterprise by Imran Raja and Andy Lim
Build Fast, Deploy Fast: Innovating in the Enterprise by Imran Raja and Andy LimBuild Fast, Deploy Fast: Innovating in the Enterprise by Imran Raja and Andy Lim
Build Fast, Deploy Fast: Innovating in the Enterprise by Imran Raja and Andy Lim
 

Similar to Writing Docker monitoring agent with Go

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scala
lunfu zhong
 

Similar to Writing Docker monitoring agent with Go (20)

Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Go Concurrency Patterns
Go Concurrency PatternsGo Concurrency Patterns
Go Concurrency Patterns
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scala
 
Concurrency in go
Concurrency in goConcurrency in go
Concurrency in go
 
Reitit - Clojure/North 2019
Reitit - Clojure/North 2019Reitit - Clojure/North 2019
Reitit - Clojure/North 2019
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and Spark
 
Java 8
Java 8Java 8
Java 8
 
Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Writing Docker monitoring agent with Go

  • 2. About me • Naoki Ainoya( ainoya) • iOS(new!)/Server/Infra engineer • Swift/Scala/Go/Docker • Recruit Marketing Partners Co, Ltd.
  • 3. A tiny deployment pipeline tool Written in Go walter-cd/walter Open source project
  • 4. Introduction of Fune • An event emitter triggered by Docker Event API • The agent process (fune-agent) communicates with docker daemon via its socket • https://github.com/ainoya/fune Docker daemon Funeagent ConttainerA ConttainerB ConttainerC Nginx/Redis vulcand(etcd) Slack notification etc.. Listens docker events API notifies each containers are created/died/stopped/started Emits pluggable actions Your arbitrary docker ecosystem ECS/k8s/fleet/etc.. Docker Host Deploy containers
  • 5. Overview of Fune • Docker Events API provides a lifecycle of container as JSON format • create/start/die/stop
  • 6. Overview of Fune fune-agent listens these events Docker daemon Funeagent ConttainerA ConttainerB ConttainerC Listens docker events API notifies each containers are created/died/stopped/started Your arbitrary docker ecosystem ECS/k8s/fleet/etc.. Docker Host Deploy containers
  • 7. Overview of Fune fune-agent emits Action
 when received Docker events
 from event Docker daemon Funeagent ConttainerA ConttainerB Nginx/Redis vulcand(etcd) Slack notification etc.. Listens docker events API notifies each containers are created/died/stopped/started Emits pluggable actions Your arbitrary docker ecosystem ECS/k8s/fleet/etc.. Docker Host Deploy containers
  • 8. Overview of Fune Docker daemon Funeagent ConttainerA ConttainerB Nginx/Redis vulcand(etcd) Slack notification etc.. Listens docker events API notifies each containers are created/died/stopped/started Emits pluggable actions Your arbitrary docker ecosystem ECS/k8s/fleet/etc.. Docker Host Deploy containers • Action, for example; • Set/Del a container information to Redis as FQDN/IP:Port pair for proxy • Slack notification • More details are next time :)
  • 9. Today I talk about: • Some tips I learned with writing fune • Studied a lot of stuffs from coreos/etcd
  • 10. Setup project • Standard structure for 
 working with Godeps correctly • /src/github.com/ainoya/fune ./${GOPATH}/src !"" 9fans.net #   %"" go !"" code.google.com #   %"" p !"" github.com #   !"" ainoya/fune #   !"" barakmich #   !"" coreos etc...
  • 11. Godeps for the package dependencies • Using Godeps once, all dependencies copied into directory and rewrite import statement • Then you need Godeps command only if package dependency is added import "github.com/fsouza/go-dockerclient" // after `Godep save -r ./…` import "github.com/ainoya/fune/Godeps/_workspace/ src/github.com/fsouza/go-dockerclient"
  • 12. Godeps for the package dependencies • All dependencies are included in git repos • But it makes dirty commit log!! • Keep off its dirtiness by split commits :)
  • 13. How about vendor feature in go1.5? • go1.5 vendor feature have some problems yet • ex) go  tool  "./…" doesn't works well • https://github.com/golang/go/issues/11659 • See also ) http://deeeet.com/writing/2015/06/26/golang-dependency- vendoring/
  • 14. Write tests • Rerun automatically if files are changed • rerun is awesome! (but ruby tool gem) rerun -x -c -d directory1, directory2,... —pattern '**/*.{go}' -- go test ./...
  • 15. Be careful about race condition • Test with "-­‐race" option if you often use goroutine in your code • "-­‐cpu  N" option may reveal race condition you didn't expected • I use "go  test  ./…  -­‐race  -­‐cpu  1,2,4" inside test script WARNING: DATA RACE Write by goroutine 8: sync.raceWrite() /usr/local/Cellar/go/1.5/libexec/src/sync/race.go:41 +0x2e sync.(*WaitGroup).Wait() /usr/local/Cellar/go/1.5/libexec/src/sync/waitgroup.go:124 +0xf9 github.com/ainoya/fune/emitter.TestBroadCast() /Users/ainoya/.go/src/github.com/ainoya/fune/gopath/src/github.com/ ainoya/fune/emitter/emitter_test.go:57 +0x444 testing.tRunner() /usr/local/Cellar/go/1.5/libexec/src/testing/testing.go:456 +0xdc
  • 16. Is Go1.5 compilation time slower than 1.4? • "go  test" obviously takes time much longer • It's probably because of GoGo compiler performance
 Ref) Performance section of https://golang.org/doc/go1.5 • It should be improved with Go1.6
  • 17. Channel tips • coreos/etcd implements a shutdown feature with using close(channel) type  Server  struct  {     name        string     channel  chan  struct{}     done        chan  struct{}     stop        chan  struct{}   }   func  main()  {     done  :=  make(chan  struct{})     stop  :=  make(chan  struct{})     s  :=  &Server{done:  done,  stop:  stop,   hoge:  hoge}     go  s.run()     s.channel  <-­‐  struct{}{}     osutil.RegisterInterrputHandler(s.Stop)     <-­‐s.done   } func  (s  *Server)  run()  {     defer  func()  {  close(s.done)  }()     for  {       select  {       case  <-­‐s.channel:         fmt.Println("do  something")       case  <-­‐s.stop:         return       }     }   }   func  (s  *S)  Stop()  {     select  {     case  s.stop  <-­‐  struct{}{}:     case  <-­‐s.done:       return     }     <-­‐s.done   }  
  • 18. Channel tips • coreos/etcd implements a shutdown feature with using close(channel) type  Server  struct  {     name        string     channel  chan  struct{}     done        chan  struct{}     stop        chan  struct{}   }   func  main()  {     done  :=  make(chan  struct{})     stop  :=  make(chan  struct{})     s  :=  &Server{done:  done,  stop:  stop,   hoge:  hoge}     go  s.run()     s.channel  <-­‐  struct{}{}     osutil.RegisterInterrputHandler(s.Stop)     <-­‐s.done   } func  (s  *Server)  run()  {     defer  func()  {  close(s.done)  }()     for  {       select  {       case  <-­‐s.channel:         fmt.Println("do  something")       case  <-­‐s.stop:         return       }     }   }   func  (s  *S)  Stop()  {     select  {     case  s.stop  <-­‐  struct{}{}:     case  <-­‐s.done:       return     }     <-­‐s.done   }  
  • 19. Channel tips • coreos/etcd implements a shutdown feature with using close(channel) type  Server  struct  {     name        string     channel  chan  struct{}     done        chan  struct{}     stop        chan  struct{}   }   func  main()  {     done  :=  make(chan  struct{})     stop  :=  make(chan  struct{})     s  :=  &Server{done:  done,  stop:  stop,   hoge:  hoge}     go  s.run()     s.channel  <-­‐  struct{}{}     osutil.RegisterInterrputHandler(s.stop)     <-­‐s.done   } func  (s  *Server)  run()  {     defer  func()  {  close(s.done)  }()     for  {       select  {       case  <-­‐s.channel:         fmt.Println("do  something")       case  <-­‐s.stop:         return       }     }   }   func  (s  *S)  Stop()  {     select  {     case  s.stop  <-­‐  struct{}{}:     case  <-­‐s.done:       return     }     <-­‐s.done   }  
  • 20. Channel tips • coreos/etcd implements a shutdown feature with using close(channel) type  Server  struct  {     name        string     channel  chan  struct{}     done        chan  struct{}     stop        chan  struct{}   }   func  main()  {     done  :=  make(chan  struct{})     stop  :=  make(chan  struct{})     s  :=  &Server{done:  done,  stop:  stop,   hoge:  hoge}     go  s.run()     s.channel  <-­‐  struct{}{}     osutil.RegisterInterrputHandler(s.Stop)     <-­‐s.done   } func  (s  *Server)  run()  {     defer  func()  {  close(s.done)  }()     for  {       select  {       case  <-­‐s.channel:         fmt.Println("do  something")       case  <-­‐s.stop:         return       }     }   }   func  (s  *S)  Stop()  {     select  {     case  s.stop  <-­‐  struct{}{}:     case  <-­‐s.done:       return     }     <-­‐s.done   }  
  • 21. Channel tips • coreos/etcd implements a shutdown feature with using close(channel) type  Server  struct  {     name        string     channel  chan  struct{}     done        chan  struct{}     stop        chan  struct{}   }   func  main()  {     done  :=  make(chan  struct{})     stop  :=  make(chan  struct{})     s  :=  &Server{done:  done,  stop:  stop,   hoge:  hoge}     go  s.run()     s.channel  <-­‐  struct{}{}     osutil.RegisterInterrputHandler(s.Stop)     <-­‐s.done   } func  (s  *Server)  run()  {     defer  func()  {  close(s.done)  }()     for  {       select  {       case  <-­‐s.channel:         fmt.Println("do  something")       case  <-­‐s.stop:         return       }     }   }   func  (s  *S)  Stop()  {     select  {     case  s.stop  <-­‐  struct{}{}:     case  <-­‐s.done:       return     }     <-­‐s.done   }  
  • 22. Test goroutine easily "s.done" channel makes testing goroutine easily //  https://github.com/coreos/etcd/blob/master/etcdserver/ server_test.go#L1031   //  TestPublishRetry  tests  that  publish  will  keep  retry  until  success.   func  TestPublishRetry(t  *testing.T)  {     n  :=  &nodeRecorder{}     srv  :=  &EtcdServer{       cfg:            &ServerConfig{TickMs:  1},       r:                raftNode{Node:  n},       w:                &waitRecorder{},       done:          make(chan  struct{}),       reqIDGen:  idutil.NewGenerator(0,  time.Time{}),     }     time.AfterFunc(500*time.Microsecond,  func()  {  close(srv.done)  })     srv.publish(10  *  time.Nanosecond)  
  • 23. Run go as Docker container • Go single binary with "SCRATCH" • You can run a go stuff inside extremely simple container! FROM  scratch   EXPOSE  8080   COPY  your-­‐golang-­‐app  /app/your-­‐golang-­‐app   ENV  PATH=/app:$PATH   ENTRYPOINT  ["/app/your-­‐golang-­‐app"]   CMD  ["-­‐some-­‐option=haha"]
  • 24. Round up • Learned a lot of stuffs from well-knowned products (coreos/etcd) • project structure, test, golang-way
  • 25. See you next kyobashi.*! • 9/7: kyobashi.dex • 9/16: potatotips • ???: kyobashi.???