From d39302183ba9d05faac217057eb6b4d0e442674a Mon Sep 17 00:00:00 2001 From: Richard Hillmann Date: Tue, 14 Mar 2017 00:48:47 +0100 Subject: [PATCH] update makefile to work with busybox --- Makefile | 16 ++++++++-------- exporter.go | 8 +++----- exporter_test.go | 13 ++++++------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 4b6e64b..9af6731 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,15 @@ GO := GO15VENDOREXPERIMENT=1 go -pkgs = $(shell $(GO) list ./... | grep -v /vendor/) +pkgs = . DOCKER_IMAGE_NAME ?= exporter DOCKER_IMAGE_TAG ?= latest -all: format build test +all: get format test build + +get: + @echo ">> get dependencies" + @$(GO) get style: @echo ">> checking code style" @@ -19,16 +23,12 @@ format: @echo ">> formatting code" @$(GO) fmt $(pkgs) -vet: - @echo ">> vetting code" - @$(GO) vet $(pkgs) - build: @echo ">> building binaries" - @$(GO) build -o exporter + @$(GO) build -tags netgo -a -o exporter docker: @echo ">> building docker image" @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . -.PHONY: all style format build test vet docker \ No newline at end of file +.PHONY: all get style format test build docker diff --git a/exporter.go b/exporter.go index f1d6189..fc87967 100644 --- a/exporter.go +++ b/exporter.go @@ -6,6 +6,8 @@ import ( "fmt" "io/ioutil" "net/http" + "net/url" + "strings" "syscall" "time" @@ -13,8 +15,6 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/log" "github.com/prometheus/common/version" - "net/url" - "strings" ) const ( @@ -137,8 +137,6 @@ func (s *appScraper) stats() (*AppStats, error) { return nil, fmt.Errorf("Invalid JSON returned, could not retreive duration.*") } - - return &stats, err } @@ -221,7 +219,7 @@ func NewExporter(endpoint string) (*Exporter, error) { // use custom http client with specific timeout client := &http.Client{ - Timeout: time.Duration(100*time.Millisecond), + Timeout: time.Duration(100 * time.Millisecond), } // create api client diff --git a/exporter_test.go b/exporter_test.go index f07553c..8a3a64f 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -1,11 +1,11 @@ package main import ( - "testing" - "net/http/httptest" "fmt" "net/http" + "net/http/httptest" "reflect" + "testing" ) func TestScraper(t *testing.T) { @@ -13,7 +13,7 @@ func TestScraper(t *testing.T) { tests := []struct { json string expected *AppStats - ok bool + ok bool }{ { json: ` @@ -48,14 +48,13 @@ func TestScraper(t *testing.T) { Count: 91905, Sum: 4484.3037570333245, Average: 0.024613801985478054, - }, }, ok: true, }, { json: "invalid", - ok: false, + ok: false, }, } @@ -72,8 +71,8 @@ func TestScraper(t *testing.T) { } stats, err := scraper.stats() - if err != nil{ - if !test.ok{ + if err != nil { + if !test.ok { continue } t.Fatalf("Test %v: http.Get(%q) unexpected error: %v", i, server.URL, err)