diff --git a/.circleci/config.yml b/.circleci/config.yml index 6eea3127..3d7e292b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ jobs: - run: go mod download - run: make - prometheus/store_artifact: - file: batchjob_exporter + file: ./bin/batchjob_exporter test-arm: executor: arm steps: diff --git a/.gitignore b/.gitignore index abe603d5..07d67793 100644 --- a/.gitignore +++ b/.gitignore @@ -23,9 +23,6 @@ go.work # Ignore fixtures collector/fixtures/sys -# Ignore binary -**/*batchjob_exporter - # Ignore scripts run.sh @@ -34,3 +31,6 @@ run.sh /.deps /.release /.tarballs + +# Ignore binaries +/bin diff --git a/.promu-cgo.yml b/.promu-cgo.yml index 6285cce9..a30b5a12 100644 --- a/.promu-cgo.yml +++ b/.promu-cgo.yml @@ -8,6 +8,7 @@ repository: build: binaries: - name: batchjob_exporter + path: ./cmd/batchjob_exporter flags: -a -tags 'netgo osusergo static_build' ldflags: | -X github.com/prometheus/common/version.Version={{.Version}} diff --git a/.promu.yml b/.promu.yml index ffca1376..a0e9736a 100644 --- a/.promu.yml +++ b/.promu.yml @@ -7,6 +7,7 @@ repository: build: binaries: - name: batchjob_exporter + path: ./cmd/batchjob_exporter flags: -a -tags 'netgo osusergo static_build' ldflags: | -X github.com/prometheus/common/version.Version={{.Version}} diff --git a/Makefile b/Makefile index 27fe0eae..9005a937 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ PROMTOOL_VERSION ?= 2.30.0 PROMTOOL_URL ?= https://github.com/prometheus/prometheus/releases/download/v$(PROMTOOL_VERSION)/prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM).tar.gz PROMTOOL ?= $(FIRST_GOPATH)/bin/promtool +PREFIX := $(shell pwd)/bin + TEST_DOCKER ?= false DOCKER_IMAGE_NAME ?= batchjob-exporter MACH ?= $(shell uname -m) @@ -101,17 +103,17 @@ skip-test-32bit: %/.unpacked: %.ttar @echo ">> extracting fixtures" if [ -d $(dir $@) ] ; then rm -rf $(dir $@) ; fi - ./ttar -C $(dir $*) -x -f $*.ttar + ./scripts/ttar -C $(dir $*) -x -f $*.ttar touch $@ update_fixtures: rm -vf collector/fixtures/sys/.unpacked - ./ttar -C collector/fixtures -c -f collector/fixtures/sys.ttar sys + ./scripts/ttar -C collector/fixtures -c -f collector/fixtures/sys.ttar sys .PHONY: test-e2e test-e2e: build collector/fixtures/sys/.unpacked @echo ">> running end-to-end tests" - ./e2e-test.sh + ./scripts/e2e-test.sh .PHONY: skip-test-e2e skip-test-e2e: @@ -120,7 +122,7 @@ skip-test-e2e: .PHONY: checkmetrics checkmetrics: $(PROMTOOL) @echo ">> checking metrics for correctness" - ./checkmetrics.sh $(PROMTOOL) $(e2e-out) + ./scripts/checkmetrics.sh $(PROMTOOL) $(e2e-out) .PHONY: checkrules checkrules: $(PROMTOOL) @@ -130,7 +132,7 @@ checkrules: $(PROMTOOL) .PHONY: test-docker test-docker: @echo ">> testing docker image" - ./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9010 + ./scripts/test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9010 .PHONY: skip-test-docker skip-test-docker: diff --git a/batchjob_exporter.go b/cmd/batchjob_exporter/batchjob_exporter.go similarity index 100% rename from batchjob_exporter.go rename to cmd/batchjob_exporter/batchjob_exporter.go diff --git a/batchjob_exporter_test.go b/cmd/batchjob_exporter/batchjob_exporter_test.go similarity index 100% rename from batchjob_exporter_test.go rename to cmd/batchjob_exporter/batchjob_exporter_test.go diff --git a/checkmetrics.sh b/scripts/checkmetrics.sh similarity index 100% rename from checkmetrics.sh rename to scripts/checkmetrics.sh diff --git a/e2e-test.sh b/scripts/e2e-test.sh similarity index 92% rename from e2e-test.sh rename to scripts/e2e-test.sh index 7dd0d6dc..fdc46bb6 100755 --- a/e2e-test.sh +++ b/scripts/e2e-test.sh @@ -2,7 +2,7 @@ set -euf -o pipefail -cd "$(dirname $0)" +cd "$(dirname $0)/.." port="$((10000 + (RANDOM % 10000)))" tmpdir=$(mktemp -d /tmp/batchjob_exporter_e2e_test.XXXXXX) @@ -44,13 +44,13 @@ do esac done -if [ ! -x ./batchjob_exporter ] +if [ ! -x ./bin/batchjob_exporter ] then - echo './batchjob_exporter not found. Consider running `go build` first.' >&2 + echo './bin/batchjob_exporter not found. Consider running `go build` first.' >&2 exit 1 fi -PATH=$PWD/collector/fixtures:$PATH ./batchjob_exporter \ +PATH=$PWD/collector/fixtures:$PATH ./bin/batchjob_exporter \ --path.sysfs="collector/fixtures/sys" \ --path.cgroupfs="collector/fixtures/sys/fs/cgroup" \ --collector.slurm.unique.jobid \ diff --git a/test_image.sh b/scripts/test_image.sh similarity index 100% rename from test_image.sh rename to scripts/test_image.sh diff --git a/ttar b/scripts/ttar similarity index 100% rename from ttar rename to scripts/ttar