Skip to content

Commit

Permalink
Merge pull request #31 from vaz-ar/master
Browse files Browse the repository at this point in the history
Updated the makefile to build without CGO
  • Loading branch information
warmans authored Nov 19, 2024
2 parents 2e80242 + f63f3e2 commit 60ad684
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ifndef MAKE_DEBUG
MAKEFLAGS += -s
MAKEFLAGS += -s
endif

GO := go
PROMU ?= $(GOPATH)/bin/promu
# Setting CGO_ENABLED to 0 disables CGO (cf. https://pkg.go.dev/cmd/cgo)
CGO_ENABLED := 0

GIT_TAG ?= $(shell git describe --tags --exact-match 2>/dev/null || echo "unknown")

Expand All @@ -13,20 +13,20 @@ PROJECT_OWNER ?= warmans
PROJECT_NAME ?= aggregate-exporter
DOCKER_NAME ?= $(PROJECT_OWNER)/$(PROJECT_NAME)

LOCAL_BIN:="$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/.env/bin"
LOCAL_BIN := "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/.env/bin"

.PHONY: install.linter
install.linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v1.51.2

.PHONT: lint.go
.PHONY: lint.go
lint:
$(LOCAL_BIN)/golangci-lint run

.PHONY: build
build:
echo ">> building linux binary"
go build -o ${BIN_DIR}/prometheus-aggregate-exporter -ldflags "-X main.Version=${GIT_TAG}" ./cmd
CGO_ENABLED=$(CGO_ENABLED) go build -o ${BIN_DIR}/prometheus-aggregate-exporter -ldflags "-X main.Version=${GIT_TAG}" ./cmd

.PHONY: build-arch
build-arch:
Expand All @@ -37,7 +37,8 @@ ifndef GOARCH
echo "GOARCH must be defined"; exit 1;
endif
echo ">> building $(GOOS) $(GOARCH) binary"
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o ${BIN_DIR}/prometheus-aggregate-exporter-$(GOOS)-$(GOARCH) -ldflags "-X main.Version=${GIT_TAG}" ./cmd
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -o ${BIN_DIR}/prometheus-aggregate-exporter-$(GOOS)-$(GOARCH) -ldflags "-X main.Version=${GIT_TAG}" ./cmd


# Manual Testing
#----------------------------------------------------------------------
Expand Down
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,31 @@ the aggregate view.
-version (VERSION)
Show version and exit
```

### How to build it

#### Build using the go binary

If you have go (1.14) installed on your machine, you can simply do:

cd cmd/
go build -o prometheus-aggregate-exporter
```shell
cd cmd/
go build -o prometheus-aggregate-exporter
```

To build without CGO enabled, which removes the dependency on `libc`, do:

```shell
cd cmd/
CGO_ENABLED=0 go build -o prometheus-aggregate-exporter
```

Or you can use the provided Makefile:

make build
```shell
make build
```

#### Build into a Docker image

Expand All @@ -70,18 +81,19 @@ You can run the exporter against some static fixture files by running the follow
in separate terminals.

```shell
$ make test.run-fixture-server
$ make test.run
make test.run-fixture-server
make test.run
```

then to view the `/metrics` page:

```shell
$ make test.scrape
make test.fetch
```

### Example Usage
```

```shell
./bin/prometheus-aggregate-exporter \
-targets="http://localhost:3000/histogram.txt,http://localhost:3000/histogram-2.txt" \
-server.bind=":8080"
Expand All @@ -90,15 +102,15 @@ $ make test.scrape
or using environment variables instead of flags:


```
```shell
TARGETS="http://localhost:3000/histogram.txt,http://localhost:3000/histogram-2.txt" \
SERVER_BIND=":8080" \
./bin/prometheus-aggregate-exporter
```

or with docker

```
```shell
docker run -it -p 8080:8080 -e TARGETS="http://localhost:3000/metrics" warmans/aggregate-exporter:latest
```

Expand Down

0 comments on commit 60ad684

Please sign in to comment.