Compile Time Code Weaving in Go. Large Systems Debugging, Profiling / Ian Eyberg (DeferPanic)

Post on 18-Jan-2017

434 views 0 download

transcript

Compile Time Code Weaving with Go

https://github.com/deferpanic/goweave

I like your software but…

What sucks about Go?

Do you know about AspectJ?

Really?

I’m not a code purist

“Which is our full time job. Write a program to write

a program”- rob pike / gopherfest 2015

Go is Actually a Decent Fit

Prior Artgo fmtgo fix

go generate

go fix

No WrappingNo code residue

Non-trivial amount of work

Regex/Sed Doesn’t Work

scopemany

packagesmany refs

Aspect Oriented Programming

Cross-Cutting Concern

Contains behavior that is prominent in many places but don’t really have anything to do with your business logic.

Logging is a canonical example

logging.Error.Println(“got here”)

logging.Error.Println(“got here”)

logging.Error.Println(“got here”)

Pointcut

an expression that details where to apply your behavior

like a regex but on the ast

Advice

fmt.Println("Hello, 世界 ")

Aspect

the combination of a pointcut and advice

Sample PointCuts

Call

Before, after or wrap around calling a function.

func blah() { some.stuff()}

func blah() { fmt.Println(“before”) some.stuff()}

before

after

Execute

Before or after inside executing a method.

func blah() { stuff()}

func stuff() {}

before

afterfunc blah() { stuff()}

func stuff() { fmt.Println(“stuff”)}

Within

Every single call within a method.

func blah() { beforeEach() slowCall() beforeEach() fastcall() }

before

after

func blah() { slowCall() fastcall() }

get

Before or After Every Get to a Variable

before

after

func blah() { x := “stuff” fmt.Println(x)}

func blah() { x := “stuff” fmt.Println(“before getting x”) fmt.Println(x)}

set

Before or After Every Set to a Variable

before

after

func blah() { x := “stuff” fmt.Println(x)}

func blah() { fmt.Println(“before setting x”) x := “stuff” fmt.Println(x)}

declaration

Before or After Every Variable Declaration

before

after

func blah() { ch := make(chan int, 2) ch <- 1}

func blah() { fmt.Println(“before make”) ch := make(chan int, 2) ch <- 1}

Logging

Monitoring

Performance Analysis

Debugging & Tracing

Undo Functionality

Behavior Mutation

Security

Transactions

Log every call to Itoa

Validation

Time Database Query Latencies

Ensure we log every panic in a goroutine

the loom

central repository for storing .weave files

https://github.com/deferpanic/goweave

https://github.com/deferpanic/loom