diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97e8b7d1..73fe03f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,18 +32,14 @@ jobs: runs-on: ubuntu-24.04 permissions: contents: read - strategy: - fail-fast: false - matrix: - go-version: ["1.22", "1.23", stable] steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Setup Golang Environment - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: - go-version: ${{ matrix.go-version }} + go-version-file: go.mod - name: Run Unit Tests run: make unit-test @@ -57,7 +53,7 @@ jobs: if: ${{ github.event.repository.fork == false }} steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Switch Repository (Nightly) if: (github.event_name == 'schedule') @@ -90,7 +86,7 @@ jobs: run: docker compose up test-no-stream --exit-code-from test-no-stream - name: Create/Update Draft - uses: lucacome/draft-release@00f74370c044c322da6cb52acc707d62c7762c71 # v1.2.4 + uses: lucacome/draft-release@fd099feb33710d1fa27b915a08a7acd6a1fb7fd2 # v2.0.0 id: release-notes with: minor-label: "enhancement" @@ -100,17 +96,16 @@ jobs: if: ${{ github.event_name == 'push' }} - name: Setup Golang Environment - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: - go-version: stable + go-version-file: go.mod if: ${{ github.ref_type == 'tag' }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 with: - version: v2.11.1 # renovate: datasource=github-tags depName=goreleaser/goreleaser + version: v2.12.5 # renovate: datasource=github-tags depName=goreleaser/goreleaser args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_COMMUNITY }} if: ${{ github.ref_type == 'tag' }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b46f37de..e4c2f6ea 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -48,17 +48,17 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Setup Golang Environment - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version: stable if: matrix.language == 'go' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2 + uses: github/codeql-action/init@a8d1ac45b9a34d11fe398d5503176af0d06b303e # v3.30.7 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -70,6 +70,6 @@ jobs: # queries: security-extended,security-and-quality - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2 + uses: github/codeql-action/analyze@a8d1ac45b9a34d11fe398d5503176af0d06b303e # v3.30.7 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 73022eb2..019d08b6 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -24,9 +24,9 @@ jobs: if: ${{ github.event_name != 'merge_group' }} steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Dependency Review - uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 + uses: actions/dependency-review-action@56339e523c0409420f6c2c9a2f4292bbb3c07dd3 # v4.8.0 with: config-file: "nginx/k8s-common/dependency-review-config.yml@main" diff --git a/.github/workflows/fossa.yml b/.github/workflows/fossa.yml index 9cd8da2a..dff10f4b 100644 --- a/.github/workflows/fossa.yml +++ b/.github/workflows/fossa.yml @@ -21,7 +21,7 @@ jobs: if: ${{ github.event.repository.fork == false }} steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Scan uses: fossas/fossa-action@3ebcea1862c6ffbd5cf1b4d0bd6b3fe7bd6f2cac # v1.7.0 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 7d9e31de..76280fb1 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -12,14 +12,14 @@ jobs: pull-requests: write # for actions/labeler to add labels runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: sparse-checkout: | labeler.yml sparse-checkout-cone-mode: false repository: nginx/k8s-common - - uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 + - uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" sync-labels: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 84d06367..ae45a4a6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,27 +25,27 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Setup Golang Environment - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version: stable - name: Lint Go uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v2.3.1 # renovate: datasource=github-tags depName=golangci/golangci-lint + version: v2.5.0 # renovate: datasource=github-tags depName=golangci/golangci-lint actionlint: name: Actionlint runs-on: ubuntu-24.04 steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Lint Actions - uses: reviewdog/action-actionlint@a5524e1c19e62881d79c1f1b9b6f09f16356e281 # v1.65.2 + uses: reviewdog/action-actionlint@95395aac8c053577d0bc67eb7b74936c660c6f66 # v1.67.0 with: actionlint_flags: -shellcheck "" @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout Repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Lint Markdown uses: DavidAnson/markdownlint-cli2-action@992badcdf24e3b8eb7e87ff9287fe931bcb00c6e # v20.0.0 @@ -67,7 +67,7 @@ jobs: name: YAML lint runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Lint YAML uses: reviewdog/action-yamllint@f01d8a48fd8d89f89895499fca2cff09f9e9e8c0 # v1.21.0 diff --git a/.github/workflows/notifications.yml b/.github/workflows/notifications.yml index bb13506e..22a891b2 100644 --- a/.github/workflows/notifications.yml +++ b/.github/workflows/notifications.yml @@ -23,7 +23,7 @@ jobs: actions: read # for 8398a7/action-slack steps: - name: Data - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 continue-on-error: true id: data with: @@ -44,7 +44,7 @@ jobs: } - name: Send Notification - uses: 8398a7/action-slack@1750b5085f3ec60384090fb7c52965ef822e869e # v3.18.0 + uses: 8398a7/action-slack@77eaa4f1c608a7d68b38af4e3f739dcd8cba273e # v3.19.0 with: status: custom custom_payload: | diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 7a152edd..5aa8b84e 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -26,12 +26,12 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2 + uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 with: results_file: results.sarif results_format: sarif @@ -57,6 +57,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2 + uses: github/codeql-action/upload-sarif@a8d1ac45b9a34d11fe398d5503176af0d06b303e # v3.30.7 with: sarif_file: results.sarif diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3f3b6b90..71389e86 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: pull-requests: write # for actions/stale to close stale PRs runs-on: ubuntu-24.04 steps: - - uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0 + - uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: "This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days." diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5753ffc4..0514898c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,11 +5,5 @@ builds: changelog: disable: true -announce: - slack: - enabled: true - channel: "#announcements" - message_template: "NGINX Plus Go Client {{ .Tag }} is out! Check it out: {{ .ReleaseURL }}" - milestones: - close: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3436174d..f45a86af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -24,12 +24,12 @@ repos: - id: detect-private-key - repo: https://github.com/golangci/golangci-lint - rev: v2.3.1 + rev: v2.5.0 hooks: - id: golangci-lint-full - repo: https://github.com/gitleaks/gitleaks - rev: v8.27.2 + rev: v8.28.0 hooks: - id: gitleaks diff --git a/Makefile b/Makefile index 8f72c183..ae4f7742 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # renovate: datasource=github-tags depName=golangci/golangci-lint -GOLANGCI_LINT_VERSION = v2.3.1 +GOLANGCI_LINT_VERSION = v2.5.0 test: unit-test test-integration test-integration-no-stream-block clean diff --git a/client/nginx.go b/client/nginx.go index e6c9c0ad..c6b96b32 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -262,10 +262,10 @@ type ExtendedCacheStats struct { // Connections represents connection related stats. type Connections struct { - Accepted uint64 - Dropped uint64 - Active uint64 - Idle uint64 + Accepted int64 + Dropped int64 + Active int64 + Idle int64 } // Slabs is map of slab stats by zone name. @@ -1002,7 +1002,7 @@ func determineUpdates(updatedServers []UpstreamServer, nginxServers []UpstreamSe } } - return + return toAdd, toRemove, toUpdate } func (client *NginxClient) getIDOfHTTPServer(ctx context.Context, upstream string, name string) (int, error) { @@ -1376,7 +1376,7 @@ func determineStreamUpdates(updatedServers []StreamUpstreamServer, nginxServers } } - return + return toAdd, toRemove, toUpdate } // GetStats gets process, slab, connection, request, ssl, zone, stream zone, upstream and stream upstream related stats from the NGINX Plus API. diff --git a/client/nginx_test.go b/client/nginx_test.go index 33e6416c..f4fd569f 100644 --- a/client/nginx_test.go +++ b/client/nginx_test.go @@ -765,6 +765,66 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) { } } +func TestGetStats_Connections(t *testing.T) { + t.Parallel() + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.RequestURI == "/": + _, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + case r.RequestURI == "/8/": + _, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl","workers"]`)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + case strings.HasPrefix(r.RequestURI, "/8/connections"): + _, err := w.Write([]byte(`{ + "active": -1, + "idle": 3, + "accepted": 5, + "dropped": 2 + }`)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + default: + _, err := w.Write([]byte(`{}`)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + } + })) + + defer ts.Close() + + // Test creating a new client with a supported API version on the server + client, err := NewNginxClient(ts.URL, WithAPIVersion(8), WithCheckAPI()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if client == nil { + t.Fatalf("client is nil") + } + + stats, err := client.GetStats(context.Background()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + testStats := Connections{ + Accepted: 5, + Dropped: 2, + Active: -1, + Idle: 3, + } + + if !reflect.DeepEqual(stats.Connections, testStats) { + t.Fatalf("Connection stats: expected %v, actual %v", testStats, stats.Connections) + } +} + func TestGetStats_SSL(t *testing.T) { t.Parallel() ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/compose.yaml b/compose.yaml index c68d0f67..189267f7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -29,7 +29,7 @@ services: service: nginx test: - image: golang:1.24 + image: golang:1.25 volumes: - type: bind source: ./ diff --git a/docker/Dockerfile b/docker/Dockerfile index 5380a7c3..8e7b07b2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1.17 +# syntax=docker/dockerfile:1.19 FROM debian:12-slim LABEL maintainer="NGINX Docker Maintainers " diff --git a/go.mod b/go.mod index f62a1c16..c1a12e69 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/nginx/nginx-plus-go-client/v3 go 1.24.2 -require golang.org/x/sync v0.16.0 +require golang.org/x/sync v0.17.0 diff --git a/go.sum b/go.sum index 878acfe4..c02bc3ef 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= -golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=