diff --git a/.circleci/config.yml b/.circleci/config.yml index 394f7ce..965b273 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,46 +1,33 @@ +--- +# Prometheus has switched to GitHub action. +# Circle CI is not disabled repository-wise so that previous pull requests +# continue working. +# This file does not generate any CircleCI workflow. + version: 2.1 -orbs: - prometheus: prometheus/prometheus@0.16.0 -jobs: - test: - # Whenever the Go version is updated here, .promu.yml - # should also be updated. + +executors: + golang: docker: - - image: cimg/go:1.18 + - image: busybox + +jobs: + noopjob: + executor: golang + steps: - - prometheus/setup_environment - - setup_remote_docker - - run: make - - prometheus/store_artifact: - file: haproxy_exporter + - run: + command: "true" + workflows: version: 2 - haproxy_exporter: + prometheus: jobs: - - test: - filters: - tags: - only: /.*/ - - prometheus/build: - name: build - filters: - tags: - only: /.*/ - - prometheus/publish_main: - context: org-context - requires: - - test - - build - filters: - branches: - only: main - - prometheus/publish_release: - context: org-context - requires: - - test - - build + - noopjob + triggers: + - schedule: + cron: "0 0 30 2 *" filters: - tags: - only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ branches: - ignore: /.*/ + only: + - main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ecff398 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +--- +name: CI +on: + pull_request: + push: +jobs: + test: + name: Test + runs-on: ubuntu-latest + # Whenever the Go version is updated here, .promu.yml + # should also be updated. + container: + image: quay.io/prometheus/golang-builder:1.19-base + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/setup_environment + - run: make + + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + thread: [ 0, 1, 2 ] + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/build + with: + parallelism: 3 + thread: ${{ matrix.thread }} + + golangci: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: '<1.19' + - name: Lint + uses: golangci/golangci-lint-action@v3.2.0 + with: + version: v1.49.0 + + publish_main: + name: Publish main branch artifacts + runs-on: ubuntu-latest + needs: [test, build] + if: github.event_name == 'push' && github.event.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/publish_main + with: + docker_hub_login: ${{ secrets.docker_hub_login }} + docker_hub_password: ${{ secrets.docker_hub_password }} + quay_io_login: ${{ secrets.quay_io_login }} + quay_io_password: ${{ secrets.quay_io_password }} + + publish_release: + name: Publish release arfefacts + runs-on: ubuntu-latest + needs: [test, build] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/publish_release + with: + docker_hub_login: ${{ secrets.docker_hub_login }} + docker_hub_password: ${{ secrets.docker_hub_password }} + quay_io_login: ${{ secrets.quay_io_login }} + quay_io_password: ${{ secrets.quay_io_password }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 6034bcb..0000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,30 +0,0 @@ -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 repository - uses: actions/checkout@v3 - - name: install Go - uses: actions/setup-go@v2 - with: - go-version: 1.18.x - - name: Install snmp_exporter/generator dependencies - run: sudo apt-get update && sudo apt-get -y install libsnmp-dev - if: github.repository == 'prometheus/snmp_exporter' - - name: Lint - uses: golangci/golangci-lint-action@v3.2.0 - with: - version: v1.45.2 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..a92005d --- /dev/null +++ b/.yamllint @@ -0,0 +1,21 @@ +--- +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 + line-length: disable + truthy: + ignore: | + .github/workflows/ci.yml diff --git a/Makefile b/Makefile index 45a4f52..cbfa9ff 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,11 @@ all:: vet checkmetrics common-all include Makefile.common -PROMTOOL_DOCKER_IMAGE ?= $(shell docker pull -q quay.io/prometheus/prometheus:latest || echo quay.io/prometheus/prometheus:latest) -PROMTOOL ?= docker run -i --rm -w "$(PWD)" -v "$(PWD):$(PWD)" --entrypoint promtool $(PROMTOOL_DOCKER_IMAGE) +PROMETHEUS_VERSION=2.39.1 +PROMTOOL ?= /tmp/prometheus-$(PROMETHEUS_VERSION).linux-amd64/promtool .PHONY: checkmetrics checkmetrics: @echo ">> checking metrics for correctness" + if ! test -x $(PROMTOOL); then curl -sL -o - https://github.com/prometheus/prometheus/releases/download/v$(PROMETHEUS_VERSION)/prometheus-$(PROMETHEUS_VERSION).linux-amd64.tar.gz | tar -C /tmp -xzf - prometheus-$(PROMETHEUS_VERSION).linux-amd64/promtool; fi for file in test/*.metrics; do $(PROMTOOL) check metrics < $$file || exit 1; done diff --git a/Makefile.common b/Makefile.common index c263b73..55783e5 100644 --- a/Makefile.common +++ b/Makefile.common @@ -83,7 +83,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v1.45.2 +GOLANGCI_LINT_VERSION ?= v1.49.0 # golangci-lint only supports linux, darwin and windows platforms on i386/amd64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) diff --git a/haproxy_exporter_test.go b/haproxy_exporter_test.go index 260248e..2518871 100644 --- a/haproxy_exporter_test.go +++ b/haproxy_exporter_test.go @@ -89,8 +89,7 @@ func TestServerWithoutChecks(t *testing.T) { // TestServerBrokenCSV ensures bugs in CSV format are handled gracefully. List of known bugs: // -// * http://permalink.gmane.org/gmane.comp.web.haproxy/26561 -// +// - http://permalink.gmane.org/gmane.comp.web.haproxy/26561 func TestServerBrokenCSV(t *testing.T) { const data = `foo,FRONTEND,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,5007,0,,1,8,1,,0,,2,0,,0,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,, foo,bug-missing-comma,0,0,0,0,,0,0,0,,0,,0,0,0,0,DRAIN (agent)1,1,0,0,0,5007,0,,1,8,1,,0,,2,0,,0,L4OK,,0,,,,,,,0,,,,0,0,,,,,,,,,,,