From 99fbc0e8a08b7da7c80316395b4e2b06865fd1c9 Mon Sep 17 00:00:00 2001 From: Dmitri Fedotov Date: Thu, 9 Jan 2025 17:28:41 +0200 Subject: [PATCH] go-makefile-maker + fork commit --- .envrc | 8 + .github/renovate.json | 52 ++++++ .github/workflows/checks.yaml | 52 ++++++ .github/workflows/ci.yaml | 57 ++++++ .github/workflows/codeql.yaml | 44 +++++ .../workflows/container-registry-ghcr.yaml | 58 ++++++ .golangci.yaml | 173 ++++++++++++++++++ .license-scan-overrides.jsonl | 7 + .license-scan-rules.json | 11 ++ Makefile | 128 +++++++++++++ Makefile.maker.yaml | 41 +++++ README.md | 10 +- REUSE.toml | 18 ++ client/bird_client.go | 4 +- client/client.go | 2 +- go.mod | 4 +- main.go | 4 +- metric_collector.go | 6 +- metrics/bfd_exporter.go | 4 +- metrics/default_label_strategy.go | 2 +- metrics/default_label_strategy_test.go | 2 +- metrics/generic_exporter.go | 2 +- metrics/label_strategy.go | 2 +- metrics/legacy_exporter.go | 2 +- metrics/legacy_label_strategy.go | 2 +- metrics/metrics_exporter.go | 2 +- metrics/ospf_exporter.go | 4 +- parser/bfd.go | 2 +- parser/bfd_test.go | 2 +- parser/ospf.go | 2 +- parser/parser.go | 2 +- parser/parser_test.go | 2 +- shell.nix | 18 ++ 33 files changed, 700 insertions(+), 29 deletions(-) create mode 100644 .envrc create mode 100644 .github/renovate.json create mode 100644 .github/workflows/checks.yaml create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/codeql.yaml create mode 100644 .github/workflows/container-registry-ghcr.yaml create mode 100644 .golangci.yaml create mode 100644 .license-scan-overrides.jsonl create mode 100644 .license-scan-rules.json create mode 100644 Makefile create mode 100644 Makefile.maker.yaml create mode 100644 REUSE.toml create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c8a98ce --- /dev/null +++ b/.envrc @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2019–2020 Target, Copyright 2021 The Nix Community +# SPDX-License-Identifier: Apache-2.0 +if type -P lorri &>/dev/null; then + eval "$(lorri direnv)" +else + use nix +fi diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..831f375 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,52 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", + "default:pinDigestsDisabled", + "mergeConfidence:all-badges", + "docker:disable" + ], + "assignees": [ + "defo89", + "SchwarzM", + "xsen84", + "goerangudat" + ], + "commitMessageAction": "Renovate: Update", + "constraints": { + "go": "1.23" + }, + "dependencyDashboardOSVVulnerabilitySummary": "all", + "osvVulnerabilityAlerts": true, + "postUpdateOptions": [ + "gomodTidy", + "gomodUpdateImportPaths" + ], + "packageRules": [ + { + "matchPackageNames": [ + "golang" + ], + "allowedVersions": "1.23.x" + }, + { + "matchPackageNames": [ + "/^github\\.com\\/sapcc\\/.*/" + ], + "automerge": true, + "groupName": "github.com/sapcc" + }, + { + "matchPackageNames": [ + "!/^github\\.com\\/sapcc\\/.*/", + "/.*/" + ], + "groupName": "External dependencies" + } + ], + "prHourlyLimit": 0, + "schedule": [ + "before 8am on Thursday" + ], + "semanticCommits": "disabled" +} diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml new file mode 100644 index 0000000..1a19633 --- /dev/null +++ b/.github/workflows/checks.yaml @@ -0,0 +1,52 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +name: Checks +"on": + push: + branches: + - main + pull_request: + branches: + - '*' + workflow_dispatch: {} +permissions: + checks: write + contents: read +jobs: + checks: + name: Checks + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + check-latest: true + go-version: 1.23.4 + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + - name: Dependency Licenses Review + run: make check-dependency-licenses + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@latest + - name: Run govulncheck + run: govulncheck -format text ./... + - name: Check for spelling errors + uses: reviewdog/action-misspell@v1 + with: + exclude: ./vendor/* + fail_on_error: true + github_token: ${{ secrets.GITHUB_TOKEN }} + ignore: importas + reporter: github-check + - name: Check if source code files have license header + run: make check-license-headers diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..8902fb4 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,57 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +name: CI +"on": + push: + branches: + - main + paths-ignore: + - '**.md' + pull_request: + branches: + - '*' + paths-ignore: + - '**.md' + workflow_dispatch: {} +permissions: + contents: read +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + check-latest: true + go-version: 1.23.4 + test: + name: Test + needs: + - build + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + check-latest: true + go-version: 1.23.4 + - name: Run tests and generate coverage report + run: make build/cover.out + - name: Upload coverage report to Coveralls + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GIT_BRANCH: ${{ github.head_ref }} + run: | + go install github.com/mattn/goveralls@latest + goveralls -service=github -coverprofile=build/cover.out diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..09e243c --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,44 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +name: CodeQL +"on": + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: '00 07 * * 1' + workflow_dispatch: {} +permissions: + actions: read + contents: read + security-events: write +jobs: + analyze: + name: CodeQL + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + check-latest: true + go-version: 1.23.4 + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: go + queries: security-extended + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/container-registry-ghcr.yaml b/.github/workflows/container-registry-ghcr.yaml new file mode 100644 index 0000000..720951f --- /dev/null +++ b/.github/workflows/container-registry-ghcr.yaml @@ -0,0 +1,58 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +name: Container Registry GHCR +"on": + push: + branches: + - main + workflow_dispatch: {} +permissions: + contents: read + packages: write +jobs: + build-and-push-image: + name: Push container to ghcr.io + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + # https://github.com/docker/metadata-action#typeedge + type=edge + # https://github.com/docker/metadata-action#latest-tag + type=raw,value=latest,enable={{is_default_branch}} + # https://github.com/docker/metadata-action#typesemver + type=semver,pattern={{raw}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + # https://github.com/docker/metadata-action#typesha + type=sha,format=long + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..14411b0 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,173 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +run: + timeout: 3m # 1m by default + modules-download-mode: readonly + +output: + # Do not print lines of code with issue. + print-issued-lines: false + +issues: + exclude: + # It is idiomatic Go to reuse the name 'err' with ':=' for subsequent errors. + # Ref: https://go.dev/doc/effective_go#redeclaration + - 'declaration of "err" shadows declaration at' + exclude-rules: + - path: _test\.go + linters: + - bodyclose + - dupl + # '0' disables the following options. + max-issues-per-linter: 0 + max-same-issues: 0 + +linters-settings: + dupl: + # Tokens count to trigger issue, 150 by default. + threshold: 100 + errcheck: + # Report about assignment of errors to blank identifier. + check-blank: true + # Do not report about not checking of errors in type assertions. + # This is not as dangerous as skipping error values because an unchecked type assertion just immediately panics. + # We disable this because it makes a ton of useless noise esp. in test code. + check-type-assertions: false + forbidigo: + analyze-types: true # required for pkg: + forbid: + # ioutil package has been deprecated: https://github.com/golang/go/issues/42026 + - ^ioutil\..*$ + # Using http.DefaultServeMux is discouraged because it's a global variable that some packages silently and magically add handlers to (esp. net/http/pprof). + # Applications wishing to use http.ServeMux should obtain local instances through http.NewServeMux() instead of using the global default instance. + - ^http\.DefaultServeMux$ + - ^http\.Handle(?:Func)?$ + # Forbid usage of old and archived square/go-jose + - pkg: ^gopkg\.in/square/go-jose\.v2$ + msg: "gopk.in/square/go-jose is archived and has CVEs. Replace it with gopkg.in/go-jose/go-jose.v2" + - pkg: ^github.com/coreos/go-oidc$ + msg: "github.com/coreos/go-oidc depends on gopkg.in/square/go-jose which has CVEs. Replace it with github.com/coreos/go-oidc/v3" + + - pkg: ^github.com/howeyc/gopass$ + msg: "github.com/howeyc/gopass is archived, use golang.org/x/term instead" + goconst: + ignore-tests: true + min-occurrences: 5 + gocritic: + enabled-checks: + - boolExprSimplify + - builtinShadow + - emptyStringTest + - evalOrder + - httpNoBody + - importShadow + - initClause + - methodExprCall + - paramTypeCombine + - preferFilepathJoin + - ptrToRefParam + - redundantSprint + - returnAfterHttpError + - stringConcatSimplify + - timeExprSimplify + - truncateCmp + - typeAssertChain + - typeUnparen + - unnamedResult + - unnecessaryBlock + - unnecessaryDefer + - weakCond + - yodaStyleExpr + goimports: + # Put local imports after 3rd-party packages. + local-prefixes: github.com/sapcc/bird_exporter + gomoddirectives: + toolchain-forbidden: true + go-version-pattern: '1\.\d+(\.0)?$' + gosec: + excludes: + # gosec wants us to set a short ReadHeaderTimeout to avoid Slowloris attacks, but doing so would expose us to Keep-Alive race conditions (see https://iximiuz.com/en/posts/reverse-proxy-http-keep-alive-and-502s/) + - G112 + # created file permissions are restricted by umask if necessary + - G306 + govet: + enable-all: true + disable: + - fieldalignment + nolintlint: + require-specific: true + stylecheck: + dot-import-whitelist: + - github.com/onsi/ginkgo/v2 + - github.com/onsi/gomega + usestdlibvars: + constant-kind: true + crypto-hash: true + default-rpc-path: true + http-method: true + http-status-code: true + sql-isolation-level: true + time-layout: true + time-month: true + time-weekday: true + tls-signature-scheme: true + usetesting: + os-setenv: true + os-temp-dir: true + whitespace: + # Enforce newlines (or comments) after multi-line function signatures. + multi-func: true + +linters: + # We use 'disable-all' and enable linters explicitly so that a newer version + # does not introduce new linters unexpectedly. + disable-all: true + enable: + - bodyclose + - containedctx + - copyloopvar + - dupl + - dupword + - durationcheck + - errcheck + - errname + - errorlint + - exptostd + - forbidigo + - ginkgolinter + - gocheckcompilerdirectives + - goconst + - gocritic + - gofmt + - goimports + - gomoddirectives + - gosec + - gosimple + - govet + - ineffassign + - intrange + - misspell + - nilerr + - noctx + - nolintlint + - nosprintfhostport + - perfsprint + - predeclared + - rowserrcheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - usetesting + - whitespace diff --git a/.license-scan-overrides.jsonl b/.license-scan-overrides.jsonl new file mode 100644 index 0000000..29aac5c --- /dev/null +++ b/.license-scan-overrides.jsonl @@ -0,0 +1,7 @@ +{"name": "github.com/chzyer/logex", "licenceType": "MIT"} +{"name": "github.com/hashicorp/vault/api/auth/approle", "licenceType": "MPL-2.0"} +{"name": "github.com/jpillora/longestcommon", "licenceType": "MIT"} +{"name": "github.com/spdx/tools-golang", "licenceTextOverrideFile": "vendor/github.com/spdx/tools-golang/LICENSE.code"} +{"name": "github.com/xeipuuv/gojsonpointer", "licenceType": "Apache-2.0"} +{"name": "github.com/xeipuuv/gojsonreference", "licenceType": "Apache-2.0"} +{"name": "github.com/xeipuuv/gojsonschema", "licenceType": "Apache-2.0"} diff --git a/.license-scan-rules.json b/.license-scan-rules.json new file mode 100644 index 0000000..e584e9d --- /dev/null +++ b/.license-scan-rules.json @@ -0,0 +1,11 @@ +{ + "allowlist": [ + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "ISC", + "MIT", + "MPL-2.0", + "Unlicense" + ] +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b83cbce --- /dev/null +++ b/Makefile @@ -0,0 +1,128 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +MAKEFLAGS=--warn-undefined-variables +# /bin/sh is dash on Debian which does not support all features of ash/bash +# to fix that we use /bin/bash only on Debian to not break Alpine +ifneq (,$(wildcard /etc/os-release)) # check file existence + ifneq ($(shell grep -c debian /etc/os-release),0) + SHELL := /bin/bash + endif +endif + +default: FORCE + @echo 'There is nothing to build, use `make check` for running the test suite or `make help` for a list of available targets.' + +install-golangci-lint: FORCE + @if ! hash golangci-lint 2>/dev/null; then printf "\e[1;36m>> Installing golangci-lint (this may take a while)...\e[0m\n"; go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; fi + +install-go-licence-detector: FORCE + @if ! hash go-licence-detector 2>/dev/null; then printf "\e[1;36m>> Installing go-licence-detector...\e[0m\n"; go install go.elastic.co/go-licence-detector@latest; fi + +install-addlicense: FORCE + @if ! hash addlicense 2>/dev/null; then printf "\e[1;36m>> Installing addlicense...\e[0m\n"; go install github.com/google/addlicense@latest; fi + +prepare-static-check: FORCE install-golangci-lint install-go-licence-detector install-addlicense + +GO_BUILDFLAGS = +GO_LDFLAGS = +GO_TESTENV = +GO_BUILDENV = + +# which packages to test with test runner +GO_TESTPKGS := $(shell go list -f '{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...) +ifeq ($(GO_TESTPKGS),) +GO_TESTPKGS := ./... +endif +# which packages to measure coverage for +GO_COVERPKGS := $(shell go list ./...) +# to get around weird Makefile syntax restrictions, we need variables containing nothing, a space and comma +null := +space := $(null) $(null) +comma := , + +check: FORCE static-check build/cover.html + @printf "\e[1;32m>> All checks successful.\e[0m\n" + +run-golangci-lint: FORCE install-golangci-lint + @printf "\e[1;36m>> golangci-lint\e[0m\n" + @golangci-lint run + +build/cover.out: FORCE | build + @printf "\e[1;36m>> Running tests\e[0m\n" + @env $(GO_TESTENV) go test -shuffle=on -p 1 -coverprofile=$@ $(GO_BUILDFLAGS) -ldflags '-s -w $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS) + +build/cover.html: build/cover.out + @printf "\e[1;36m>> go tool cover > build/cover.html\e[0m\n" + @go tool cover -html $< -o $@ + +static-check: FORCE run-golangci-lint check-dependency-licenses check-license-headers + +build: + @mkdir $@ + +tidy-deps: FORCE + go mod tidy + go mod verify + +force-license-headers: FORCE install-addlicense + @printf "\e[1;36m>> addlicense\e[0m\n" + echo -n $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) | xargs -d" " -I{} bash -c 'year="$$(rg -P "Copyright (....) SAP SE" -Nor "\$$1" {})"; awk -i inplace '"'"'{if (display) {print} else {!/^\/\*/ && !/^\*/ && !/^\$$/}}; /^package /{print;display=1}'"'"' {}; addlicense -c "SAP SE" -s=only -y "$$year" -- {}' + +license-headers: FORCE install-addlicense + @printf "\e[1;36m>> addlicense\e[0m\n" + @addlicense -c "SAP SE" -s=only -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) + +check-license-headers: FORCE install-addlicense + @printf "\e[1;36m>> addlicense --check\e[0m\n" + @addlicense --check -- $(patsubst $(shell awk '$$1 == "module" {print $$2}' go.mod)%,.%/*.go,$(shell go list ./...)) + +check-dependency-licenses: FORCE install-go-licence-detector + @printf "\e[1;36m>> go-licence-detector\e[0m\n" + @go list -m -mod=readonly -json all | go-licence-detector -includeIndirect -rules .license-scan-rules.json -overrides .license-scan-overrides.jsonl + +clean: FORCE + git clean -dxf build + +vars: FORCE + @printf "GO_BUILDFLAGS=$(GO_BUILDFLAGS)\n" + @printf "GO_COVERPKGS=$(GO_COVERPKGS)\n" + @printf "GO_LDFLAGS=$(GO_LDFLAGS)\n" + @printf "GO_TESTENV=$(GO_TESTENV)\n" + @printf "GO_TESTPKGS=$(GO_TESTPKGS)\n" +help: FORCE + @printf "\n" + @printf "\e[1mUsage:\e[0m\n" + @printf " make \e[36m\e[0m\n" + @printf "\n" + @printf "\e[1mGeneral\e[0m\n" + @printf " \e[36mvars\e[0m Display values of relevant Makefile variables.\n" + @printf " \e[36mhelp\e[0m Display this help.\n" + @printf "\n" + @printf "\e[1mPrepare\e[0m\n" + @printf " \e[36minstall-golangci-lint\e[0m Install golangci-lint required by run-golangci-lint/static-check\n" + @printf " \e[36minstall-go-licence-detector\e[0m Install-go-licence-detector required by check-dependency-licenses/static-check\n" + @printf " \e[36minstall-addlicense\e[0m Install addlicense required by check-license-headers/license-headers/static-check\n" + @printf " \e[36mprepare-static-check\e[0m Install any tools required by static-check. This is used in CI before dropping privileges, you should probably install all the tools using your package manager\n" + @printf "\n" + @printf "\e[1mTest\e[0m\n" + @printf " \e[36mcheck\e[0m Run the test suite (unit tests and golangci-lint).\n" + @printf " \e[36mrun-golangci-lint\e[0m Install and run golangci-lint. Installing is used in CI, but you should probably install golangci-lint using your package manager.\n" + @printf " \e[36mbuild/cover.out\e[0m Run tests and generate coverage report.\n" + @printf " \e[36mbuild/cover.html\e[0m Generate an HTML file with source code annotations from the coverage report.\n" + @printf " \e[36mstatic-check\e[0m Run static code checks\n" + @printf "\n" + @printf "\e[1mDevelopment\e[0m\n" + @printf " \e[36mtidy-deps\e[0m Run go mod tidy and go mod verify.\n" + @printf " \e[36mforce-license-headers\e[0m Remove and re-add all license headers to all non-vendored source code files.\n" + @printf " \e[36mlicense-headers\e[0m Add license headers to all non-vendored source code files.\n" + @printf " \e[36mcheck-license-headers\e[0m Check license headers in all non-vendored .go files.\n" + @printf " \e[36mcheck-dependency-licenses\e[0m Check all dependency licenses using go-licence-detector.\n" + @printf " \e[36mclean\e[0m Run git clean.\n" + +.PHONY: FORCE diff --git a/Makefile.maker.yaml b/Makefile.maker.yaml new file mode 100644 index 0000000..cfadf44 --- /dev/null +++ b/Makefile.maker.yaml @@ -0,0 +1,41 @@ +# Configuration file for + +metadata: + url: https://github.com/sapcc/bird_exporter + +dockerfile: + enabled: false + +golang: + enableVendoring: false + setGoModVersion: true + +golangciLint: + createConfig: true + +githubWorkflow: + ci: + enabled: true + coveralls: true + ignorePaths: + - "**.md" # all Markdown files + license: + enabled: true + securityChecks: + enabled: true + pushContainerToGhcr: + enabled: true + platforms: "linux/amd64" + tagStrategy: + - edge + - latest + - semver + - sha + +renovate: + enabled: true + assignees: + - defo89 + - SchwarzM + - xsen84 + - goerangudat diff --git a/README.md b/README.md index 56be246..b6dc8ea 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # bird_exporter -[![Go Report Card](https://goreportcard.com/badge/github.com/czerwonk/bird_exporter)](https://goreportcard.com/report/github.com/czerwonk/bird_exporter) +[![Go Report Card](https://goreportcard.com/badge/github.com/sapcc/bird_exporter)](https://goreportcard.com/report/github.com/sapcc/bird_exporter) Metric exporter for bird routing daemon to use with Prometheus. +> [!NOTE] +> This is a fork of [czerwonk/bird_exporter](https://github.com/czerwonk/bird_exporter) +> to keep up with dependency updates. + ## Remarks Since bird_exporter uses the bird unix sockets, bird has to be installed on the same machine as bird_exporter. Also the user executing bird_exporter must have permission to access the bird socket files. @@ -52,7 +56,7 @@ In version 0.8 communication to bird changed to sockets. The default socket path ## Install ``` -go get -u github.com/czerwonk/bird_exporter +go get -u github.com/sapcc/bird_exporter ``` ## Usage @@ -65,7 +69,7 @@ this sample dashboard was created by [openbsod](https://github.com/openbsod). Th [https://grafana.com/grafana/dashboards/5259-bird-rs/](https://grafana.com/grafana/dashboards/5259-bird-rs/) -![alt text](https://github.com/czerwonk/bird_exporter/blob/master/grafana/img/bird_exporter.png) +![alt text](https://github.com/sapcc/bird_exporter/blob/master/grafana/img/bird_exporter.png) ## Features * BGP session state diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..552d440 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: SAP SE +# SPDX-License-Identifier: Apache-2.0 + +version = 1 + +[[annotations]] +path = [ + ".github/CODEOWNERS", + ".github/renovate.json", + ".gitignore", + ".license-scan-overrides.jsonl", + ".license-scan-rules.json", + "go.mod", + "go.sum", + "Makefile.maker.yaml", +] +SPDX-FileCopyrightText = "SAP SE" +SPDX-License-Identifier = "Apache-2.0" diff --git a/client/bird_client.go b/client/bird_client.go index 2b8d56a..d2d5717 100644 --- a/client/bird_client.go +++ b/client/bird_client.go @@ -3,9 +3,9 @@ package client import ( "fmt" - "github.com/czerwonk/bird_exporter/parser" - "github.com/czerwonk/bird_exporter/protocol" birdsocket "github.com/czerwonk/bird_socket" + "github.com/sapcc/bird_exporter/parser" + "github.com/sapcc/bird_exporter/protocol" ) // BirdClient communicates with the bird socket to retrieve information diff --git a/client/client.go b/client/client.go index 20fa7e2..09412e9 100644 --- a/client/client.go +++ b/client/client.go @@ -1,6 +1,6 @@ package client -import "github.com/czerwonk/bird_exporter/protocol" +import "github.com/sapcc/bird_exporter/protocol" // Client retrieves information from Bird routing daemon type Client interface { diff --git a/go.mod b/go.mod index 9d187f6..0efa343 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/czerwonk/bird_exporter +module github.com/sapcc/bird_exporter -go 1.21 +go 1.23 require ( github.com/czerwonk/bird_socket v0.0.0-20230831050638-df62ae583e1d diff --git a/main.go b/main.go index eb00419..af273aa 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,9 @@ import ( "net/http" "os" - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/sapcc/bird_exporter/protocol" log "github.com/sirupsen/logrus" ) @@ -80,7 +80,7 @@ func startServer() {

Bird Routing Daemon Exporter

Metrics

More information:

-

github.com/czerwonk/bird_exporter

+

github.com/sapcc/bird_exporter

`)) }) diff --git a/metric_collector.go b/metric_collector.go index 2e4fd8e..cab2e92 100644 --- a/metric_collector.go +++ b/metric_collector.go @@ -1,10 +1,10 @@ package main import ( - "github.com/czerwonk/bird_exporter/client" - "github.com/czerwonk/bird_exporter/metrics" - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/client" + "github.com/sapcc/bird_exporter/metrics" + "github.com/sapcc/bird_exporter/protocol" log "github.com/sirupsen/logrus" ) diff --git a/metrics/bfd_exporter.go b/metrics/bfd_exporter.go index 3094edd..ab009f5 100644 --- a/metrics/bfd_exporter.go +++ b/metrics/bfd_exporter.go @@ -1,9 +1,9 @@ package metrics import ( - "github.com/czerwonk/bird_exporter/client" - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/client" + "github.com/sapcc/bird_exporter/protocol" log "github.com/sirupsen/logrus" ) diff --git a/metrics/default_label_strategy.go b/metrics/default_label_strategy.go index c280806..a75fde5 100644 --- a/metrics/default_label_strategy.go +++ b/metrics/default_label_strategy.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" ) // DefaultLabelStrategy defines the labels to add to an metric and its data retrieval method diff --git a/metrics/default_label_strategy_test.go b/metrics/default_label_strategy_test.go index 63da6ea..86e2a4e 100644 --- a/metrics/default_label_strategy_test.go +++ b/metrics/default_label_strategy_test.go @@ -3,7 +3,7 @@ package metrics import ( "testing" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" "github.com/stretchr/testify/assert" ) diff --git a/metrics/generic_exporter.go b/metrics/generic_exporter.go index 937ca11..99f45ef 100644 --- a/metrics/generic_exporter.go +++ b/metrics/generic_exporter.go @@ -1,8 +1,8 @@ package metrics import ( - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/protocol" ) // GenericProtocolMetricExporter exports metrics retrieved from Bird routing daemon diff --git a/metrics/label_strategy.go b/metrics/label_strategy.go index acd2af2..f172deb 100644 --- a/metrics/label_strategy.go +++ b/metrics/label_strategy.go @@ -1,6 +1,6 @@ package metrics -import "github.com/czerwonk/bird_exporter/protocol" +import "github.com/sapcc/bird_exporter/protocol" // LabelStrategy abstracts the label generation for protocol metrics type LabelStrategy interface { diff --git a/metrics/legacy_exporter.go b/metrics/legacy_exporter.go index dbf33d0..8d59466 100644 --- a/metrics/legacy_exporter.go +++ b/metrics/legacy_exporter.go @@ -1,8 +1,8 @@ package metrics import ( - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/protocol" ) type LegacyMetricExporter struct { diff --git a/metrics/legacy_label_strategy.go b/metrics/legacy_label_strategy.go index 324d8ec..9936986 100644 --- a/metrics/legacy_label_strategy.go +++ b/metrics/legacy_label_strategy.go @@ -1,6 +1,6 @@ package metrics -import "github.com/czerwonk/bird_exporter/protocol" +import "github.com/sapcc/bird_exporter/protocol" type LegacyLabelStrategy struct { } diff --git a/metrics/metrics_exporter.go b/metrics/metrics_exporter.go index 1f3cf7e..853b7c8 100644 --- a/metrics/metrics_exporter.go +++ b/metrics/metrics_exporter.go @@ -1,8 +1,8 @@ package metrics import ( - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/protocol" ) type MetricExporter interface { diff --git a/metrics/ospf_exporter.go b/metrics/ospf_exporter.go index 8db4eee..1adbfad 100644 --- a/metrics/ospf_exporter.go +++ b/metrics/ospf_exporter.go @@ -1,9 +1,9 @@ package metrics import ( - "github.com/czerwonk/bird_exporter/client" - "github.com/czerwonk/bird_exporter/protocol" "github.com/prometheus/client_golang/prometheus" + "github.com/sapcc/bird_exporter/client" + "github.com/sapcc/bird_exporter/protocol" log "github.com/sirupsen/logrus" ) diff --git a/parser/bfd.go b/parser/bfd.go index 47037e5..1a7185d 100644 --- a/parser/bfd.go +++ b/parser/bfd.go @@ -6,7 +6,7 @@ import ( "regexp" "strings" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" ) var ( diff --git a/parser/bfd_test.go b/parser/bfd_test.go index 9e6e527..14f57f2 100644 --- a/parser/bfd_test.go +++ b/parser/bfd_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" "github.com/stretchr/testify/assert" ) diff --git a/parser/ospf.go b/parser/ospf.go index 27875ee..8a5579e 100644 --- a/parser/ospf.go +++ b/parser/ospf.go @@ -7,7 +7,7 @@ import ( "bytes" "strings" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" ) type ospfRegex struct { diff --git a/parser/parser.go b/parser/parser.go index 45a48a3..fda08d4 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/czerwonk/bird_exporter/protocol" + "github.com/sapcc/bird_exporter/protocol" ) var ( diff --git a/parser/parser_test.go b/parser/parser_test.go index 15dcead..cde3de9 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/czerwonk/bird_exporter/protocol" "github.com/czerwonk/testutils/assert" + "github.com/sapcc/bird_exporter/protocol" ) func TestEstablishedBgpOldTimeFormat(t *testing.T) { diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7bb4bd7 --- /dev/null +++ b/shell.nix @@ -0,0 +1,18 @@ +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +{ pkgs ? import { } }: + +with pkgs; + +mkShell { + nativeBuildInputs = [ + go-licence-detector + go_1_23 + golangci-lint + gotools # goimports + + # keep this line if you use bash + bashInteractive + ]; +}