Skip to content

Commit

Permalink
Add source code
Browse files Browse the repository at this point in the history
  • Loading branch information
mahendrapaipuri committed Nov 15, 2023
1 parent 41e3604 commit 7bd2a5d
Show file tree
Hide file tree
Showing 34 changed files with 7,319 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This action is synced from https://github.com/prometheus/prometheus
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@

# Go workspace file
go.work

# Ignore fixtures
collector/fixtures/sys

# Ignore binary
**/*batchjob_exporter

# Ignore scripts
run.sh
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
linters:
enable:
- misspell
- revive
disable:
# Disable soon to deprecated[1] linters that lead to false
# positives when build tags disable certain files[2]
# 1: https://github.com/golangci/golangci-lint/issues/1841
# 2: https://github.com/prometheus/node_exporter/issues/1545
- deadcode
- unused
- structcheck
- varcheck

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude-functions:
# Used in HTTP handlers, any error is handled by the server itself.
- (net/http.ResponseWriter).Write
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
27 changes: 27 additions & 0 deletions .promu-cgo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu.yml should also be updated.
version: 1.21
cgo: true
repository:
path: github.com/mahendrapaipuri/batchjob_exporter
build:
binaries:
- name: batchjob_exporter
flags: -a -tags 'netgo osusergo static_build'
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE
crossbuild:
platforms:
- darwin/amd64
- darwin/arm64
- netbsd/amd64
- netbsd/386
24 changes: 24 additions & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu-cgo.yml should also be updated.
version: 1.21
repository:
path: github.com/mahendrapaipuri/batchjob_exporter
build:
binaries:
- name: batchjob_exporter
flags: -a -tags 'netgo osusergo static_build'
ldflags: |
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE
crossbuild:
platforms:
- linux
- openbsd/amd64
23 changes: 23 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
commas: disable
comments: disable
comments-indentation: disable
document-start: disable
indentation:
spaces: consistent
indent-sequences: consistent
key-duplicates:
ignore: |
config/testdata/section_key_dup.bad.yml
line-length: disable
truthy:
check-keys: false
134 changes: 134 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Nicked from node_exporter repo and modified to current exporter

# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
all::

# Needs to be defined before including Makefile.common to auto-generate targets
DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le s390x

include Makefile.common

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

DOCKER_IMAGE_NAME ?= batchjob-exporter
MACH ?= $(shell uname -m)

STATICCHECK_IGNORE =

ifeq ($(GOHOSTOS), linux)
test-e2e := test-e2e
else
test-e2e := skip-test-e2e
endif

# Use CGO for non-Linux builds.
ifeq ($(GOOS), linux)
PROMU_CONF ?= .promu.yml
else
ifndef GOOS
ifeq ($(GOHOSTOS), linux)
PROMU_CONF ?= .promu.yml
else
PROMU_CONF ?= .promu-cgo.yml
endif
else
# Do not use CGO for openbsd/amd64 builds
ifeq ($(GOOS), openbsd)
ifeq ($(GOARCH), amd64)
PROMU_CONF ?= .promu.yml
else
PROMU_CONF ?= .promu-cgo.yml
endif
else
PROMU_CONF ?= .promu-cgo.yml
endif
endif
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)
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.
cross-test = skip-test-32bit
define goarch_pair
ifeq ($$(GOHOSTOS),linux)
ifeq ($$(GOHOSTARCH),$1)
GOARCH_CROSS = $2
cross-test = test-32bit
endif
endif
endef

# By default, "cross" test with ourselves to cover unknown pairings.
$(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)

.PHONY: test
test: collector/fixtures/sys/.unpacked
@echo ">> running tests"
$(GO) test -short $(test-flags) $(pkgs)

.PHONY: test-32bit
test-32bit: collector/fixtures/sys/.unpacked
@echo ">> running tests in 32-bit mode"
@env GOARCH=$(GOARCH_CROSS) $(GO) test $(pkgs)

.PHONY: skip-test-32bit
skip-test-32bit:
@echo ">> SKIP running tests in 32-bit mode: not supported on $(GOHOSTOS)/$(GOHOSTARCH)"

%/.unpacked: %.ttar
@echo ">> extracting fixtures"
if [ -d $(dir $@) ] ; then rm -rf $(dir $@) ; fi
./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


.PHONY: test-e2e
test-e2e: build collector/fixtures/sys/.unpacked
@echo ">> running end-to-end tests"
./end-to-end-test.sh

.PHONY: skip-test-e2e
skip-test-e2e:
@echo ">> SKIP running end-to-end tests on $(GOHOSTOS)"

.PHONY: checkmetrics
checkmetrics: $(PROMTOOL)
@echo ">> checking metrics for correctness"
./checkmetrics.sh $(PROMTOOL) $(e2e-out)
./checkmetrics.sh $(PROMTOOL) $(e2e-out-64k-page)

.PHONY: checkrules
checkrules: $(PROMTOOL)
@echo ">> checking rules for correctness"
find . -name "*rules*.yml" | xargs -I {} $(PROMTOOL) check rules {}

.PHONY: test-docker
test-docker:
@echo ">> testing docker image"
./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9100

.PHONY: promtool
promtool: $(PROMTOOL)

$(PROMTOOL):
mkdir -p $(FIRST_GOPATH)/bin
curl -fsS -L $(PROMTOOL_URL) | tar -xvzf - -C $(FIRST_GOPATH)/bin --strip 1 "prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM)/promtool"
Loading

0 comments on commit 7bd2a5d

Please sign in to comment.