Repository: prometheus/common
Pull request #157 (2018-11-16 16:25:53)

*: support Go modules
This also enables additional checks in Travis CI: style, staticcheck and license headers.

brian-brazil: :+1: 

Patch:
diff --git a/.travis.yml b/.travis.yml
index 2fe8e9a..c295cb0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,5 +2,12 @@ sudo: false
 
 language: go
 go:
-  - 1.7.5
-  - tip
+  - 1.7.x
+  - 1.8.x
+  - 1.9.x
+  - 1.10.x
+  - 1.11.x
+
+script:
+  - make test
+  - if [[ $TRAVIS_GO_VERSION =~ ^1\.(11)\. ]]; then make style; fi
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..583ef31
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+# Copyright 2018 The Prometheus Authors
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+include Makefile.common
+
+.PHONY: deps
+deps:
+	@echo ">> getting dependencies"
+	GO111MODULE=$(GO111MODULE) $(GO) get $(GOOPTS) -t ./...
+
+.PHONY: test
+test:: deps check_license unused common-test
+
+ifeq (,$(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(7|8|9)\.'))
+test:: staticcheck
+endif
diff --git a/Makefile.common b/Makefile.common
new file mode 100644
index 0000000..0248fee
--- /dev/null
+++ b/Makefile.common
@@ -0,0 +1,223 @@
+# Copyright 2018 The Prometheus Authors
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# A common Makefile that includes rules to be reused in different prometheus projects.
+# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
+
+# Example usage :
+# Create the main Makefile in the root project directory.
+# include Makefile.common
+# customTarget:
+# 	@echo ">> Running customTarget"
+#
+
+# Ensure GOBIN is not set during build so that promu is installed to the correct path
+unexport GOBIN
+
+GO           ?= go
+GOFMT        ?= $(GO)fmt
+FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
+GOOPTS       ?=
+
+GO_VERSION        ?= $(shell $(GO) version)
+GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
+PRE_GO_111        ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
+
+unexport GOVENDOR
+ifeq (, $(PRE_GO_111))
+	ifneq (,$(wildcard go.mod))
+		# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
+		GO111MODULE := on
+
+		ifneq (,$(wildcard vendor))
+			# Always use the local vendor/ directory to satisfy the dependencies.
+			GOOPTS := $(GOOPTS) -mod=vendor
+		endif
+	endif
+else
+	ifneq (,$(wildcard go.mod))
+		ifneq (,$(wildcard vendor))
+$(warning This repository requires Go >= 1.11 because of Go modules)
+$(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
+		endif
+	else
+		# This repository isn't using Go modules (yet).
+		GOVENDOR := $(FIRST_GOPATH)/bin/govendor
+	endif
+
+	unexport GO111MODULE
+endif
+PROMU        := $(FIRST_GOPATH)/bin/promu
+STATICCHECK  := $(FIRST_GOPATH)/bin/staticcheck
+pkgs          = ./...
+
+GO_VERSION        ?= $(shell $(GO) version)
+GO_BUILD_PLATFORM ?= $(subst /,-,$(lastword $(GO_VERSION)))
+
+PROMU_VERSION ?= 0.2.0
+PROMU_URL     := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
+
+PREFIX                  ?= $(shell pwd)
+BIN_DIR                 ?= $(shell pwd)
+DOCKER_IMAGE_TAG        ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
+DOCKER_REPO             ?= prom
+
+.PHONY: all
+all: precheck style staticcheck unused build test
+
+# This rule is used to forward a target like "build" to "common-build".  This
+# allows a new "build" target to be defined in a Makefile which includes this
+# one and override "common-build" without override warnings.
+%: common-% ;
+
+.PHONY: common-style
+common-style:
+	@echo ">> checking code style"
+	@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
+	if [ -n "$${fmtRes}" ]; then \
+		echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
+		echo "Please ensure you are using $$($(GO) version) for formatting code."; \
+		exit 1; \
+	fi
+
+.PHONY: common-check_license
+common-check_license:
+	@echo ">> checking license header"
+	@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
+               awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
+       done); \
+       if [ -n "$${licRes}" ]; then \
+               echo "license header checking failed:"; echo "$${licRes}"; \
+               exit 1; \
+       fi
+
+.PHONY: common-test-short
+common-test-short:
+	@echo ">> running short tests"
+	GO111MODULE=$(GO111MODULE) $(GO) test -short $(GOOPTS) $(pkgs)
+
+.PHONY: common-test
+common-test:
+	@echo ">> running all tests"
+	GO111MODULE=$(GO111MODULE) $(GO) test -race $(GOOPTS) $(pkgs)
+
+.PHONY: common-format
+common-format:
+	@echo ">> formatting code"
+	GO111MODULE=$(GO111MODULE) $(GO) fmt $(GOOPTS) $(pkgs)
+
+.PHONY: common-vet
+common-vet:
+	@echo ">> vetting code"
+	GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
+
+.PHONY: common-staticcheck
+common-staticcheck: $(STATICCHECK)
+	@echo ">> running staticcheck"
+ifdef GO111MODULE
+	GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" -checks "SA*" $(pkgs)
+else
+	$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
+endif
+
+.PHONY: common-unused
+common-unused: $(GOVENDOR)
+ifdef GOVENDOR
+	@echo ">> running check for unused packages"
+	@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
+else
+ifdef GO111MODULE
+	@echo ">> running check for unused/missing packages in go.mod"
+	GO111MODULE=$(GO111MODULE) $(GO) mod tidy
+	@git diff --exit-code -- go.sum go.mod
+ifneq (,$(wildcard vendor))
+	@echo ">> running check for unused packages in vendor/"
+	GO111MODULE=$(GO111MODULE) $(GO) mod vendor
+	@git diff --exit-code -- go.sum go.mod vendor/
+endif
+endif
+endif
+
+.PHONY: common-build
+common-build: promu
+	@echo ">> building binaries"
+	GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX)
+
+.PHONY: common-tarball
+common-tarball: promu
+	@echo ">> building release tarball"
+	$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
+
+.PHONY: common-docker
+common-docker:
+	docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
+
+.PHONY: common-docker-publish
+common-docker-publish:
+	docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
+
+.PHONY: common-docker-tag-latest
+common-docker-tag-latest:
+	docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"
+
+.PHONY: promu
+promu: $(PROMU)
+
+$(PROMU):
+	curl -s -L $(PROMU_URL) | tar -xvz -C /tmp
+	mkdir -v -p $(FIRST_GOPATH)/bin
+	cp -v /tmp/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(PROMU)
+
+.PHONY: proto
+proto:
+	@echo ">> generating code from proto files"
+	@./scripts/genproto.sh
+
+.PHONY: $(STATICCHECK)
+$(STATICCHECK):
+ifdef GO111MODULE
+# Get staticcheck from a temporary directory to avoid modifying the local go.{mod,sum}.
+# See https://github.com/golang/go/issues/27643.
+# For now, we are using the next branch of staticcheck because master isn't compatible yet with Go modules.
+	tmpModule=$$(mktemp -d 2>&1) && \
+	mkdir -p $${tmpModule}/staticcheck && \
+	cd "$${tmpModule}"/staticcheck && \
+	GO111MODULE=on $(GO) mod init example.com/staticcheck && \
+	GO111MODULE=on GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck@next && \
+	rm -rf $${tmpModule};
+else
+	GOOS= GOARCH= GO111MODULE=off $(GO) get -u honnef.co/go/tools/cmd/staticcheck
+endif
+
+ifdef GOVENDOR
+.PHONY: $(GOVENDOR)
+$(GOVENDOR):
+	GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
+endif
+
+.PHONY: precheck
+precheck::
+
+define PRECHECK_COMMAND_template =
+precheck:: $(1)_precheck
+
+
+PRECHECK_COMMAND_$(1) ?= $(1) $$(strip $$(PRECHECK_OPTIONS_$(1)))
+.PHONE: $(1)_precheck
+$(1)_precheck:
+	@if ! $$(PRECHECK_COMMAND_$(1)) 1>/dev/null 2>&1; then \
+		echo "Execution of '$$(PRECHECK_COMMAND_$(1))' command failed. Is $(1) installed?"; \
+		exit 1; \
+	fi
+endef
diff --git a/expfmt/text_create.go b/expfmt/text_create.go
index 16655d4..8e473d0 100644
--- a/expfmt/text_create.go
+++ b/expfmt/text_create.go
@@ -436,11 +436,11 @@ func writeEscapedString(w enhancedWriter, v string, includeDoubleQuote bool) (in
 func writeFloat(w enhancedWriter, f float64) (int, error) {
 	switch {
 	case f == 1:
-		return w.WriteString("1.0")
+		return 1, w.WriteByte('1')
 	case f == 0:
-		return w.WriteString("0.0")
+		return 1, w.WriteByte('0')
 	case f == -1:
-		return w.WriteString("-1.0")
+		return w.WriteString("-1")
 	case math.IsNaN(f):
 		return w.WriteString("NaN")
 	case math.IsInf(f, +1):
@@ -450,12 +450,6 @@ func writeFloat(w enhancedWriter, f float64) (int, error) {
 	default:
 		bp := numBufPool.Get().(*[]byte)
 		*bp = strconv.AppendFloat((*bp)[:0], f, 'g', -1, 64)
-		// Add a .0 if used fixed point and there is no decimal
-		// point already. This is for future proofing with OpenMetrics,
-		// where floats always contain either an exponent or decimal.
-		if !bytes.ContainsAny(*bp, "e.") {
-			*bp = append(*bp, '.', '0')
-		}
 		written, err := w.Write(*bp)
 		numBufPool.Put(bp)
 		return written, err
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..53aa344
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,26 @@
+module github.com/prometheus/common
+
+require (
+	github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
+	github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
+	github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
+	github.com/go-kit/kit v0.8.0
+	github.com/go-logfmt/logfmt v0.3.0 // indirect
+	github.com/go-stack/stack v1.8.0 // indirect
+	github.com/gogo/protobuf v1.1.1 // indirect
+	github.com/golang/protobuf v1.2.0
+	github.com/julienschmidt/httprouter v1.2.0
+	github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect
+	github.com/matttproud/golang_protobuf_extensions v1.0.1
+	github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223
+	github.com/pkg/errors v0.8.0
+	github.com/prometheus/client_golang v0.9.1
+	github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
+	github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d // indirect
+	github.com/sirupsen/logrus v1.2.0
+	golang.org/x/net v0.0.0-20181114220301-adae6a3d119a // indirect
+	golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
+	golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5
+	gopkg.in/alecthomas/kingpin.v2 v2.2.6
+	gopkg.in/yaml.v2 v2.2.1
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..3e2d132
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,58 @@
+github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
+github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
+github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
+github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
+github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
+github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
+github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
+github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic=
+github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
+github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
+github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
+github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
+github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
+github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
+github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
+github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
+github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 h1:F9x/1yl3T2AeKLr2AMdilSD8+f9bvMnNN8VS5iDtovc=
+github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
+github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
+github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_golang v0.9.1 h1:K47Rk0v/fkEfwfQet2KWhscE0cJzjgCCDBG2KHZoVno=
+github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
+github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
+github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFdaDqxJVlbOQ1DtGmZWs/Qau0hIlk+WQ=
+github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
+github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
+github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
+golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 h1:mzjBh+S5frKOsOBobWIMAbXavqjmgO17k/2puhcFR94=
+golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
+gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
+gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/internal/bitbucket.org/ww/goautoneg/autoneg.go b/internal/bitbucket.org/ww/goautoneg/autoneg.go
index 648b38c..26e9228 100644
--- a/internal/bitbucket.org/ww/goautoneg/autoneg.go
+++ b/internal/bitbucket.org/ww/goautoneg/autoneg.go
@@ -1,12 +1,12 @@
 /*
+Copyright (c) 2011, Open Knowledge Foundation Ltd.
+All rights reserved.
+
 HTTP Content-Type Autonegotiation.
 
 The functions in this package implement the behaviour specified in
 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
 
-Copyright (c) 2011, Open Knowledge Foundation Ltd.
-All rights reserved.
-
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
diff --git a/route/route.go b/route/route.go
index 66c9d48..ec45bdf 100644
--- a/route/route.go
+++ b/route/route.go
@@ -1,3 +1,16 @@
+// Copyright 2015 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package route
 
 import (


Test patch:
diff --git a/expfmt/decode_test.go b/expfmt/decode_test.go
index 47c480e..669d56c 100644
--- a/expfmt/decode_test.go
+++ b/expfmt/decode_test.go
@@ -205,7 +205,7 @@ func TestProtoDecoder(t *testing.T) {
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
-						"le": "100",
+						"le":                  "100",
 					},
 					Value:     123,
 					Timestamp: testTime,
@@ -213,7 +213,7 @@ func TestProtoDecoder(t *testing.T) {
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
-						"le": "120",
+						"le":                  "120",
 					},
 					Value:     412,
 					Timestamp: testTime,
@@ -221,7 +221,7 @@ func TestProtoDecoder(t *testing.T) {
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
-						"le": "144",
+						"le":                  "144",
 					},
 					Value:     592,
 					Timestamp: testTime,
@@ -229,7 +229,7 @@ func TestProtoDecoder(t *testing.T) {
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
-						"le": "172.8",
+						"le":                  "172.8",
 					},
 					Value:     1524,
 					Timestamp: testTime,
@@ -237,7 +237,7 @@ func TestProtoDecoder(t *testing.T) {
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
-						"le": "+Inf",
+						"le":                  "+Inf",
 					},
 					Value:     2693,
 					Timestamp: testTime,
@@ -265,55 +265,55 @@ func TestProtoDecoder(t *testing.T) {
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_count",
 					},
-					Value: 2693,
-					Timestamp:testTime,
+					Value:     2693,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
-						"le": "+Inf",
+						"le":                  "+Inf",
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
 					},
-					Value: 2693,
-					Timestamp:testTime,
+					Value:     2693,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
 						model.MetricNameLabel: "request_duration_microseconds_sum",
 					},
-					Value: 1756047.3,
-					Timestamp:testTime,
+					Value:     1756047.3,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
-						"le": "172.8",
+						"le":                  "172.8",
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
 					},
-					Value: 1524,
-					Timestamp:testTime,
+					Value:     1524,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
-						"le": "144",
+						"le":                  "144",
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
 					},
-					Value: 592,
-					Timestamp:testTime,
+					Value:     592,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
-						"le": "120",
+						"le":                  "120",
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
 					},
-					Value: 412,
-					Timestamp:testTime,
+					Value:     412,
+					Timestamp: testTime,
 				},
 				&model.Sample{
 					Metric: model.Metric{
-						"le": "100",
+						"le":                  "100",
 						model.MetricNameLabel: "request_duration_microseconds_bucket",
 					},
-					Value: 123,
-					Timestamp:testTime,
+					Value:     123,
+					Timestamp: testTime,
 				},
 			},
 		},
diff --git a/expfmt/encode_test.go b/expfmt/encode_test.go
index 16255e0..1b22873 100644
--- a/expfmt/encode_test.go
+++ b/expfmt/encode_test.go
@@ -1,3 +1,16 @@
+// Copyright 2018 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package expfmt
 
 import (
diff --git a/expfmt/text_create_test.go b/expfmt/text_create_test.go
index 892be8c..86e767c 100644
--- a/expfmt/text_create_test.go
+++ b/expfmt/text_create_test.go
@@ -212,14 +212,14 @@ untyped_name{name_1="value 1"} -1.23e-45
 # TYPE summary_name summary
 summary_name{quantile="0.5"} -1.23
 summary_name{quantile="0.9"} 0.2342354
-summary_name{quantile="0.99"} 0.0
+summary_name{quantile="0.99"} 0
 summary_name_sum -3.4567
-summary_name_count 42.0
-summary_name{name_1="value 1",name_2="value 2",quantile="0.5"} 1.0
-summary_name{name_1="value 1",name_2="value 2",quantile="0.9"} 2.0
-summary_name{name_1="value 1",name_2="value 2",quantile="0.99"} 3.0
+summary_name_count 42
+summary_name{name_1="value 1",name_2="value 2",quantile="0.5"} 1
+summary_name{name_1="value 1",name_2="value 2",quantile="0.9"} 2
+summary_name{name_1="value 1",name_2="value 2",quantile="0.99"} 3
 summary_name_sum{name_1="value 1",name_2="value 2"} 2010.1971
-summary_name_count{name_1="value 1",name_2="value 2"} 4711.0
+summary_name_count{name_1="value 1",name_2="value 2"} 4711
 `,
 		},
 		// 4: Histogram
@@ -261,13 +261,13 @@ summary_name_count{name_1="value 1",name_2="value 2"} 4711.0
 			},
 			out: `# HELP request_duration_microseconds The response latency.
 # TYPE request_duration_microseconds histogram
-request_duration_microseconds_bucket{le="100.0"} 123.0
-request_duration_microseconds_bucket{le="120.0"} 412.0
-request_duration_microseconds_bucket{le="144.0"} 592.0
-request_duration_microseconds_bucket{le="172.8"} 1524.0
-request_duration_microseconds_bucket{le="+Inf"} 2693.0
+request_duration_microseconds_bucket{le="100"} 123
+request_duration_microseconds_bucket{le="120"} 412
+request_duration_microseconds_bucket{le="144"} 592
+request_duration_microseconds_bucket{le="172.8"} 1524
+request_duration_microseconds_bucket{le="+Inf"} 2693
 request_duration_microseconds_sum 1.7560473e+06
-request_duration_microseconds_count 2693.0
+request_duration_microseconds_count 2693
 `,
 		},
 		// 5: Histogram with missing +Inf bucket.
@@ -282,26 +282,6 @@ request_duration_microseconds_count 2693.0
 							SampleCount: proto.Uint64(2693),
 							SampleSum:   proto.Float64(1756047.3),
 							Bucket: []*dto.Bucket{
-								&dto.Bucket{
-									UpperBound:      proto.Float64(0),
-									CumulativeCount: proto.Uint64(123),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e-5),
-									CumulativeCount: proto.Uint64(123),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e-4),
-									CumulativeCount: proto.Uint64(123),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e-1),
-									CumulativeCount: proto.Uint64(123),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1),
-									CumulativeCount: proto.Uint64(123),
-								},
 								&dto.Bucket{
 									UpperBound:      proto.Float64(100),
 									CumulativeCount: proto.Uint64(123),
@@ -318,18 +298,6 @@ request_duration_microseconds_count 2693.0
 									UpperBound:      proto.Float64(172.8),
 									CumulativeCount: proto.Uint64(1524),
 								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e5),
-									CumulativeCount: proto.Uint64(1543),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e6),
-									CumulativeCount: proto.Uint64(1544),
-								},
-								&dto.Bucket{
-									UpperBound:      proto.Float64(1e23),
-									CumulativeCount: proto.Uint64(1545),
-								},
 							},
 						},
 					},
@@ -337,21 +305,13 @@ request_duration_microseconds_count 2693.0
 			},
 			out: `# HELP request_duration_microseconds The response latency.
 # TYPE request_duration_microseconds histogram
-request_duration_microseconds_bucket{le="0.0"} 123.0
-request_duration_microseconds_bucket{le="1e-05"} 123.0
-request_duration_microseconds_bucket{le="0.0001"} 123.0
-request_duration_microseconds_bucket{le="0.1"} 123.0
-request_duration_microseconds_bucket{le="1.0"} 123.0
-request_duration_microseconds_bucket{le="100.0"} 123.0
-request_duration_microseconds_bucket{le="120.0"} 412.0
-request_duration_microseconds_bucket{le="144.0"} 592.0
-request_duration_microseconds_bucket{le="172.8"} 1524.0
-request_duration_microseconds_bucket{le="100000.0"} 1543.0
-request_duration_microseconds_bucket{le="1e+06"} 1544.0
-request_duration_microseconds_bucket{le="1e+23"} 1545.0
-request_duration_microseconds_bucket{le="+Inf"} 2693.0
+request_duration_microseconds_bucket{le="100"} 123
+request_duration_microseconds_bucket{le="120"} 412
+request_duration_microseconds_bucket{le="144"} 592
+request_duration_microseconds_bucket{le="172.8"} 1524
+request_duration_microseconds_bucket{le="+Inf"} 2693
 request_duration_microseconds_sum 1.7560473e+06
-request_duration_microseconds_count 2693.0
+request_duration_microseconds_count 2693
 `,
 		},
 		// 6: No metric type, should result in default type Counter.
diff --git a/internal/bitbucket.org/ww/goautoneg/autoneg_test.go b/internal/bitbucket.org/ww/goautoneg/autoneg_test.go
index 41d328f..aa424b3 100644
--- a/internal/bitbucket.org/ww/goautoneg/autoneg_test.go
+++ b/internal/bitbucket.org/ww/goautoneg/autoneg_test.go
@@ -1,3 +1,43 @@
+/*
+Copyright (c) 2011, Open Knowledge Foundation Ltd.
+All rights reserved.
+
+HTTP Content-Type Autonegotiation.
+
+The functions in this package implement the behaviour specified in
+http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+    Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+    Neither the name of the Open Knowledge Foundation Ltd. nor the
+    names of its contributors may be used to endorse or promote
+    products derived from this software without specific prior written
+    permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+*/
 package goautoneg
 
 import (
diff --git a/model/metric_test.go b/model/metric_test.go
index d708b57..8745bf2 100644
--- a/model/metric_test.go
+++ b/model/metric_test.go
@@ -120,7 +120,7 @@ func TestMetricNameIsValid(t *testing.T) {
 			valid: true,
 		},
 		{
-			mn: "",
+			mn:    "",
 			valid: false,
 		},
 	}
diff --git a/model/signature_test.go b/model/signature_test.go
index d59c8a8..0c79705 100644
--- a/model/signature_test.go
+++ b/model/signature_test.go
@@ -14,6 +14,7 @@
 package model
 
 import (
+	"fmt"
 	"runtime"
 	"sync"
 	"testing"
@@ -280,13 +281,17 @@ func benchmarkMetricToFastFingerprintConc(b *testing.B, ls LabelSet, e Fingerpri
 	var start, end sync.WaitGroup
 	start.Add(1)
 	end.Add(concLevel)
+	errc := make(chan error, 1)
 
 	for i := 0; i < concLevel; i++ {
 		go func() {
 			start.Wait()
 			for j := b.N / concLevel; j >= 0; j-- {
 				if a := labelSetToFastFingerprint(ls); a != e {
-					b.Fatalf("expected signature of %d for %s, got %d", e, ls, a)
+					select {
+					case errc <- fmt.Errorf("expected signature of %d for %s, got %d", e, ls, a):
+					default:
+					}
 				}
 			}
 			end.Done()
@@ -295,6 +300,12 @@ func benchmarkMetricToFastFingerprintConc(b *testing.B, ls LabelSet, e Fingerpri
 	b.ResetTimer()
 	start.Done()
 	end.Wait()
+
+	select {
+	case err := <-errc:
+		b.Fatal(err)
+	default:
+	}
 }
 
 func BenchmarkMetricToFastFingerprintTripleConc1(b *testing.B) {
diff --git a/route/route_test.go b/route/route_test.go
index 127974c..1019317 100644
--- a/route/route_test.go
+++ b/route/route_test.go
@@ -1,3 +1,16 @@
+// Copyright 2015 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package route
 
 import (