diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml new file mode 100644 index 000000000..8a9a13016 --- /dev/null +++ b/.github/actionlint.yaml @@ -0,0 +1,2 @@ +# actionlint configuration +# https://github.com/rhysd/actionlint/blob/main/docs/config.md diff --git a/.github/settings.yml b/.github/settings.yml index e78499030..d5c2434e1 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -1,4 +1,3 @@ ---- branches: - name: main protection: diff --git a/.github/stale.yml b/.github/stale.yml index d9fa51d57..e7da8955d 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -68,10 +68,7 @@ pull: daysUntilClose: 14 daysUntilStale: 60 markComment: > - Hello 👋 Looks like there was no activity on this amazing PR for the last 60 days. - **Do you mind updating us on the status?** Is there anything we can help with? If you plan to still work on it, just comment on this PR or push a commit. Thanks! 🤗 - - If there will be no activity in the next 2 weeks, this issue will be closed (we can always reopen a PR if you get back to this!). + Hello 👋 Looks like there was no activity on this amazing PR for the last 60 days. **Do you mind updating us on the status?** Is there anything we can help with? If you plan to still work on it, just comment on this PR or push a commit. Thanks! 🤗 #magic___^_^___line If there will be no activity in the next 2 weeks, this issue will be closed (we can always reopen a PR if you get back to this!). # unmarkComment: No need for unmark comment. closeComment: > Closing for now as promised, let us know if you need this to be reopened! 🤗 @@ -79,10 +76,7 @@ issues: daysUntilClose: 90 daysUntilStale: 180 markComment: > - Hello 👋 Looks like there was no activity on this issue for the last 3 months. - **Do you mind updating us on the status?** Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 - - If there will be no activity in the next 4 weeks, this issue will be closed (we can always reopen an issue if we need!). + Hello 👋 Looks like there was no activity on this issue for the last 3 months. **Do you mind updating us on the status?** Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 #magic___^_^___line If there will be no activity in the next 4 weeks, this issue will be closed (we can always reopen an issue if we need!). # unmarkComment: No need for unmark comment. closeComment: > Closing for now as promised, let us know if you need this to be reopened! 🤗 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d830fce6d..7658ee666 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL" on: push: - branches: [ main ] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: [main] schedule: - cron: '31 21 * * 6' @@ -40,39 +40,39 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'go' ] + language: ['go'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support steps: - - name: Checkout repository - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - #- run: | - # make bootstrap - # make release + #- run: | + # make bootstrap + # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5 diff --git a/.github/workflows/container_description.yml b/.github/workflows/container_description.yml index c7c7ac776..74f72d245 100644 --- a/.github/workflows/container_description.yml +++ b/.github/workflows/container_description.yml @@ -1,4 +1,3 @@ ---- name: Push README to Docker Hub on: push: @@ -6,7 +5,7 @@ on: - "README.md" - "README-containers.md" - ".github/workflows/container_description.yml" - branches: [ main, master ] + branches: [main, master] permissions: contents: read @@ -22,7 +21,7 @@ jobs: with: persist-credentials: false - name: Set docker hub repo name - run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV + run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> "$GITHUB_ENV" - name: Push README to Dockerhub uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1 env: @@ -46,9 +45,9 @@ jobs: with: persist-credentials: false - name: Set quay.io org name - run: echo "DOCKER_REPO=$(echo quay.io/${GITHUB_REPOSITORY_OWNER} | tr -d '-')" >> $GITHUB_ENV + run: echo "DOCKER_REPO=$(echo "quay.io/${GITHUB_REPOSITORY_OWNER}" | tr -d '-')" >> "$GITHUB_ENV" - name: Set quay.io repo name - run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV + run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> "$GITHUB_ENV" - name: Push README to quay.io uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1 env: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index cde2b76f2..e3b828b02 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,4 +1,3 @@ ---- # This action is synced from https://github.com/prometheus/prometheus name: golangci-lint on: @@ -12,14 +11,14 @@ on: - ".golangci.yml" pull_request: -permissions: # added using https://github.com/step-security/secure-repo +permissions: # added using https://github.com/step-security/secure-repo contents: read jobs: golangci: permissions: - contents: read # for actions/checkout to fetch code - pull-requests: read # for golangci/golangci-lint-action to fetch pull requests + contents: read # for actions/checkout to fetch code + pull-requests: read # for golangci/golangci-lint-action to fetch pull requests name: lint runs-on: ubuntu-latest steps: diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index e8b3485ae..8d666a8e7 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -9,7 +9,7 @@ on: schedule: - cron: '22 1 * * 0' push: - branches: [ "main" ] + branches: ["main"] # Declare default permissions as read only. permissions: read-all diff --git a/.github/workflows/update-go-versions.yml b/.github/workflows/update-go-versions.yml index 3e2a05139..4685af2c2 100644 --- a/.github/workflows/update-go-versions.yml +++ b/.github/workflows/update-go-versions.yml @@ -1,4 +1,3 @@ ---- name: Generate Metric files for new Go version on: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 99072ff19..2185a3d5b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,4 +1,3 @@ ---- name: Validate on: pull_request: @@ -22,16 +21,16 @@ jobs: name: Fetch supported Go versions runs-on: ubuntu-latest outputs: - supported_versions: ${{ steps.matrix.outputs.supported_versions }} + supported_versions: ${{ steps.matrix.outputs.supported_versions }} steps: - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Read supported_go_versions.txt id: matrix run: | - versions=$(cat supported_go_versions.txt) - matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" - echo "supported_versions=$matrix" >> $GITHUB_OUTPUT + versions=$(cat supported_go_versions.txt) + matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" + echo "supported_versions=$matrix" >> "$GITHUB_OUTPUT" test: name: Tests (${{ matrix.go_version }}) @@ -69,3 +68,22 @@ jobs: - name: Run style and unused if: ${{ matrix.go_version == '1.22' }} run: make style unused + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Set up Go + uses: actions/setup-go@v6.0.0 + with: + go-version: stable + check-latest: true + + - name: Lint YAML files + run: make lint-yaml + + - name: Lint GitHub Actions workflows + run: make lint-actions diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 000000000..65f1cfcdb --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,17 @@ +# yamlfmt configuration +# https://github.com/google/yamlfmt + +doublestar: true + +exclude: + - "**/testdata/**" + - "**/*testdata*/**" + +gitignore_excludes: true + +formatter: + type: basic + indent: 2 + include_document_start: false + retain_line_breaks: true + max_line_length: 0 diff --git a/.yamllint b/.yamllint new file mode 100644 index 000000000..8d09c375f --- /dev/null +++ b/.yamllint @@ -0,0 +1,25 @@ +--- +extends: default +ignore: | + **/node_modules + +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 diff --git a/Makefile b/Makefile index ff01ce882..37755cd50 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,9 @@ BUF_VERSION ?= v1.39.0 $(BUF): go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) +.DEFAULT_GOAL := default +default: precheck style check_license format lint unused test + .PHONY: deps deps: $(MAKE) common-deps @@ -45,7 +48,10 @@ generate-go-collector-test-files: go mod tidy .PHONY: fmt -fmt: common-format +fmt: common-format format-yaml fix-crlf + +.PHONY: format +format: fmt .PHONY: proto proto: ## Regenerate Go from remote write proto. @@ -66,6 +72,30 @@ test-exp: test-exp-short: cd exp && $(GOTEST) -short $(GOOPTS) $(pkgs) +YAMLFMT := $(FIRST_GOPATH)/bin/yamlfmt +ACTIONLINT := $(FIRST_GOPATH)/bin/actionlint + +$(YAMLFMT): + go install github.com/google/yamlfmt/cmd/yamlfmt@latest + +$(ACTIONLINT): + go install github.com/rhysd/actionlint/cmd/actionlint@latest + +.PHONY: format-yaml +format-yaml: $(YAMLFMT) + @echo ">> formatting YAML files" + $(YAMLFMT) -dstar '**/*.yml' '**/*.yaml' + +.PHONY: lint +lint: common-lint common-yamllint common-lint-fix lint-actions + +lint-yaml: common-yamllint + +.PHONY: lint-actions +lint-actions: $(ACTIONLINT) + @echo ">> linting GitHub Actions workflows" + $(ACTIONLINT) + .PHONY: check-crlf check-crlf: @echo ">> checking for CRLF line endings" diff --git a/api/prometheus/v1/api_bench_test.go b/api/prometheus/v1/api_bench_test.go index f1f8000ef..97f502e56 100644 --- a/api/prometheus/v1/api_bench_test.go +++ b/api/prometheus/v1/api_bench_test.go @@ -100,7 +100,7 @@ func generateData(timeseries, datapoints int) (floatMatrix, histogramMatrix mode floatMatrix = append(floatMatrix, fss) histogramMatrix = append(histogramMatrix, hss) } - return + return floatMatrix, histogramMatrix } func BenchmarkSamplesJsonSerialization(b *testing.B) { diff --git a/exp/api/remote/genproto/buf.gen.yaml b/exp/api/remote/genproto/buf.gen.yaml index 63e34a0d7..64369538a 100644 --- a/exp/api/remote/genproto/buf.gen.yaml +++ b/exp/api/remote/genproto/buf.gen.yaml @@ -2,20 +2,20 @@ version: v2 plugins: -- remote: buf.build/protocolbuffers/go:v1.31.0 - out: . - opt: - - Mio/prometheus/write/v2/types.proto=./v2 + - remote: buf.build/protocolbuffers/go:v1.31.0 + out: . + opt: + - Mio/prometheus/write/v2/types.proto=./v2 -# vtproto for efficiency utilities like pooling etc. -# https://buf.build/community/planetscale-vtprotobuf?version=v0.6.0 -- remote: buf.build/community/planetscale-vtprotobuf:v0.6.0 - out: . - opt: - - Mio/prometheus/write/v2/types.proto=./v2 - - features=marshal+unmarshal+size + # vtproto for efficiency utilities like pooling etc. + # https://buf.build/community/planetscale-vtprotobuf?version=v0.6.0 + - remote: buf.build/community/planetscale-vtprotobuf:v0.6.0 + out: . + opt: + - Mio/prometheus/write/v2/types.proto=./v2 + - features=marshal+unmarshal+size inputs: -- module: buf.build/prometheus/prometheus:5b212ab78fb7460e831cf7ff2d83e385 - types: - - "io.prometheus.write.v2.Request" + - module: buf.build/prometheus/prometheus:5b212ab78fb7460e831cf7ff2d83e385 + types: + - "io.prometheus.write.v2.Request" diff --git a/internal/github.com/golang/gddo/httputil/header/header.go b/internal/github.com/golang/gddo/httputil/header/header.go index 8547c8dfd..820bf436a 100644 --- a/internal/github.com/golang/gddo/httputil/header/header.go +++ b/internal/github.com/golang/gddo/httputil/header/header.go @@ -90,7 +90,7 @@ loop: s = skipSpace(s[1:]) } } - return + return specs } func skipSpace(s string) (rest string) { diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index 92b61ca85..efe06f758 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -53,7 +53,7 @@ func (c *ClusterManager) ReallyExpensiveAssessmentOfTheSystemState() ( "foo.example.org": 6.023e23, "bar.example.org": 3.14, } - return + return oomCountByHost, ramUsageByHost } // ClusterManagerCollector implements the Collector interface. diff --git a/prometheus/graphite/bridge_test.go b/prometheus/graphite/bridge_test.go index a00fff528..b5c772ce9 100644 --- a/prometheus/graphite/bridge_test.go +++ b/prometheus/graphite/bridge_test.go @@ -342,7 +342,7 @@ func stringToLines(s string) (lines []string, err error) { lines = append(lines, scanner.Text()) } err = scanner.Err() - return + return lines, err } func TestPush(t *testing.T) { diff --git a/prometheus/promhttp/instrument_server.go b/prometheus/promhttp/instrument_server.go index 9332b0249..66878b80a 100644 --- a/prometheus/promhttp/instrument_server.go +++ b/prometheus/promhttp/instrument_server.go @@ -366,7 +366,7 @@ func checkLabels(c prometheus.Collector) (code, method bool) { panic("metric partitioned with non-supported labels") } } - return + return code, method } func isLabelCurried(c prometheus.Collector, label string) bool { diff --git a/prometheus/promhttp/instrument_server_test.go b/prometheus/promhttp/instrument_server_test.go index 45640e605..e769cb9ba 100644 --- a/prometheus/promhttp/instrument_server_test.go +++ b/prometheus/promhttp/instrument_server_test.go @@ -324,7 +324,7 @@ func TestLabels(t *testing.T) { panic("metric partitioned with non-supported labels for this test") } } - return + return gotCode, gotMethod } equalLabels := func(gotLabels, wantLabels prometheus.Labels) bool { if len(gotLabels) != len(wantLabels) { diff --git a/prometheus/summary_test.go b/prometheus/summary_test.go index 440237206..2067449b4 100644 --- a/prometheus/summary_test.go +++ b/prometheus/summary_test.go @@ -422,7 +422,7 @@ func getBounds(vars []float64, q, Îĩ float64) (minBound, maxBound float64) { if upper < len(vars) { maxBound = vars[upper-1] } - return + return minBound, maxBound } func TestSummaryVecCreatedTimestampWithDeletes(t *testing.T) { diff --git a/tutorials/whatsup/internal/acceptance_test.go b/tutorials/whatsup/internal/acceptance_test.go index 38533c495..57848a9b9 100644 --- a/tutorials/whatsup/internal/acceptance_test.go +++ b/tutorials/whatsup/internal/acceptance_test.go @@ -78,5 +78,4 @@ func TestAcceptance(t *testing.T) { if gotErr { fmt.Println("Got this response from ", fmt.Sprintf("http://localhost:%v", WhatsupPort), ":", metrics) } - } diff --git a/tutorials/whatsup/main.go b/tutorials/whatsup/main.go index 5943eefb0..15ebd4e72 100644 --- a/tutorials/whatsup/main.go +++ b/tutorials/whatsup/main.go @@ -73,7 +73,7 @@ func runMain(opts internal.Config) (err error) { m := http.NewServeMux() // Create HTTP handler for Prometheus metrics. // TODO - //m.Handle("/metrics", ... + // m.Handle("/metrics", ... promClient, err := api.NewClient(api.Config{ Client: &http.Client{Transport: instrumentRoundTripper(nil, "prometheus", http.DefaultTransport)},