From 74ef7502108de528ae36d5e8067b9d6dd83a4862 Mon Sep 17 00:00:00 2001 From: ADITYATIWARI342005 <142050150+ADITYATIWARI342005@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:47:14 +0530 Subject: [PATCH 1/4] chore(lint): enable promlinter in golangci-lint and update docs -enable promlinter in tools/linter/golangci-lint/.golangci.yml -add brief DEVELOP.md note about Prometheus metrics linting -no code changes required; CI will now report Prometheus metrics lint issues Signed-off-by: ADITYATIWARI342005 <142050150+ADITYATIWARI342005@users.noreply.github.com> --- site/content/en/contributions/DEVELOP.md | 2 ++ tools/linter/golangci-lint/.golangci.yml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/site/content/en/contributions/DEVELOP.md b/site/content/en/contributions/DEVELOP.md index d608c33e2be..560d821d968 100644 --- a/site/content/en/contributions/DEVELOP.md +++ b/site/content/en/contributions/DEVELOP.md @@ -58,6 +58,8 @@ __Note:__ The binaries get generated in the `bin/$OS/$ARCH` directory, for examp __Note:__ The `golangci-lint` configuration resides [here](https://github.com/envoyproxy/gateway/blob/main/tools/linter/golangci-lint/.golangci.yml). +__Prometheus metrics linting:__ We enable `promlinter` via `golangci-lint` to catch common Prometheus client misuse (e.g., using `promauto` in libraries, non-constant metric descriptors, histogram/summary pitfalls). If your change adds or modifies metrics, ensure it passes these checks. + ### Building and Pushing the Image * Run `IMAGE=docker.io/you/gateway-dev make image` to build the docker image. diff --git a/tools/linter/golangci-lint/.golangci.yml b/tools/linter/golangci-lint/.golangci.yml index d004df8f965..5cdfc4f713c 100644 --- a/tools/linter/golangci-lint/.golangci.yml +++ b/tools/linter/golangci-lint/.golangci.yml @@ -47,6 +47,7 @@ linters: - testifylint - unconvert - unparam + - promlinter exclusions: generated: lax presets: @@ -120,8 +121,6 @@ linters: alias: apiextensionsv1 - pkg: sigs.k8s.io/mcs-api/pkg/apis/v1alpha1 alias: mcsapiv1a1 - - pkg: k8s.io/api/certificates/v1beta1 - alias: certificatesv1b1 - pkg: k8s.io/api/(\w+)/(v[\w\d]+) alias: $1$2 # Do not allow unaliased imports of aliased packages. @@ -145,6 +144,9 @@ linters: enable-all: true unparam: check-exported: false + promlinter: + disabled-linters: [] + strict: false output: show-stats: false run: From b436a0aa8826d93e4c5fdf7ae9d22eac09a88b78 Mon Sep 17 00:00:00 2001 From: ADITYATIWARI342005 <142050150+ADITYATIWARI342005@users.noreply.github.com> Date: Fri, 26 Sep 2025 01:45:41 +0530 Subject: [PATCH 2/4] chore(lint): enable promlinter in golangci-lint - Add promlinter to enabled linters in .golangci.yml - Configure promlinter with strict: true - No code changes required; CI will now report Prometheus metrics lint issues Signed-off-by: ADITYATIWARI342005 <142050150+ADITYATIWARI342005@users.noreply.github.com> --- site/content/en/contributions/DEVELOP.md | 1 - tools/linter/golangci-lint/.golangci.yml | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/site/content/en/contributions/DEVELOP.md b/site/content/en/contributions/DEVELOP.md index 560d821d968..96d8427ffc7 100644 --- a/site/content/en/contributions/DEVELOP.md +++ b/site/content/en/contributions/DEVELOP.md @@ -58,7 +58,6 @@ __Note:__ The binaries get generated in the `bin/$OS/$ARCH` directory, for examp __Note:__ The `golangci-lint` configuration resides [here](https://github.com/envoyproxy/gateway/blob/main/tools/linter/golangci-lint/.golangci.yml). -__Prometheus metrics linting:__ We enable `promlinter` via `golangci-lint` to catch common Prometheus client misuse (e.g., using `promauto` in libraries, non-constant metric descriptors, histogram/summary pitfalls). If your change adds or modifies metrics, ensure it passes these checks. ### Building and Pushing the Image diff --git a/tools/linter/golangci-lint/.golangci.yml b/tools/linter/golangci-lint/.golangci.yml index cb986842e6f..53cde5b55f3 100644 --- a/tools/linter/golangci-lint/.golangci.yml +++ b/tools/linter/golangci-lint/.golangci.yml @@ -42,12 +42,12 @@ linters: - gosec - importas - misspell + - promlinter - revive - staticcheck - testifylint - unconvert - unparam - - promlinter exclusions: generated: lax presets: @@ -124,12 +124,16 @@ linters: alias: apiextensionsv1 - pkg: sigs.k8s.io/mcs-api/pkg/apis/v1alpha1 alias: mcsapiv1a1 + - pkg: k8s.io/api/certificates/v1beta1 + alias: certificatesv1b1 - pkg: k8s.io/api/(\w+)/(v[\w\d]+) alias: $1$2 # Do not allow unaliased imports of aliased packages. no-unaliased: true # Do not allow non-required aliases. no-extra-aliases: false + promlinter: + strict: true revive: # TODO: enable if-return check rules: @@ -147,11 +151,8 @@ linters: enable-all: true unparam: check-exported: false - promlinter: - disabled-linters: [] - strict: false output: show-stats: false run: timeout: 10m -version: "2" +version: "2" \ No newline at end of file From 5f166d6b28b10e010b22127cd62dadf7d602a6a2 Mon Sep 17 00:00:00 2001 From: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> Date: Fri, 26 Sep 2025 01:49:00 +0530 Subject: [PATCH 3/4] Update DEVELOP.md, revert unnecessary changes Signed-off-by: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> --- site/content/en/contributions/DEVELOP.md | 1 - 1 file changed, 1 deletion(-) diff --git a/site/content/en/contributions/DEVELOP.md b/site/content/en/contributions/DEVELOP.md index 96d8427ffc7..d608c33e2be 100644 --- a/site/content/en/contributions/DEVELOP.md +++ b/site/content/en/contributions/DEVELOP.md @@ -58,7 +58,6 @@ __Note:__ The binaries get generated in the `bin/$OS/$ARCH` directory, for examp __Note:__ The `golangci-lint` configuration resides [here](https://github.com/envoyproxy/gateway/blob/main/tools/linter/golangci-lint/.golangci.yml). - ### Building and Pushing the Image * Run `IMAGE=docker.io/you/gateway-dev make image` to build the docker image. From 838d8885e9b86bd01d23b5e71756e42ffba9c453 Mon Sep 17 00:00:00 2001 From: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> Date: Fri, 26 Sep 2025 11:12:18 +0530 Subject: [PATCH 4/4] Update .golangci.yml, add new line to pass build/lint test Signed-off-by: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com> --- tools/linter/golangci-lint/.golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linter/golangci-lint/.golangci.yml b/tools/linter/golangci-lint/.golangci.yml index 53cde5b55f3..7ea11d4ffe9 100644 --- a/tools/linter/golangci-lint/.golangci.yml +++ b/tools/linter/golangci-lint/.golangci.yml @@ -155,4 +155,4 @@ output: show-stats: false run: timeout: 10m -version: "2" \ No newline at end of file +version: "2"