diff --git a/Makefile b/Makefile index 7d7335ae8d7..c00c7accecd 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ GOTEST_OPT?= -race -timeout 30s GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic GOTEST=go test GOFMT=gofmt +GOIMPORTS=goimports GOLINT=golint GOVET=go vet GOOS=$(shell go env GOOS) @@ -32,8 +33,8 @@ all-srcs: .DEFAULT_GOAL := addlicense-fmt-vet-lint-test -.PHONY: addlicense-fmt-vet-lint-test -addlicense-fmt-vet-lint-test: addlicense fmt vet lint test +.PHONY: addlicense-fmt-vet-lint-goimports-test +addlicense-fmt-vet-lint-goimports-test: addlicense fmt vet lint goimports test .PHONY: e2e-test e2e-test: otelsvc @@ -44,7 +45,7 @@ test: $(GOTEST) $(GOTEST_OPT) $(ALL_PKGS) .PHONY: travis-ci -travis-ci: fmt vet lint test-with-cover otelsvc +travis-ci: fmt vet lint goimports test-with-cover otelsvc $(MAKE) -C testbed install-tools $(MAKE) -C testbed runtests @@ -90,6 +91,17 @@ lint: echo "Lint finished successfully"; \ fi +.PHONY: goimports +goimports: + @IMPORTSOUT=`$(GOIMPORTS) -l . 2>&1`; \ + if [ "$$IMPORTSOUT" ]; then \ + echo "$(GOIMPORTS) FAILED => fix the import order in the following files:\n"; \ + echo "$$IMPORTSOUT\n"; \ + exit 1; \ + else \ + echo "Goimports finished successfully"; \ + fi + .PHONY: vet vet: @$(GOVET) ./... @@ -97,8 +109,10 @@ vet: .PHONY: install-tools install-tools: - GO111MODULE=on go install github.com/google/addlicense - GO111MODULE=on go install golang.org/x/lint/golint + GO111MODULE=on go install \ + github.com/google/addlicense \ + golang.org/x/lint/golint \ + golang.org/x/tools/cmd/goimports .PHONY: otelsvc otelsvc: diff --git a/internal/tools.go b/internal/tools.go index ed803ce866f..aed724a39b8 100644 --- a/internal/tools.go +++ b/internal/tools.go @@ -26,4 +26,5 @@ import ( _ "github.com/google/addlicense" _ "github.com/jstemmer/go-junit-report" _ "golang.org/x/lint/golint" + _ "golang.org/x/tools/cmd/goimports" ) diff --git a/receiver/prometheusreceiver/internal/metadata.go b/receiver/prometheusreceiver/internal/metadata.go index ba362e8f728..09529d04b6c 100644 --- a/receiver/prometheusreceiver/internal/metadata.go +++ b/receiver/prometheusreceiver/internal/metadata.go @@ -16,6 +16,7 @@ package internal import ( "errors" + "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/scrape" diff --git a/receiver/prometheusreceiver/internal/metricsbuilder.go b/receiver/prometheusreceiver/internal/metricsbuilder.go index c2d962e58ef..ebd2339ed52 100644 --- a/receiver/prometheusreceiver/internal/metricsbuilder.go +++ b/receiver/prometheusreceiver/internal/metricsbuilder.go @@ -17,8 +17,6 @@ package internal import ( "errors" "fmt" - "github.com/golang/protobuf/ptypes/wrappers" - "go.uber.org/zap" "sort" "strconv" "strings" @@ -26,11 +24,14 @@ import ( commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1" "github.com/golang/protobuf/ptypes/timestamp" - "github.com/open-telemetry/opentelemetry-service/consumer/consumerdata" + "github.com/golang/protobuf/ptypes/wrappers" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/textparse" "github.com/prometheus/prometheus/scrape" + "go.uber.org/zap" + + "github.com/open-telemetry/opentelemetry-service/consumer/consumerdata" ) const metricsSuffixCount = "_count" diff --git a/receiver/prometheusreceiver/internal/metricsbuilder_test.go b/receiver/prometheusreceiver/internal/metricsbuilder_test.go index 8ae4e83c88d..ff65bb27a4d 100644 --- a/receiver/prometheusreceiver/internal/metricsbuilder_test.go +++ b/receiver/prometheusreceiver/internal/metricsbuilder_test.go @@ -15,17 +15,18 @@ package internal import ( - "github.com/golang/protobuf/ptypes/wrappers" "reflect" "testing" commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1" - "github.com/open-telemetry/opentelemetry-service/exporter/exportertest" + "github.com/golang/protobuf/ptypes/wrappers" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/textparse" "github.com/prometheus/prometheus/scrape" + + "github.com/open-telemetry/opentelemetry-service/exporter/exportertest" ) func Test_isUsefulLabel(t *testing.T) { diff --git a/receiver/prometheusreceiver/internal/ocastore.go b/receiver/prometheusreceiver/internal/ocastore.go index 47db09791d6..1260ed49b4b 100644 --- a/receiver/prometheusreceiver/internal/ocastore.go +++ b/receiver/prometheusreceiver/internal/ocastore.go @@ -17,14 +17,16 @@ package internal import ( "context" "errors" - "github.com/open-telemetry/opentelemetry-service/consumer" + "io" + "sync" + "sync/atomic" + "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" "go.uber.org/zap" - "io" - "sync" - "sync/atomic" + + "github.com/open-telemetry/opentelemetry-service/consumer" ) const ( diff --git a/receiver/prometheusreceiver/internal/ocastore_test.go b/receiver/prometheusreceiver/internal/ocastore_test.go index 9647fdbd019..feafd3834ca 100644 --- a/receiver/prometheusreceiver/internal/ocastore_test.go +++ b/receiver/prometheusreceiver/internal/ocastore_test.go @@ -17,9 +17,6 @@ package internal import ( "context" "fmt" - "github.com/go-kit/kit/log" - "github.com/open-telemetry/opentelemetry-service/consumer/consumerdata" - "github.com/prometheus/prometheus/discovery" "net/http" "net/http/httptest" "net/url" @@ -28,9 +25,13 @@ import ( "time" metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1" + "github.com/go-kit/kit/log" "github.com/prometheus/prometheus/config" sd_config "github.com/prometheus/prometheus/discovery/config" "github.com/prometheus/prometheus/scrape" + + "github.com/open-telemetry/opentelemetry-service/consumer/consumerdata" + "github.com/prometheus/prometheus/discovery" ) func TestOcaStore(t *testing.T) { diff --git a/receiver/prometheusreceiver/internal/transaction.go b/receiver/prometheusreceiver/internal/transaction.go index 0c83350a218..ca46fb284de 100644 --- a/receiver/prometheusreceiver/internal/transaction.go +++ b/receiver/prometheusreceiver/internal/transaction.go @@ -17,14 +17,16 @@ package internal import ( "context" "errors" + "strings" + "sync/atomic" + commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" - "github.com/open-telemetry/opentelemetry-service/consumer" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/storage" "go.uber.org/zap" - "strings" - "sync/atomic" + + "github.com/open-telemetry/opentelemetry-service/consumer" ) const ( diff --git a/receiver/prometheusreceiver/internal/transaction_test.go b/receiver/prometheusreceiver/internal/transaction_test.go index 40a7e5aea9f..4cdd0911e8a 100644 --- a/receiver/prometheusreceiver/internal/transaction_test.go +++ b/receiver/prometheusreceiver/internal/transaction_test.go @@ -16,11 +16,12 @@ package internal import ( "context" - "github.com/prometheus/prometheus/pkg/labels" - "github.com/prometheus/prometheus/scrape" "reflect" "testing" "time" + + "github.com/prometheus/prometheus/pkg/labels" + "github.com/prometheus/prometheus/scrape" ) func Test_transaction(t *testing.T) { diff --git a/service/builder/builder.go b/service/builder/builder.go index ece0e4bd278..d13339b9169 100644 --- a/service/builder/builder.go +++ b/service/builder/builder.go @@ -19,6 +19,7 @@ package builder import ( "flag" "fmt" + "github.com/spf13/viper" )