From 39cbd1545304d16266f7ab9fe8134f4940d627c4 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:12:05 -0500 Subject: [PATCH 1/8] Add travis build and coverage --- .gitignore | 4 +++ .travis | 13 +++++++ Makefile | 68 ++++++++++++++++++++++++++++++++++++ cmd/agent/.nocover | 0 cmd/agent/main.go | 5 +++ glide.lock | 10 ++++++ glide.yaml | 1 + scripts/cover.sh | 60 +++++++++++++++++++++++++++++++ services/agent/agent.go | 24 +++++++++++++ services/agent/agent_test.go | 11 ++++++ 10 files changed, 196 insertions(+) create mode 100644 .travis create mode 100644 Makefile create mode 100644 cmd/agent/.nocover create mode 100644 cmd/agent/main.go create mode 100644 glide.lock create mode 100755 scripts/cover.sh create mode 100644 services/agent/agent.go create mode 100644 services/agent/agent_test.go diff --git a/.gitignore b/.gitignore index f0e0c9f93f7..698f0e20498 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,12 @@ *.test *.xml *.swp +fmt.log +lint.log +cover.html .idea/ .tmp/ _site/ env/ Gemfile.lock +vendor/ diff --git a/.travis b/.travis new file mode 100644 index 00000000000..52cfa46da23 --- /dev/null +++ b/.travis @@ -0,0 +1,13 @@ +sudo: required + +language: go + +go: + - 1.7 + +install: + - make install_ci + +script: + - make test_ci + diff --git a/Makefile b/Makefile new file mode 100644 index 00000000000..af4f4311061 --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +PROJECT_ROOT=github.com/uber/jaeger +PACKAGES := $(shell glide novendor | grep -v ./thrift-gen/...) + +# all .go files that don't exist in hidden directories +ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen \ + -e ".*/\..*" \ + -e ".*/_.*" \ + -e ".*/mocks.*") + +export GO15VENDOREXPERIMENT=1 + +RACE=-race +GOTEST=go test -v $(RACE) +GOLINT=golint +GOVET=go vet +GOFMT=gofmt +FMT_LOG=fmt.log +LINT_LOG=lint.log + +PASS=$(shell printf "\033[32mPASS\033[0m") +FAIL=$(shell printf "\033[31mFAIL\033[0m") +COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/'' + +.DEFAULT_GOAL := test-and-lint + +.PHONY: test-and-lint +test-and-lint: test fmt lint + +.PHONY: test +test: + $(GOTEST) $(PACKAGES) | $(COLORIZE) + +.PHONY: fmt +fmt: + $(GOFMT) -e -s -l -w $(ALL_SRC) + +.PHONY: lint +lint: + $(GOVET) $(PACKAGES) + @cat /dev/null > $(LINT_LOG) + @$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift >> $(LINT_LOG) || true;) + @[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false) + @$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG) + @[ ! -s "$(FMT_LOG)" ] || (echo "Go Fmt Failures, run 'make fmt'" | cat - $(FMT_LOG) && false) + +.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 + +.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 + go get github.com/golang/lint/golint + + +.PHONY: test_ci +test_ci: + @./scripts/cover.sh $(shell go list $(PACKAGES)) + make lint + diff --git a/cmd/agent/.nocover b/cmd/agent/.nocover new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cmd/agent/main.go b/cmd/agent/main.go new file mode 100644 index 00000000000..ac2fa31864a --- /dev/null +++ b/cmd/agent/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + println("jaeger-agent") +} diff --git a/glide.lock b/glide.lock new file mode 100644 index 00000000000..39560fc11ee --- /dev/null +++ b/glide.lock @@ -0,0 +1,10 @@ +hash: 4991ad16cc808453448bce6a0bababfb7fb73627d4cb4416187f80b33fce9c83 +updated: 2016-11-07T19:46:26.519447717-05:00 +imports: +- name: github.com/uber-go/atomic + version: 0c9e689d64f004564b79d9a663634756df322902 +- name: github.com/uber-go/zap + version: c4939d1166b2220bb45338e21506623b4bbdec50 +- name: github.com/uber/jaeger-lib + version: 7b113fceac673e60e5b10dff7039787bab5c5ed7 +testImports: [] diff --git a/glide.yaml b/glide.yaml index 1f3c256e099..7d9a0864956 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,3 +1,4 @@ package: github.com/uber/jaeger import: - package: github.com/uber/jaeger-lib +- package: github.com/uber-go/zap diff --git a/scripts/cover.sh b/scripts/cover.sh new file mode 100755 index 00000000000..d94bd4257a8 --- /dev/null +++ b/scripts/cover.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +set -e + +COVER=.cover +ROOT_PKG=github.com/uber/jaeger/ + +if [[ -d "$COVER" ]]; then + rm -rf "$COVER" +fi +mkdir -p "$COVER" + +# If a package directory has a .nocover file, don't count it when calculating +# coverage. +filter="" +for pkg in "$@"; do + if [[ -f "$GOPATH/src/$pkg/.nocover" ]]; then + if [[ -n "$filter" ]]; then + filter="$filter, " + fi + filter="\"$pkg\": true" + fi +done + +i=0 +for pkg in "$@"; do + i=$((i + 1)) + + extracoverpkg="" + if [[ -f "$GOPATH/src/$pkg/.extra-coverpkg" ]]; then + extracoverpkg=$( \ + sed -e "s|^|$pkg/|g" < "$GOPATH/src/$pkg/.extra-coverpkg" \ + | tr '\n' ',') + fi + + coverpkg=$(go list -json "$pkg" | jq -r ' + .Deps + | . + ["'"$pkg"'"] + | map + ( select(startswith("'"$ROOT_PKG"'")) + | select(contains("/vendor/") | not) + | select(in({'"$filter"'}) | not) + ) + | join(",") + ') + if [[ -n "$extracoverpkg" ]]; then + coverpkg="$extracoverpkg$coverpkg" + fi + + if [[ -z "$coverpkg" ]]; then + continue + fi + + args="-coverprofile $COVER/cover.${i}.out" # -coverpkg $coverpkg + + echo go test -race "$pkg" + go test $args -race "$pkg" +done + +gocovmerge "$COVER"/*.out > cover.out diff --git a/services/agent/agent.go b/services/agent/agent.go new file mode 100644 index 00000000000..351ca760eb2 --- /dev/null +++ b/services/agent/agent.go @@ -0,0 +1,24 @@ +package agent + +import ( + "github.com/uber-go/zap" +) + +// Agent is a composition of all services / components +type Agent interface { + // Run starts all services of the Agent + // Run() +} + +type agent struct { + logger zap.Logger +} + +// New creates a new Jaeger Agent +func New( + logger zap.Logger, +) Agent { + return &agent{ + logger: logger, + } +} diff --git a/services/agent/agent_test.go b/services/agent/agent_test.go new file mode 100644 index 00000000000..b34dc0d1e0a --- /dev/null +++ b/services/agent/agent_test.go @@ -0,0 +1,11 @@ +package agent_test + +import ( + "testing" + + "github.com/uber/jaeger/services/agent" +) + +func TestNewAgent(t *testing.T) { + agent.New(nil) +} From 95ab10a3e436834e78abf6ad50ef44d136a4400d Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:13:14 -0500 Subject: [PATCH 2/8] Fix travis file name --- .travis => .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis => .travis.yml (100%) diff --git a/.travis b/.travis.yml similarity index 100% rename from .travis rename to .travis.yml From 86ba6179e4280d8cf282f65bcbe137026ed54ed6 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:19:32 -0500 Subject: [PATCH 3/8] Ensure latest version of jq --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 52cfa46da23..5288d31cabb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ language: go go: - 1.7 +before_install: + - sudo apt-get -qq update + - sudo apt-get install -y jq + install: - make install_ci From 8e6296a67cfb704111b0e8beef4ea6d6ccf65c97 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:22:15 -0500 Subject: [PATCH 4/8] Log jq version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5288d31cabb..0320309a4fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ go: before_install: - sudo apt-get -qq update - sudo apt-get install -y jq + - jq --version install: - make install_ci From 8a25f7400eeada5934517e0ffe090f32842f7444 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:27:50 -0500 Subject: [PATCH 5/8] Upgrade jq --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0320309a4fd..d52a56a5e61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ go: before_install: - sudo apt-get -qq update - - sudo apt-get install -y jq + - sudo apt-get upgrade -y jq - jq --version install: From e11bbcf92a67651c21fb9881aa12bd5784344c56 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 20:32:25 -0500 Subject: [PATCH 6/8] Select v1.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d52a56a5e61..9bdc760750c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ go: before_install: - sudo apt-get -qq update - - sudo apt-get upgrade -y jq + - sudo apt-get install -y jq=1.5 - jq --version install: From cc62a18b5c73ede1e96cdbaf870cde6c7f0dab93 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 21:50:52 -0500 Subject: [PATCH 7/8] Enable docker --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9bdc760750c..04436ba543e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,13 @@ language: go go: - 1.7 -before_install: - - sudo apt-get -qq update - - sudo apt-get install -y jq=1.5 - - jq --version +services: + - docker + +#before_install: +# - sudo apt-get -qq update +# - sudo apt-get install -y jq-1.5 +# - jq --version install: - make install_ci From ced97ed1ad4721550cf669e7ed3f699dc88005e0 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 7 Nov 2016 21:54:03 -0500 Subject: [PATCH 8/8] Add coverage --- .travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04436ba543e..da7ebdbae1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,14 +8,10 @@ go: services: - docker -#before_install: -# - sudo apt-get -qq update -# - sudo apt-get install -y jq-1.5 -# - jq --version - install: - make install_ci script: - make test_ci + - travis_retry goveralls -coverprofile=cover.out -service=travis-ci || true