Skip to content

Commit

Permalink
Migrate from internal repostory
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri Shkuro committed May 20, 2016
1 parent 1f3b1ab commit e1f1c0c
Show file tree
Hide file tree
Showing 95 changed files with 12,715 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.out
*.test
*.xml
*.swp
.idea/
.tmp/
*.iml
*.cov
*.html
gen/thrift/js
gen/thrift/py
vendor/
crossdock-main
51 changes: 51 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
sudo: required

language: go

go:
- 1.5
- 1.6

services:
- docker

env:
global:
- DOCKER_VERSION=1.10.1-0~trusty
- DOCKER_COMPOSE_VERSION=1.6.0
- GO15VENDOREXPERIMENT=1
- COMMIT=${TRAVIS_COMMIT::8}
- secure: rZOVU0zQTkPvaG43IIt/guPoq3EAE6/So/+elGcmHF14PsfPcPQ6MyexqdwRkVPd/fAuNwiXXwTXHkjI8ECYz5LF+m+g2VwvrhE9H1wfLuGbtgXSSXqB+dqylHGUz4ksm4q1gwiet8fpVHlNfbSfu+lhTpbl4+SUfFK+s9LqnAKbm+Hi8vKzyhGhvlTngi0Y2O4Z2FLUgU2fkUm5fesdUyW0H2/Bn5KRqJRtcyTmmj4eD/qMq5WDe8n5Sy9J+kuCpweC8vBZQzAGuPpGdj8jvbPCO+N2xM26Y7DNKMsgj6IU49D6sbmLvyVMbI1pBeAQ54TCJx5LySuZpLAzyaaqHEDwOs4+cRolZSQwpd7Q8/wOxZ13KqMhYOokBIcDlLs0yB9J3KOTS1lxU8YC6A3j+Wenw9/JjL0sXSSeOAvNkAeVtEu3dqXg326HJjzXgIQbci83TTtWv4MsQKIXMADOgMnQdgd4JRaGyfxM2hswsE2/Y5OlyXqrqtFHvgKy6MpLTB26r3aRA22VY6p5hFhuEGLClbHidyeHgkNI2iHOXZqoEdmno33Eq7WicH64bezmq+Z4nwyjBOLTblcG7V79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Ks1TTZOqV1NVt7VJ887NPe4fLIxP1/jQLzsh6kShTcctLszc70NgrowdwhdIqN/3TUmxkVbGP2JzbQ4yR6LVKCDDeWpKGiPsIKy75kEiW4ZlEZhnwCOKaR94FyBy1HEnhyoD9OJD6Gq/u4UdEw/QuNfE89gbr47LA4z487AzYGzH+1J3MlEbTNgTCmWduC0ghTx33vItrYMXXabGDe7XwfdJKTnMjfXVv+CVBdMAZVtDL27sEmbbAzIrRjP+JOFm7ZRYfzvxu5vCWlB/3wMMt7DzcutjxR4tyYs71Ec5zdUH/16wSvjQR1laJZCujlNSA/3FZUizCzW3qFVsBkaWRF+/C/cksi6cR83xIrc4y4WRLttAcbfqmsXaigL5Iz4GbLg62vmFP88=

before_install:
- apt-cache madison docker-engine
- sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION}
- docker version
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- docker-compose version

install:
- make install_ci

script:
- make test_ci
- echo SKIPPING travis_retry goveralls -coverprofile=cover.out -service=travis-ci
- make crossdock
- timeout 5 docker-compose logs || true

after_success:
- export REPO=uber/jaeger-client-go
- export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi)
- export TAG=`if [ "$BRANCH" == "master" ]; then echo "latest"; else echo $BRANCH; fi`
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, REPO=$REPO, PR=$PR, BRANCH=$BRANCH, TAG=$TAG"
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker build -f Dockerfile -t $REPO:$COMMIT .
- docker tag $REPO:$COMMIT $REPO:$TAG
- docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER
- docker push $REPO
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM golang
ADD crossdock/crossdock /
CMD ["/crossdock"]
EXPOSE 8080-8082
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Uber Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
PACKAGES := $(shell glide novendor | grep -v ./thrift/...)

export GO15VENDOREXPERIMENT=1

GOTEST=go test -v
GOLINT=golint
GOVET=go vet
GOFMT=go fmt


.PHONY: test
test:
$(GOTEST) $(PACKAGES)


.PHONY: fmt
fmt:
$(GOFMT) $(PACKAGES)


.PHONY: lint
lint:
$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift || true;)
$(GOVET) $(PACKAGES)


.PHONY: install
install:
glide --version || go get github.com/Masterminds/glide
glide install


.PHONY: cover
cover:
./scripts/cover.sh $(shell go list $(PACKAGES))
go tool cover -html=cover.out -o cover.html


# This is not part of the regular test target because we don't want to slow it
# down.
.PHONY: test-examples
test-examples:
make -C examples


.PHONY: bins
bins:
CGO_ENABLED=0 GOOS=linux time go build -a -installsuffix cgo -o crossdock/crossdock ./crossdock


.PHONY: crossdock
crossdock: bins
docker-compose kill go
docker-compose rm -f go
docker-compose build go
docker-compose run crossdock


.PHONY: crossdock-fresh
crossdock-fresh: bins
docker-compose kill
docker-compose rm --force
docker-compose pull
docker-compose build
docker-compose run crossdock


.PHONY: install_ci
install_ci: install
go get github.com/wadey/gocovmerge
go get github.com/mattn/goveralls
go get golang.org/x/tools/cmd/cover


.PHONY: test_ci
test_ci:
@./scripts/cover.sh $(shell go list $(PACKAGES))
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# jaeger-client-go

215 changes: 215 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Copyright (c) 2016 Uber Technologies, Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package config

import (
"errors"
"fmt"
"io"
"time"

"github.com/opentracing/opentracing-go"

"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/transport"
"github.com/uber/jaeger-client-go/transport/udp"
)

// Configuration configures and creates Jaeger Tracer
type Configuration struct {
Disabled bool `yaml:"disabled"`
Sampler *SamplerConfig `yaml:"sampler"`
Reporter *ReporterConfig `yaml:"reporter"`

// Logger can be provided to log Reporter errors, as well as to log spans
// if Reporter.LogSpans is set to true. This cannot be specified in
// the configuration file, it must be specified in code.
Logger jaeger.Logger `yaml:"-"`
}

// SamplerConfig allows initializing a non-default sampler. All fields are optional.
type SamplerConfig struct {
// Type specifies the type of the sampler: const, probabilistic, rateLimiting, or remote
Type string `yaml:"type"`

// Param is a value passed to the sampler.
// Valid values for Param field are:
// - for "const" sampler, 0 or 1 for always false/true respectively
// - for "probabilistic" sampler, a probability between 0 and 1
// - for "rateLimiting" sampler, the number of spans per second
// - for "remote" sampler, param is the same as for "probabilistic"
// and indicates the initial sampling rate before the actual one
// is received from the mothership
Param float64 `yaml:"param"`

// LocalAgentHostPort is the address of jaeger-agent's HTTP server
LocalAgentHostPort string `yaml:"localAgentHostPort"`
}

// ReporterConfig configures the reporter. All fields are optional.
type ReporterConfig struct {
// QueueSize controls how many spans the reporter can keep in memory before it starts dropping
// new spans. The queue is continuously drained by a background go-routine, as fast as spans
// can be sent out of process.
QueueSize int `yaml:"queueSize"`

// BufferFlushInterval controls how often the buffer is force-flushed, even if it's not full.
// It is generally not useful, as it only matters for very low traffic services.
BufferFlushInterval time.Duration

// LogSpans, when true, enables LoggingReporter that runs in parallel with the main reporter
// and logs all submitted spans. Main Configuration.Logger must be initialized in the code
// for this option to have any effect.
LogSpans bool `yaml:"logSpans"`

// LocalAgentHostPort instructs reporter to send spans to jaeger-agent at this address
LocalAgentHostPort string `yaml:"localAgentHostPort"`
}

type nullCloser struct{}

func (*nullCloser) Close() error { return nil }

// New creates a new Jaeger Tracer, and a closer func that can be used to flush buffers
// before shutdown.
func (c Configuration) New(
serviceName string,
statsReporter jaeger.StatsReporter,
) (opentracing.Tracer, io.Closer, error) {
if c.Disabled {
return &opentracing.NoopTracer{}, &nullCloser{}, nil
}
if serviceName == "" {
return nil, nil, errors.New("no service name provided")
}
if c.Sampler == nil {
c.Sampler = &SamplerConfig{Type: samplerTypeProbabilistic, Param: 0.01}
}
if c.Reporter == nil {
c.Reporter = &ReporterConfig{}
}

metrics := jaeger.NewMetrics(statsReporter, nil)

sampler, err := c.Sampler.NewSampler(serviceName, metrics)
if err != nil {
return nil, nil, err
}

reporter, err := c.Reporter.NewReporter(serviceName, metrics, c.Logger)
if err != nil {
return nil, nil, err
}

tracer, closer := jaeger.NewTracer(
serviceName,
sampler,
reporter,
jaeger.TracerOptions.Metrics(metrics))

return tracer, closer, nil
}

// InitGlobalTracer creates a new Jaeger Tracer, and sets is as global OpenTracing Tracer.
// It returns a closer func that can be used to flush buffers before shutdown.
func (c Configuration) InitGlobalTracer(
serviceName string,
statsReporter jaeger.StatsReporter,
) (io.Closer, error) {
if c.Disabled {
return &nullCloser{}, nil
}
tracer, closer, err := c.New(serviceName, statsReporter)
if err != nil {
return nil, err
}
opentracing.InitGlobalTracer(tracer)
return closer, nil
}

const (
samplerTypeConst = "const"
samplerTypeRemote = "remote"
samplerTypeProbabilistic = "probabilistic"
samplerTypeRateLimiting = "rateLimiting"
)

// NewSampler creates a new sampler based on the configuration
func (sc *SamplerConfig) NewSampler(
serviceName string,
metrics *jaeger.Metrics,
) (jaeger.Sampler, error) {
if sc.Type == samplerTypeConst {
return jaeger.NewConstSampler(sc.Param != 0), nil
}
if sc.Type == samplerTypeProbabilistic {
if sc.Param >= 0 && sc.Param <= 1.0 {
return jaeger.NewProbabilisticSampler(sc.Param)
}
return nil, fmt.Errorf(
"Invalid Param for probabilistic sampler: %v. Expecting value between 0 and 1",
sc.Param,
)
}
if sc.Type == samplerTypeRateLimiting {
return jaeger.NewRateLimitingSampler(sc.Param)
}
if sc.Type == samplerTypeRemote || sc.Type == "" {
sc2 := *sc
sc2.Type = samplerTypeProbabilistic
initSampler, err := sc2.NewSampler(serviceName, nil)
if err != nil {
return nil, err
}
return jaeger.NewRemotelyControlledSampler(serviceName, initSampler,
sc.LocalAgentHostPort, metrics, jaeger.NullLogger), nil
}
return nil, fmt.Errorf("Unknown sampler type %v", sc.Type)
}

// NewReporter instantiates a new reporter that submits spans to tcollector
func (rc *ReporterConfig) NewReporter(
serviceName string,
metrics *jaeger.Metrics,
logger jaeger.Logger,
) (jaeger.Reporter, error) {
sender, err := rc.newTransport()
if err != nil {
return nil, err
}

reporter := jaeger.NewRemoteReporter(
sender,
&jaeger.ReporterOptions{
QueueSize: rc.QueueSize,
BufferFlushInterval: rc.BufferFlushInterval,
Logger: logger,
Metrics: metrics})
if rc.LogSpans && logger != nil {
logger.Infof("Initializing logging reporter\n")
reporter = jaeger.NewCompositeReporter(jaeger.NewLoggingReporter(logger), reporter)
}
return reporter, err
}

func (rc *ReporterConfig) newTransport() (transport.Transport, error) {
return udp.NewUDPTransport(rc.LocalAgentHostPort, 0)
}
Loading

0 comments on commit e1f1c0c

Please sign in to comment.