Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CircleCI setup #1

Merged
merged 14 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
version: 2.1
orbs:
prometheus: prometheus/[email protected]
executors:
# Whenever the Go version is updated here, .promu.yml and .promu-cgo.yml
# should also be updated.
golang:
docker:
- image: cimg/go:1.21
arm:
machine:
image: ubuntu-2204:current
resource_class: arm.medium

jobs:
test:
executor: golang
steps:
- prometheus/setup_environment
- run: go mod download
- run: make
- prometheus/store_artifact:
file: batchjob_exporter
test-arm:
executor: arm
steps:
- checkout
- run: uname -a
- run: make test-e2e
build:
machine:
image: ubuntu-2204:current
parallelism: 3
steps:
- prometheus/setup_environment
- run: docker run --privileged linuxkit/binfmt:af88a591f9cc896a52ce596b9cf7ca26a061ef97
- run: promu crossbuild -v --parallelism $CIRCLE_NODE_TOTAL --parallelism-thread $CIRCLE_NODE_INDEX
# - run: promu --config .promu-cgo.yml crossbuild -v --parallelism $CIRCLE_NODE_TOTAL --parallelism-thread $CIRCLE_NODE_INDEX
- persist_to_workspace:
root: .
paths:
- .build
- store_artifacts:
path: .build
destination: /build
test_docker:
machine:
image: ubuntu-2204:current
environment:
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.18-base
REPO_PATH: github.com/prometheus/batchjob_exporter
steps:
- prometheus/setup_environment
- attach_workspace:
at: .
- run:
command: |
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker
fi
- run: docker images
- run: docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T
- run:
command: |
if [ -n "$CIRCLE_TAG" ]; then
make test-docker DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make test-docker
fi
workflows:
version: 2
batchjob_exporter:
jobs:
- test:
filters:
tags:
only: /.*/
- test-arm:
filters:
tags:
only: /.*/
- build:
filters:
tags:
only: /.*/
# - test_docker:
# requires:
# - test
# - build
# filters:
# tags:
# only: /.*/
- prometheus/publish_master:
context: org-context
requires:
- test
- build
filters:
branches:
only: master
- prometheus/publish_release:
context: org-context
requires:
- test
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
Expand All @@ -28,3 +28,9 @@ collector/fixtures/sys

# Ignore scripts
run.sh

# Ignore artifacts
/.build
/.deps
/.release
/.tarballs
4 changes: 2 additions & 2 deletions .promu-cgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tarball:
- NOTICE
crossbuild:
platforms:
- darwin/amd64
- darwin/arm64
# We are not sure if our exporter will work on netbsd. So dont bother on
# cross compiling for now
- netbsd/amd64
- netbsd/386
10 changes: 8 additions & 2 deletions .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ tarball:
- NOTICE
crossbuild:
platforms:
- linux
- openbsd/amd64
- linux/amd64
- linux/386
- linux/arm64
- linux/mips
- linux/mipsle
- linux/mips64
- linux/mips64le
- linux/ppc64le
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
LABEL maintainer="Mahendra Paipuri <[email protected]>"

ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/batchjob_exporter /bin/batchjob_exporter

EXPOSE 9100
USER nobody
ENTRYPOINT [ "/bin/batchjob_exporter" ]
34 changes: 22 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ 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

TEST_DOCKER ?= false
DOCKER_IMAGE_NAME ?= batchjob-exporter
MACH ?= $(shell uname -m)
CGROUPS_MODE ?= $([ $(stat -fc %T /sys/fs/cgroup/) = "cgroup2fs" ] && echo "unified" || ( [ -e /sys/fs/cgroup/unified/ ] && echo "hybrid" || echo "legacy"))

STATICCHECK_IGNORE =

Expand All @@ -23,6 +25,12 @@ else
test-e2e := skip-test-e2e
endif

ifeq ($(TEST_DOCKER), false)
test-docker := skip-test-docker
else
test-docker := test-docker
endif

# Use CGO for non-Linux builds.
ifeq ($(GOOS), linux)
PROMU_CONF ?= .promu.yml
Expand All @@ -49,13 +57,13 @@ endif

PROMU := $(FIRST_GOPATH)/bin/promu --config $(PROMU_CONF)

e2e-out-64k-page = collector/fixtures/e2e-64k-page-output.txt
e2e-out = collector/fixtures/e2e-output.txt
ifeq ($(MACH), ppc64le)
e2e-out = $(e2e-out-64k-page)
endif
ifeq ($(MACH), aarch64)
e2e-out = $(e2e-out-64k-page)
e2e-cgroupsv2-out = collector/fixtures/e2e-test-cgroupsv2-output.txt
e2e-cgroupsv1-out = collector/fixtures/e2e-test-cgroupsv1-output.txt

ifeq ($(CGROUPS_MODE), unified)
e2e-out = $(e2e-cgroupsv2-out)
else
e2e-out = $(e2e-cgroupsv1-out)
endif

# 64bit -> 32bit mapping for cross-checking. At least for amd64/386, the 64bit CPU can execute 32bit code but not the other way around, so we don't support cross-testing upwards.
Expand All @@ -74,7 +82,7 @@ $(eval $(call goarch_pair,amd64,386))
$(eval $(call goarch_pair,mips64,mips))
$(eval $(call goarch_pair,mips64el,mipsel))

all:: vet checkmetrics checkrules common-all $(cross-test) $(test-e2e)
all:: vet checkmetrics checkrules common-all $(cross-test) $(test-docker) $(test-e2e)

.PHONY: test
test: collector/fixtures/sys/.unpacked
Expand All @@ -100,11 +108,10 @@ update_fixtures:
rm -vf collector/fixtures/sys/.unpacked
./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"
./end-to-end-test.sh
./e2e-test.sh

.PHONY: skip-test-e2e
skip-test-e2e:
Expand All @@ -114,7 +121,6 @@ skip-test-e2e:
checkmetrics: $(PROMTOOL)
@echo ">> checking metrics for correctness"
./checkmetrics.sh $(PROMTOOL) $(e2e-out)
./checkmetrics.sh $(PROMTOOL) $(e2e-out-64k-page)

.PHONY: checkrules
checkrules: $(PROMTOOL)
Expand All @@ -124,7 +130,11 @@ checkrules: $(PROMTOOL)
.PHONY: test-docker
test-docker:
@echo ">> testing docker image"
./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9100
./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9010

.PHONY: skip-test-docker
skip-test-docker:
@echo ">> SKIP running docker tests"

.PHONY: promtool
promtool: $(PROMTOOL)
Expand Down
4 changes: 2 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKERFILE_PATH ?= ./Dockerfile
DOCKERBUILD_CONTEXT ?= ./
DOCKER_REPO ?= prom
DOCKER_REPO ?= mahendrapaipuri

DOCKER_ARCHS ?= amd64

Expand All @@ -92,7 +92,7 @@ endif
%: common-% ;

.PHONY: common-all
common-all: precheck style check_license lint yamllint unused build test
common-all: precheck style lint yamllint unused build test

.PHONY: common-style
common-style:
Expand Down
2 changes: 1 addition & 1 deletion batchjob_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) e
cmd.Process.Kill()
}
return err
}
}
16 changes: 16 additions & 0 deletions checkmetrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if [[ ( -z "$1" ) || ( -z "$2" ) ]]; then
echo "usage: ./checkmetrics.sh /usr/bin/promtool e2e-test-output.txt"
exit 1
fi

# Ignore known issues in auto-generated and network specific collectors.
lint=$($1 check metrics < "$2" 2>&1 | grep -v -E "^batchjob_(memory_fail_count|memsw_fail_count)")

if [[ -n $lint ]]; then
echo -e "Some Prometheus metrics do not follow best practices:\n"
echo "$lint"

exit 1
fi
Loading