Browse Source

update makefile to work with busybox

master
Richard Hillmann 9 years ago
parent
commit
d39302183b
  1. 16
      Makefile
  2. 8
      exporter.go
  3. 13
      exporter_test.go

16
Makefile

@ -1,11 +1,15 @@
GO := GO15VENDOREXPERIMENT=1 go GO := GO15VENDOREXPERIMENT=1 go
pkgs = $(shell $(GO) list ./... | grep -v /vendor/) pkgs = .
DOCKER_IMAGE_NAME ?= exporter DOCKER_IMAGE_NAME ?= exporter
DOCKER_IMAGE_TAG ?= latest DOCKER_IMAGE_TAG ?= latest
all: format build test all: get format test build
get:
@echo ">> get dependencies"
@$(GO) get
style: style:
@echo ">> checking code style" @echo ">> checking code style"
@ -19,16 +23,12 @@ format:
@echo ">> formatting code" @echo ">> formatting code"
@$(GO) fmt $(pkgs) @$(GO) fmt $(pkgs)
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
build: build:
@echo ">> building binaries" @echo ">> building binaries"
@$(GO) build -o exporter @$(GO) build -tags netgo -a -o exporter
docker: docker:
@echo ">> building docker image" @echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
.PHONY: all style format build test vet docker .PHONY: all get style format test build docker

8
exporter.go

@ -6,6 +6,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"strings"
"syscall" "syscall"
"time" "time"
@ -13,8 +15,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
"github.com/prometheus/common/version" "github.com/prometheus/common/version"
"net/url"
"strings"
) )
const ( const (
@ -137,8 +137,6 @@ func (s *appScraper) stats() (*AppStats, error) {
return nil, fmt.Errorf("Invalid JSON returned, could not retreive duration.*") return nil, fmt.Errorf("Invalid JSON returned, could not retreive duration.*")
} }
return &stats, err return &stats, err
} }
@ -221,7 +219,7 @@ func NewExporter(endpoint string) (*Exporter, error) {
// use custom http client with specific timeout // use custom http client with specific timeout
client := &http.Client{ client := &http.Client{
Timeout: time.Duration(100*time.Millisecond), Timeout: time.Duration(100 * time.Millisecond),
} }
// create api client // create api client

13
exporter_test.go

@ -1,11 +1,11 @@
package main package main
import ( import (
"testing"
"net/http/httptest"
"fmt" "fmt"
"net/http" "net/http"
"net/http/httptest"
"reflect" "reflect"
"testing"
) )
func TestScraper(t *testing.T) { func TestScraper(t *testing.T) {
@ -13,7 +13,7 @@ func TestScraper(t *testing.T) {
tests := []struct { tests := []struct {
json string json string
expected *AppStats expected *AppStats
ok bool ok bool
}{ }{
{ {
json: ` json: `
@ -48,14 +48,13 @@ func TestScraper(t *testing.T) {
Count: 91905, Count: 91905,
Sum: 4484.3037570333245, Sum: 4484.3037570333245,
Average: 0.024613801985478054, Average: 0.024613801985478054,
}, },
}, },
ok: true, ok: true,
}, },
{ {
json: "invalid", json: "invalid",
ok: false, ok: false,
}, },
} }
@ -72,8 +71,8 @@ func TestScraper(t *testing.T) {
} }
stats, err := scraper.stats() stats, err := scraper.stats()
if err != nil{ if err != nil {
if !test.ok{ if !test.ok {
continue continue
} }
t.Fatalf("Test %v: http.Get(%q) unexpected error: %v", i, server.URL, err) t.Fatalf("Test %v: http.Get(%q) unexpected error: %v", i, server.URL, err)

Loading…
Cancel
Save