diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8dc4473..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,88 +0,0 @@ ---- -version: 2.1 - -orbs: - prometheus: prometheus/prometheus@0.17.1 - -executors: - golang: - docker: - # Whenever the Go version is updated here, .promu.yml should also be updated. - - image: cimg/go:1.25 - -jobs: - test: - executor: golang - steps: - - prometheus/setup_environment - - run: make - - prometheus/store_artifact: - file: consul_exporter - - integration: - parameters: - consul_version: - type: string - docker: - # Whenever the Go version is updated here, .promu.yml should also be updated. - - image: cimg/go:1.25 - - image: hashicorp/consul:<< parameters.consul_version >> - name: consul - environment: - CONSUL_LOCAL_CONFIG: '{"node_name":"test"}' - environment: - CONSUL_SERVER: consul:8500 - CONSUL_NODE_NAME: test - - steps: - - run: - command: | - echo "CONSUL_VERSION=$(/bin/consul version | awk '$1 == "Consul" {print $2}' | tr -d 'v')" >> $BASH_ENV - source $BASH_ENV - - prometheus/setup_environment - - run: make test - - run: git diff --exit-code - - store_test_results: - path: test-results - -workflows: - version: 2 - prometheus: - jobs: - - test: - filters: - tags: - only: /.*/ - - integration: - matrix: - parameters: - consul_version: - - "1.18" - - "1.21" - - "1.22" - filters: - tags: - only: /.*/ - - prometheus/build: - name: 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[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ - branches: - ignore: /.*/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8488e46 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,103 @@ +--- +name: CI +on: + pull_request: + push: + branches: [master, 'release-*'] + tags: ['v*'] + +permissions: + contents: read + +jobs: + test_go: + name: Go tests + runs-on: ubuntu-latest + container: + # Whenever the Go version is updated here, .promu.yml should also be + # updated. + image: quay.io/prometheus/golang-builder:1.26-base + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - run: make + - run: git diff --exit-code + + integration: + name: Integration tests (Consul ${{ matrix.consul_version }}) + runs-on: ubuntu-latest + container: + # Whenever the Go version is updated here, .promu.yml should also be + # updated. + image: quay.io/prometheus/golang-builder:1.26-base + strategy: + matrix: + consul_version: ["1.18", "1.21", "1.22"] + services: + consul: + image: hashicorp/consul:${{ matrix.consul_version }} + env: + CONSUL_LOCAL_CONFIG: '{"node_name":"test"}' + env: + CONSUL_SERVER: "consul:8500" + CONSUL_NODE_NAME: "test" + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - run: | + until curl -sf http://consul:8500/v1/agent/self > /dev/null; do sleep 1; done + CONSUL_VERSION=$(curl -s http://consul:8500/v1/agent/self | jq -r '.Config.Version') + test -n "$CONSUL_VERSION" + echo "CONSUL_VERSION=$CONSUL_VERSION" >> $GITHUB_ENV + - run: make test GOOPTS=-v + - run: git diff --exit-code + + build: + name: Build consul_exporter for all architectures + runs-on: ubuntu-latest + strategy: + matrix: + thread: [ 0, 1, 2, 3] + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: prometheus/promci/build@9347e3d5e607933687d9db7af2f23504fe7f893a # v0.6.2 + with: + parallelism: 4 + thread: ${{ matrix.thread }} + + publish_main: + name: Publish main branch artifacts + runs-on: ubuntu-latest + needs: [test_go, integration, build] + if: (github.event_name == 'push' && github.event.ref == 'refs/heads/master') + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: prometheus/promci/publish_main@9347e3d5e607933687d9db7af2f23504fe7f893a # v0.6.2 + 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 artifacts + runs-on: ubuntu-latest + needs: [test_go, integration, build] + if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: prometheus/promci/publish_release@9347e3d5e607933687d9db7af2f23504fe7f893a # v0.6.2 + 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 }} + github_token: ${{ secrets.PROMBOT_GITHUB_TOKEN }} diff --git a/.promu.yml b/.promu.yml index ebcaaad..b29ef80 100644 --- a/.promu.yml +++ b/.promu.yml @@ -1,7 +1,7 @@ go: - # Whenever the Go version is updated here, .circle/config.yml should also - # be updated. - version: 1.25 + # Whenever the Go version is updated here, .github/workflows/ci.yml should + # also be updated. + version: 1.26 repository: path: github.com/prometheus/consul_exporter build: diff --git a/pkg/exporter/consul_exporter_test.go b/pkg/exporter/consul_exporter_test.go index 2b18db8..a197d89 100644 --- a/pkg/exporter/consul_exporter_test.go +++ b/pkg/exporter/consul_exporter_test.go @@ -24,6 +24,7 @@ import ( consul_api "github.com/hashicorp/consul/api" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/prometheus/common/expfmt" + "github.com/prometheus/common/model" "github.com/prometheus/common/promslog" ) @@ -275,7 +276,7 @@ consul_service_tag{node="{{ .Node }}",service_id="foobar",tag="tag2"} 1 // Only check metrics that are explicitly listed above. var ( - tp expfmt.TextParser + tp = expfmt.NewTextParser(model.UTF8Validation) metricNames []string buf = bytes.NewReader(w.Bytes()) )