From 4bf210ea33ad66e3d3cdc61ab4ebdad0b524539a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Wed, 22 Jan 2025 12:42:40 +0100 Subject: [PATCH] update go, ci and add dependabot (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Bauer --- .github/auto-merge.yml | 4 + .github/dependabot.yml | 23 +++++ .github/release-drafter.yml | 38 ++++++++ .github/workflows/ci.yaml | 92 +++++++++++++++++++ .github/workflows/docker-publish.yml | 75 --------------- .github/workflows/release-drafter.yaml | 23 +++++ .github/workflows/release.yaml | 60 ++++++++++++ Dockerfile | 5 +- Makefile | 4 +- README.md | 16 ++-- cmd/pingdom-exporter/main.go | 27 +++--- cmd/pingdom-exporter/server.go | 4 +- go.mod | 28 +++--- go.sum | 85 +++++++++-------- .../api_responses.go | 4 +- .../api_responses_test.go | 0 pkg/{pingdom => pingdom-exporter}/check.go | 10 +- .../check_test.go | 0 pkg/{pingdom => pingdom-exporter}/outage.go | 9 +- .../outage_test.go | 0 pkg/{pingdom => pingdom-exporter}/pingdom.go | 6 +- .../pingdom_test.go | 6 +- sonar-project.properties | 2 - 23 files changed, 354 insertions(+), 167 deletions(-) create mode 100644 .github/auto-merge.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/docker-publish.yml create mode 100644 .github/workflows/release-drafter.yaml create mode 100644 .github/workflows/release.yaml rename pkg/{pingdom => pingdom-exporter}/api_responses.go (98%) rename pkg/{pingdom => pingdom-exporter}/api_responses_test.go (100%) rename pkg/{pingdom => pingdom-exporter}/check.go (86%) rename pkg/{pingdom => pingdom-exporter}/check_test.go (100%) rename pkg/{pingdom => pingdom-exporter}/outage.go (86%) rename pkg/{pingdom => pingdom-exporter}/outage_test.go (100%) rename pkg/{pingdom => pingdom-exporter}/pingdom.go (97%) rename pkg/{pingdom => pingdom-exporter}/pingdom_test.go (94%) delete mode 100644 sonar-project.properties diff --git a/.github/auto-merge.yml b/.github/auto-merge.yml new file mode 100644 index 0000000..3f1d122 --- /dev/null +++ b/.github/auto-merge.yml @@ -0,0 +1,4 @@ +--- +- match: + dependency_type: all + update_type: "semver:major" diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..02f0ac0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +--- +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + time: "09:00" + timezone: "Europe/Berlin" + + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "weekly" + time: "09:00" + timezone: "Europe/Berlin" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + time: "09:00" + timezone: "Europe/Berlin" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..d7c5eb2 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,38 @@ +--- +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧹 Maintenance' + labels: + - 'chore' + - 'dependencies' +version-resolver: + major: + labels: + - 'feature' + minor: + labels: + - 'enhancement' + patch: + labels: + - 'fix' + - 'bugfix' + - 'bug' + - 'chore' + - 'dependencies' + default: patch +template: | + ## Changes + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0356eb3 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,92 @@ +--- +name: ci + +permissions: read-all + +on: + pull_request: + +jobs: + go-lint: + name: go-lint + runs-on: ubuntu-24.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: stable + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + + go-test: + name: go test + runs-on: ubuntu-24.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: go test + run: make test + + super-linter: + permissions: + statuses: write + runs-on: ubuntu-24.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Lint Code Base + uses: github/super-linter/slim@v7 + env: + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VALIDATE_CHECKOV: false + VALIDATE_GO: false + VALIDATE_GO_MODULES: false + VALIDATE_JSCPD: false + VALIDATE_SHELL_SHFMT: false + VALIDATE_YAML_PRETTIER: false + + docker-build: + needs: + - go-lint + - go-test + runs-on: ubuntu-24.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build + id: docker_build + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + push: false + + dependabot-auto-merge: + needs: + - docker-build + - super-linter + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-24.04 + if: github.actor == 'dependabot[bot]' + steps: + - name: Enable auto-merge for Dependabot PRs + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 4ecbfb3..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Docker - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -on: - #schedule: - # - cron: '23 16 * * *' - push: - branches: [ "master" ] - # Publish semver tags as releases. - tags: [ 'v*.*.*' ] - pull_request: - branches: [ "master" ] - -env: - # Use docker.io for Docker Hub if empty - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} - - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - # This is used to complete the identity challenge - # with sigstore/fulcio when running outside of PRs. - id-token: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Set up BuildKit Docker container builder to be able to build - # multi-platform images and export cache - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..88fadac --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,23 @@ +--- +name: Release Drafter + +permissions: + contents: read + +on: + push: + branches: + - main + pull_request: + types: [opened, reopened, synchronize] + +jobs: + update_release_draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-24.04 + steps: + - uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..43b1a98 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,60 @@ +--- +name: release + +permissions: read-all + +on: + push: + branches: + - main + tags: + - 'v*' + +jobs: + docker-build-push: + permissions: + contents: read + id-token: write + packages: write + runs-on: ubuntu-24.04 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker metadata action + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v6 + with: + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index 039a94c..e2fbe45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ -FROM golang:1.19 AS build +FROM golang:1.23 AS build WORKDIR /app -ADD . . +COPY . . RUN make build FROM alpine:3 -MAINTAINER Daniel Martins COPY --from=build /app/bin/pingdom-exporter /pingdom-exporter ENTRYPOINT ["/pingdom-exporter"] diff --git a/Makefile b/Makefile index d42c007..b8951ae 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ GO=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go BIN=pingdom-exporter -IMAGE=jusbrasil/$(BIN) +IMAGE=monotek/$(BIN) DOCKER_BIN=docker TAG=$(shell git describe --tags) @@ -17,7 +17,7 @@ test: .PHONY: lint lint: - go get -u golang.org/x/lint/golint + go install golang.org/x/lint/golint@latest golint ./... # Build the Docker build stage TARGET diff --git a/README.md b/README.md index e50a217..20281da 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Pingdom Metrics Exporter for Prometheus +This is a fork of: + Prometheus exporter for uptime metrics exposed by the Pingdom API. ## Running @@ -7,7 +9,7 @@ Prometheus exporter for uptime metrics exposed by the Pingdom API. Make sure you expose the Pingdom API Token via the `PINGDOM_API_TOKEN` environment variable: -```sh +```bash # Expose the Pingdom API Token export PINGDOM_API_TOKEN= @@ -17,20 +19,20 @@ bin/pingdom-exporter ### Usage -``` +```bash bin/pingdom-exporter -h Usage of bin/pingdom-exporter: -default-uptime-slo float - default uptime SLO to be used when the check doesn't provide a uptime SLO tag (i.e. uptime_slo_999 to 99.9% uptime SLO) (default 99) + default uptime SLO to be used when the check doesn't provide a uptime SLO tag (i.e. uptime_slo_999 to 99.9% uptime SLO) (default 99) -metrics-path string - path under which to expose metrics (default "/metrics") + path under which to expose metrics (default "/metrics") -outage-check-period int - time (in days) in which to retrieve outage data from the Pingdom API (default 7) + time (in days) in which to retrieve outage data from the Pingdom API (default 7) -port int - port to listen on (default 9158) + port to listen on (default 9158) -tags string - tag list separated by commas + tag list separated by commas ``` #### Supported Pingdom Tags diff --git a/cmd/pingdom-exporter/main.go b/cmd/pingdom-exporter/main.go index d296c81..245c8bf 100644 --- a/cmd/pingdom-exporter/main.go +++ b/cmd/pingdom-exporter/main.go @@ -10,8 +10,9 @@ import ( "sync" "time" - "github.com/jusbrasil/pingdom-exporter/pkg/pingdom" + "github.com/monotek/pingdom-exporter/pkg/pingdom-exporter" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -22,7 +23,6 @@ var ( token string tags string metricsPath string - waitSeconds int port int outageCheckPeriod int defaultUptimeSLO float64 @@ -209,7 +209,7 @@ func (pc pingdomCollector) Collect(ch chan<- prometheus.Metric) { for _, state := range states { switch state.Status { case "down": - downCount = downCount + 1 + downCount++ downTime = downTime + float64(state.ToTime-state.FromTime) case "up": upTime = upTime + float64(state.ToTime-state.FromTime) @@ -299,19 +299,22 @@ func main() { registry.MustRegister( collector, - prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}), - prometheus.NewGoCollector(), + collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), + collectors.NewGoCollector(), ) http.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{})) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(` - Pingdom Exporter - -

Pingdom Exporter

-

Metrics

- - `)) + _, err := w.Write([]byte(` + Pingdom Exporter + +

Pingdom Exporter

+

Metrics

+ + `)) + if err != nil { + http.Error(w, "Unable to write response", http.StatusInternalServerError) + } }) fmt.Fprintf(os.Stdout, "Pingdom Exporter %v listening on http://0.0.0.0:%v\n", VERSION, port) diff --git a/cmd/pingdom-exporter/server.go b/cmd/pingdom-exporter/server.go index a237976..c602b56 100644 --- a/cmd/pingdom-exporter/server.go +++ b/cmd/pingdom-exporter/server.go @@ -29,5 +29,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (s *Server) healthz(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("OK")) + if _, err := w.Write([]byte("OK")); err != nil { + http.Error(w, "Unable to write response", http.StatusInternalServerError) + } } diff --git a/go.mod b/go.mod index b96bf5b..cf5d134 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,26 @@ -module github.com/jusbrasil/pingdom-exporter +module github.com/monotek/pingdom-exporter require ( - github.com/prometheus/client_golang v1.14.0 - github.com/stretchr/testify v1.8.1 + github.com/prometheus/client_golang v1.20.5 + github.com/stretchr/testify v1.10.0 ) require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.2 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.39.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect - golang.org/x/sys v0.3.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.55.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + golang.org/x/lint v0.0.0-20241112194109-818c5a804067 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/tools v0.29.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) -go 1.19 +go 1.23 diff --git a/go.sum b/go.sum index a2bdb61..afaed77 100644 --- a/go.sum +++ b/go.sum @@ -1,54 +1,61 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jusbrasil/pingdom-exporter v1.4.2 h1:Sb/iyIbfUQpWz1qfZFn8JdTyHyeq5p1uSpSyhkBQDlI= +github.com/jusbrasil/pingdom-exporter v1.4.2/go.mod h1:rJ8AqCbAfYLU6JxVic0DSKxZR/AqiZqnkxI4zInCBSI= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= -github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20241112194109-818c5a804067 h1:adDmSQyFTCiv19j015EGKJBoaa7ElV0Q1Wovb/4G7NA= +golang.org/x/lint v0.0.0-20241112194109-818c5a804067/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/pingdom/api_responses.go b/pkg/pingdom-exporter/api_responses.go similarity index 98% rename from pkg/pingdom/api_responses.go rename to pkg/pingdom-exporter/api_responses.go index e9051f5..8459b5c 100644 --- a/pkg/pingdom/api_responses.go +++ b/pkg/pingdom-exporter/api_responses.go @@ -51,11 +51,11 @@ type CheckResponse struct { LastErrorTime int64 `json:"lasterrortime,omitempty"` LastTestTime int64 `json:"lasttesttime,omitempty"` LastResponseTime int64 `json:"lastresponsetime,omitempty"` - IntegrationIds []int `json:"integrationids,omitempty"` + IntegrationIDs []int `json:"integrationids,omitempty"` SeverityLevel string `json:"severity_level,omitempty"` Type CheckResponseType `json:"type,omitempty"` Tags []CheckResponseTag `json:"tags,omitempty"` - UserIds []int `json:"userids,omitempty"` + UserIDs []int `json:"userids,omitempty"` Teams []CheckTeamResponse `json:"teams,omitempty"` ResponseTimeThreshold int `json:"responsetime_threshold,omitempty"` ProbeFilters []string `json:"probe_filters,omitempty"` diff --git a/pkg/pingdom/api_responses_test.go b/pkg/pingdom-exporter/api_responses_test.go similarity index 100% rename from pkg/pingdom/api_responses_test.go rename to pkg/pingdom-exporter/api_responses_test.go diff --git a/pkg/pingdom/check.go b/pkg/pingdom-exporter/check.go similarity index 86% rename from pkg/pingdom/check.go rename to pkg/pingdom-exporter/check.go index 0e54911..253aad1 100644 --- a/pkg/pingdom/check.go +++ b/pkg/pingdom-exporter/check.go @@ -2,7 +2,8 @@ package pingdom import ( "encoding/json" - "io/ioutil" + "io" + "log" ) // CheckService provides an interface to Pingdom checks. @@ -32,8 +33,11 @@ func (cs *CheckService) List(params ...map[string]string) ([]CheckResponse, erro if err := validateResponse(resp); err != nil { return nil, err } - - bodyBytes, _ := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + log.Println("Error reading response body:", err) + return nil, err + } bodyString := string(bodyBytes) m := &listChecksJSONResponse{} err = json.Unmarshal([]byte(bodyString), &m) diff --git a/pkg/pingdom/check_test.go b/pkg/pingdom-exporter/check_test.go similarity index 100% rename from pkg/pingdom/check_test.go rename to pkg/pingdom-exporter/check_test.go diff --git a/pkg/pingdom/outage.go b/pkg/pingdom-exporter/outage.go similarity index 86% rename from pkg/pingdom/outage.go rename to pkg/pingdom-exporter/outage.go index 545b00f..8dd74f7 100644 --- a/pkg/pingdom/outage.go +++ b/pkg/pingdom-exporter/outage.go @@ -3,7 +3,8 @@ package pingdom import ( "encoding/json" "fmt" - "io/ioutil" + "io" + "log" ) // OutageSummaryService provides an interface to Pingdom outage summary. @@ -33,7 +34,11 @@ func (os *OutageSummaryService) List(checkID int, params ...map[string]string) ( return nil, err } - bodyBytes, _ := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + log.Println("Error reading response body:", err) + return nil, err + } bodyString := string(bodyBytes) m := &listOutageSummaryJSONResponse{} err = json.Unmarshal([]byte(bodyString), &m) diff --git a/pkg/pingdom/outage_test.go b/pkg/pingdom-exporter/outage_test.go similarity index 100% rename from pkg/pingdom/outage_test.go rename to pkg/pingdom-exporter/outage_test.go diff --git a/pkg/pingdom/pingdom.go b/pkg/pingdom-exporter/pingdom.go similarity index 97% rename from pkg/pingdom/pingdom.go rename to pkg/pingdom-exporter/pingdom.go index 6f51583..2edbfd7 100644 --- a/pkg/pingdom/pingdom.go +++ b/pkg/pingdom-exporter/pingdom.go @@ -3,7 +3,7 @@ package pingdom import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" ) @@ -114,7 +114,7 @@ func decodeResponse(r *http.Response, v interface{}) error { return fmt.Errorf("nil interface provided to decodeResponse") } - bodyBytes, _ := ioutil.ReadAll(r.Body) + bodyBytes, _ := io.ReadAll(r.Body) bodyString := string(bodyBytes) err := json.Unmarshal([]byte(bodyString), &v) return err @@ -128,7 +128,7 @@ func validateResponse(r *http.Response) error { return nil } - bodyBytes, _ := ioutil.ReadAll(r.Body) + bodyBytes, _ := io.ReadAll(r.Body) bodyString := string(bodyBytes) m := &errorJSONResponse{} err := json.Unmarshal([]byte(bodyString), &m) diff --git a/pkg/pingdom/pingdom_test.go b/pkg/pingdom-exporter/pingdom_test.go similarity index 94% rename from pkg/pingdom/pingdom_test.go rename to pkg/pingdom-exporter/pingdom_test.go index 9a14633..502c215 100644 --- a/pkg/pingdom/pingdom_test.go +++ b/pkg/pingdom-exporter/pingdom_test.go @@ -2,7 +2,7 @@ package pingdom import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -88,7 +88,7 @@ func TestValidateResponse(t *testing.T) { valid := &http.Response{ Request: &http.Request{}, StatusCode: http.StatusOK, - Body: ioutil.NopCloser(strings.NewReader("OK")), + Body: io.NopCloser(strings.NewReader("OK")), } assert.NoError(t, validateResponse(valid)) @@ -96,7 +96,7 @@ func TestValidateResponse(t *testing.T) { invalid := &http.Response{ Request: &http.Request{}, StatusCode: http.StatusBadRequest, - Body: ioutil.NopCloser(strings.NewReader(`{ + Body: io.NopCloser(strings.NewReader(`{ "error" : { "statuscode": 400, "statusdesc": "Bad Request", diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 8522499..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,2 +0,0 @@ -sonar.projectKey=jusbrasil_pingdom-exporter -sonar.go.coverage.reportPaths=coverage.out \ No newline at end of file