Skip to content

Commit

Permalink
Feature: Add OpenTracing (gomods#112)
Browse files Browse the repository at this point in the history
* tracing

* oops
  • Loading branch information
bketelsen authored Mar 26, 2018
1 parent 0a3eb4c commit e76125d
Show file tree
Hide file tree
Showing 305 changed files with 43,027 additions and 960 deletions.
18 changes: 18 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
workspace:
base: /go
path: src/github.com/gomods/athens

pipeline:
ping:
image: mongo:3.0
commands:
- sleep 15
build:
image: golang:1.10
commands:
- go test ./...

services:
mongo:
image: mongo:3.0
command: [ --smallfiles ]
127 changes: 115 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion actions/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func App() *buffalo.App {
if ENV == "development" {
app.Use(middleware.ParameterLogger)
}

initializeTracing(app)
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
// Remove to disable this.
csrfMiddleware := csrf.New
Expand Down
11 changes: 11 additions & 0 deletions actions/home.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package actions

import (
"time"

"github.com/bketelsen/buffet"
"github.com/gobuffalo/buffalo"
)

Expand All @@ -9,5 +12,13 @@ func proxyHomeHandler(c buffalo.Context) error {
}

func homeHandler(c buffalo.Context) error {
slow(c)
return c.Render(200, registry.HTML("index.html"))
}

func slow(c buffalo.Context) {
sp := buffet.ChildSpan("slow", c)
defer sp.Finish()
time.Sleep(1 * time.Millisecond)

}
41 changes: 41 additions & 0 deletions actions/tracing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package actions

import (
"log"
"time"

"github.com/bketelsen/buffet"
"github.com/gobuffalo/buffalo"
opentracing "github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/rpcmetrics"
"github.com/uber/jaeger-lib/metrics/prometheus"
)

func initializeTracing(app *buffalo.App) {
cfg := config.Configuration{
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &config.ReporterConfig{
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
LocalAgentHostPort: "0.0.0.0:6831", //hostPort,
},
}
// TODO(ys) a quick hack to ensure random generators get different seeds, which are based on current time.
time.Sleep(100 * time.Millisecond)
metricsFactory := prometheus.New()
tracer, _, err := cfg.New(
"athens", //serviceName,

config.Observer(rpcmetrics.NewObserver(metricsFactory, rpcmetrics.DefaultNameNormalizer)),
)
if err != nil {
log.Fatal("cannot initialize Jaeger Tracer", err)
}
opentracing.SetGlobalTracer(tracer)
app.Use(buffet.OpenTracing(tracer))

}
42 changes: 27 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
version: '3'
services:
mongo:
image: mongo:3.0.15-wheezy
ports:
- 27017:27017
mysql:
image: bitnami/mysql:5.7.21-r7
ports:
- "3306:3306"
environment:
- "ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_USER=vgp"
- "MYSQL_PASSWORD=vgp"
- "MYSQL_DATABASE=vgoprox"
version: '3'
services:
mongo:
image: mongo:3.0.15-wheezy
ports:
- 27017:27017
mysql:
image: bitnami/mysql:5.7.21-r7
ports:
- "3306:3306"
environment:
- "ALLOW_EMPTY_PASSWORD=yes"
- "MYSQL_USER=vgp"
- "MYSQL_PASSWORD=vgp"
- "MYSQL_DATABASE=vgoprox"
jaeger:
environment:
- COLLECTOR_ZIPKIN_HTTP_PORT=9441
image: jaegertracing/all-in-one:latest
ports:
- 14268:14268
- 9411:9411
- 5775:5775/udp
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
Loading

0 comments on commit e76125d

Please sign in to comment.