From 5473734e253db0d02ad611ceb19875a1c14c8155 Mon Sep 17 00:00:00 2001 From: Oliver O'Mahony Date: Thu, 10 Aug 2023 14:03:21 +0100 Subject: [PATCH 1/8] added version 9 of API and new worker metrics. Updated pipeline for R30 --- Makefile | 6 ++++-- client/nginx.go | 37 +++++++++++++++++++++++++++++++++++-- docker/Dockerfile | 5 +++-- docker/nginx.conf | 7 +------ docker/nginx_no_stream.conf | 6 +----- docker/test.conf | 1 - tests/client_test.go | 4 ++++ 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index e2fb6c12..f8d92d57 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ -NGINX_PLUS_VERSION=r29 +NGINX_PLUS_VERSION=r30 DOCKER_NETWORK?=test DOCKER_NETWORK_ALIAS=nginx-plus-test DOCKER_NGINX_PLUS?=nginx-plus DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper +NGINX_REPO_URL?=pkgs-test.nginx.com +NGINX_CERT_DIR?=docker GOLANG_CONTAINER=golang:1.19 @@ -16,7 +18,7 @@ lint: docker run --pull always --rm -v $(shell pwd):/nginx-plus-go-client -w /nginx-plus-go-client -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run docker-build: - docker build --secret id=nginx-repo.crt,src=docker/nginx-repo.crt --secret id=nginx-repo.key,src=docker/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) -t nginx-plus:$(NGINX_PLUS_VERSION) docker + docker build --secret id=nginx-repo.crt,src=${NGINX_CERT_DIR}/nginx-repo.crt --secret id=nginx-repo.key,src=${NGINX_CERT_DIR}/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) --build-arg NGINX_REPO_URL=$(NGINX_REPO_URL) -t nginx-plus:$(NGINX_PLUS_VERSION) docker run-nginx-plus: docker network create --driver bridge $(DOCKER_NETWORK) diff --git a/client/nginx.go b/client/nginx.go index 11cf093a..25f9d1ab 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -15,7 +15,7 @@ import ( const ( // APIVersion is the default version of NGINX Plus API supported by the client. - APIVersion = 8 + APIVersion = 9 pathNotFoundCode = "PathNotFound" streamContext = true @@ -24,7 +24,7 @@ const ( ) var ( - supportedAPIVersions = versions{4, 5, 6, 7, 8} + supportedAPIVersions = versions{4, 5, 6, 7, 8, 9} // Default values for servers in Upstreams. defaultMaxConns = 0 @@ -132,6 +132,7 @@ type Stats struct { HTTPLimitRequests HTTPLimitRequests HTTPLimitConnections HTTPLimitConnections StreamLimitConnections StreamLimitConnections + Workers []*Workers } // NginxInfo contains general information about NGINX Plus. @@ -494,6 +495,19 @@ type HTTPLimitConnections map[string]LimitConnection // StreamLimitConnections represents limit connections related stats type StreamLimitConnections map[string]LimitConnection +// Workers represents worker connections related stats +type Workers struct { + ID int + ProcessID uint64 `json:"pid"` + HTTP WorkersHTTP `json:"http"` + Connections Connections +} + +// WorkersHTTP represents HTTP worker connections +type WorkersHTTP struct { + HTTPRequests HTTPRequests `json:"requests"` +} + // NewNginxClient creates an NginxClient with the latest supported version. func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient, error) { return NewNginxClientWithVersion(httpClient, apiEndpoint, APIVersion) @@ -1186,6 +1200,11 @@ func (client *NginxClient) GetStats() (*Stats, error) { return nil, fmt.Errorf("failed to get stats: %w", err) } + workers, err := client.GetWorkers() + if err != nil { + return nil, fmt.Errorf("failed to get stats: %w", err) + } + return &Stats{ NginxInfo: *info, Caches: *caches, @@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) { HTTPLimitRequests: *limitReqs, HTTPLimitConnections: *limitConnsHTTP, StreamLimitConnections: *limitConnsStream, + Workers: workers, }, nil } @@ -1639,3 +1659,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections, } return &limitConns, nil } + +// GetWorkers returns workers stats. +func (client *NginxClient) GetWorkers() ([]*Workers, error) { + var workers []*Workers + if client.version < 8 { + return workers, nil + } + err := client.get("workers", &workers) + if err != nil { + return nil, fmt.Errorf("failed to get workers: %w", err) + } + return workers, nil +} diff --git a/docker/Dockerfile b/docker/Dockerfile index 9464155a..125eb316 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,9 +1,10 @@ # syntax=docker/dockerfile:1.4 -FROM debian:bullseye-slim +FROM debian:bullseye LABEL maintainer="NGINX Docker Maintainers " ARG NGINX_PLUS_VERSION +ARG NGINX_REPO_URL # Install NGINX Plus # Download certificate and key from the customer portal (https://my.f5.com) @@ -16,7 +17,7 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode curl -fsSL https://cs.nginx.com/static/keys/nginx_signing.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nginx_signing.gpg curl -fsSL -o /etc/apt/apt.conf.d/90pkgs-nginx https://cs.nginx.com/static/files/90pkgs-nginx DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release) - printf "%s\n" "deb https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION^^}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list + printf "%s\n" "deb [trusted=yes] https://${NGINX_REPO_URL}/plus/${NGINX_PLUS_VERSION^^}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list apt-get update apt-get install -y nginx-plus apt-get remove --purge --auto-remove -y gnupg diff --git a/docker/nginx.conf b/docker/nginx.conf index d5446aaa..329fc546 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,16 +1,14 @@ user nginx; -worker_processes auto; +worker_processes 4; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; - events { worker_connections 1024; } - http { include /etc/nginx/mime.types; default_type application/octet-stream; @@ -22,12 +20,9 @@ http { access_log /var/log/nginx/access.log main; sendfile on; - #tcp_nopush on; keepalive_timeout 65; - #gzip on; - keyval_zone zone=zone_one:32k; keyval $arg_text $text zone=zone_one; diff --git a/docker/nginx_no_stream.conf b/docker/nginx_no_stream.conf index 5e076aad..01e69fe9 100644 --- a/docker/nginx_no_stream.conf +++ b/docker/nginx_no_stream.conf @@ -1,6 +1,6 @@ user nginx; -worker_processes auto; +worker_processes 4; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; @@ -10,7 +10,6 @@ events { worker_connections 1024; } - http { include /etc/nginx/mime.types; default_type application/octet-stream; @@ -22,11 +21,8 @@ http { access_log /var/log/nginx/access.log main; sendfile on; - #tcp_nopush on; keepalive_timeout 65; - #gzip on; - include /etc/nginx/conf.d/*.conf; } diff --git a/docker/test.conf b/docker/test.conf index 65bba6bf..5eece1ee 100644 --- a/docker/test.conf +++ b/docker/test.conf @@ -27,7 +27,6 @@ server { health_check interval=10 fails=3 passes=1; } status_zone test; - } upstream test-drain { diff --git a/tests/client_test.go b/tests/client_test.go index dff8383a..27fb84e9 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -627,6 +627,10 @@ func TestStats(t *testing.T) { t.Errorf("Bad connections: %v", stats.Connections) } + if len(stats.Workers) < 1 { + t.Errorf("Bad workers: %v", stats.Workers) + } + if val, ok := stats.Caches[cacheZone]; ok { if val.MaxSize != 104857600 { // 100MiB t.Errorf("Cache max size stats missing: %v", val.Size) From 2a5bed8e42df1b21c600882967f281b2cddf46bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:36:08 -0700 Subject: [PATCH 2/8] Bump goreleaser/goreleaser-action from 4.3.0 to 4.4.0 (#146) Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 4.3.0 to 4.4.0. - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/336e29918d653399e599bfca99fadc1d7ffbc9f7...3fa32b8bb5620a2c1afe798654bbad59f9da4906) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be6de2c8..043a669f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: if: ${{ github.event_name == 'push' }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0 + uses: goreleaser/goreleaser-action@3fa32b8bb5620a2c1afe798654bbad59f9da4906 # v4.4.0 with: version: latest args: release --clean From b4472396cbd0619515ecfcf2900a4c8f0079ec1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:37:57 +0000 Subject: [PATCH 3/8] Bump actions/setup-go from 4.0.1 to 4.1.0 (#145) Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4.0.1 to 4.1.0. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/fac708d6674e30b6ba41289acaab6d4b75aa0753...93397bea11091df50f3d7e59dc26a7711a8bcfbe) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 24790407..c592fd5e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: Setup Golang Environment - uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version-file: go.mod From e5a44686633ac52859110e5dca0cd5f648127af0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:39:37 +0000 Subject: [PATCH 4/8] Bump actions/dependency-review-action from 3.0.6 to 3.0.7 (#144) Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 3.0.6 to 3.0.7. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/1360a344ccb0ab6e9475edef90ad2f46bf8003b1...7d90b4f05fea31dde1c4a1fb3fa787e197ea93ab) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependency-review.yml | 2 +- Makefile | 4 +--- docker/Dockerfile | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index c6910e4d..9097ac70 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -22,6 +22,6 @@ jobs: uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: "Dependency Review" - uses: actions/dependency-review-action@1360a344ccb0ab6e9475edef90ad2f46bf8003b1 # v3.0.6 + uses: actions/dependency-review-action@7d90b4f05fea31dde1c4a1fb3fa787e197ea93ab # v3.0.7 with: config-file: "nginxinc/k8s-common/dependency-review-config.yml@main" diff --git a/Makefile b/Makefile index f8d92d57..d070c53a 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,6 @@ DOCKER_NETWORK?=test DOCKER_NETWORK_ALIAS=nginx-plus-test DOCKER_NGINX_PLUS?=nginx-plus DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper -NGINX_REPO_URL?=pkgs-test.nginx.com -NGINX_CERT_DIR?=docker GOLANG_CONTAINER=golang:1.19 @@ -18,7 +16,7 @@ lint: docker run --pull always --rm -v $(shell pwd):/nginx-plus-go-client -w /nginx-plus-go-client -v $(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v $(shell go env GOPATH)/pkg:/go/pkg golangci/golangci-lint:latest golangci-lint --color always run docker-build: - docker build --secret id=nginx-repo.crt,src=${NGINX_CERT_DIR}/nginx-repo.crt --secret id=nginx-repo.key,src=${NGINX_CERT_DIR}/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) --build-arg NGINX_REPO_URL=$(NGINX_REPO_URL) -t nginx-plus:$(NGINX_PLUS_VERSION) docker + docker build --secret id=nginx-repo.crt,src=docker/nginx-repo.crt --secret id=nginx-repo.key,src=docker/nginx-repo.key --build-arg NGINX_PLUS_VERSION=$(NGINX_PLUS_VERSION) -t nginx-plus:$(NGINX_PLUS_VERSION) docker run-nginx-plus: docker network create --driver bridge $(DOCKER_NETWORK) diff --git a/docker/Dockerfile b/docker/Dockerfile index 125eb316..9464155a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,10 +1,9 @@ # syntax=docker/dockerfile:1.4 -FROM debian:bullseye +FROM debian:bullseye-slim LABEL maintainer="NGINX Docker Maintainers " ARG NGINX_PLUS_VERSION -ARG NGINX_REPO_URL # Install NGINX Plus # Download certificate and key from the customer portal (https://my.f5.com) @@ -17,7 +16,7 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode curl -fsSL https://cs.nginx.com/static/keys/nginx_signing.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nginx_signing.gpg curl -fsSL -o /etc/apt/apt.conf.d/90pkgs-nginx https://cs.nginx.com/static/files/90pkgs-nginx DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release) - printf "%s\n" "deb [trusted=yes] https://${NGINX_REPO_URL}/plus/${NGINX_PLUS_VERSION^^}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list + printf "%s\n" "deb https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION^^}/debian ${DEBIAN_VERSION} nginx-plus" > /etc/apt/sources.list.d/nginx-plus.list apt-get update apt-get install -y nginx-plus apt-get remove --purge --auto-remove -y gnupg From 7754b4c7615c3eae42731a857742ec430b55b00f Mon Sep 17 00:00:00 2001 From: Oliver O'Mahony Date: Tue, 15 Aug 2023 18:06:44 +0100 Subject: [PATCH 5/8] issue with R30 --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9464155a..b77adaca 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.4 -FROM debian:bullseye-slim +FROM debian:bullseye LABEL maintainer="NGINX Docker Maintainers " From 7f1bb963b37605d68e8956bdac9b4f2075f4b4f2 Mon Sep 17 00:00:00 2001 From: Oliver O'Mahony Date: Thu, 17 Aug 2023 11:32:14 +0100 Subject: [PATCH 6/8] code review comments 1 of 2 --- client/nginx.go | 2 +- docker/nginx.conf | 9 +++++++-- docker/nginx_no_stream.conf | 8 ++++++-- docker/test.conf | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/client/nginx.go b/client/nginx.go index 25f9d1ab..c6fb9f68 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -1663,7 +1663,7 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections, // GetWorkers returns workers stats. func (client *NginxClient) GetWorkers() ([]*Workers, error) { var workers []*Workers - if client.version < 8 { + if client.version < 9 { return workers, nil } err := client.get("workers", &workers) diff --git a/docker/nginx.conf b/docker/nginx.conf index 329fc546..a94915e2 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,14 +1,16 @@ user nginx; -worker_processes 4; +worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; + events { worker_connections 1024; } + http { include /etc/nginx/mime.types; default_type application/octet-stream; @@ -20,9 +22,12 @@ http { access_log /var/log/nginx/access.log main; sendfile on; + #tcp_nopush on; keepalive_timeout 65; + #gzip on; + keyval_zone zone=zone_one:32k; keyval $arg_text $text zone=zone_one; @@ -56,4 +61,4 @@ stream { zone_sync; zone_sync_server nginx-plus-test:7777 resolve; } -} +} \ No newline at end of file diff --git a/docker/nginx_no_stream.conf b/docker/nginx_no_stream.conf index 01e69fe9..358f0194 100644 --- a/docker/nginx_no_stream.conf +++ b/docker/nginx_no_stream.conf @@ -1,6 +1,6 @@ user nginx; -worker_processes 4; +worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; @@ -10,6 +10,7 @@ events { worker_connections 1024; } + http { include /etc/nginx/mime.types; default_type application/octet-stream; @@ -21,8 +22,11 @@ http { access_log /var/log/nginx/access.log main; sendfile on; + #tcp_nopush on; keepalive_timeout 65; + #gzip on; + include /etc/nginx/conf.d/*.conf; -} +} \ No newline at end of file diff --git a/docker/test.conf b/docker/test.conf index 5eece1ee..be4e02d7 100644 --- a/docker/test.conf +++ b/docker/test.conf @@ -27,10 +27,11 @@ server { health_check interval=10 fails=3 passes=1; } status_zone test; + } upstream test-drain { zone test-drain 64k; server 127.0.0.1:9001 drain; -} +} \ No newline at end of file From d21716ce587a09b32661189977b38412aa67b0d9 Mon Sep 17 00:00:00 2001 From: Oliver O'Mahony Date: Thu, 24 Aug 2023 13:08:56 +0100 Subject: [PATCH 7/8] added newlines back in --- docker/nginx.conf | 2 +- docker/nginx_no_stream.conf | 2 +- docker/test.conf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/nginx.conf b/docker/nginx.conf index bc286d92..9bd4a649 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -61,4 +61,4 @@ stream { zone_sync; zone_sync_server nginx-plus-test:7777 resolve; } -} \ No newline at end of file +} diff --git a/docker/nginx_no_stream.conf b/docker/nginx_no_stream.conf index 13c80a6a..34859140 100644 --- a/docker/nginx_no_stream.conf +++ b/docker/nginx_no_stream.conf @@ -29,4 +29,4 @@ http { #gzip on; include /etc/nginx/conf.d/*.conf; -} \ No newline at end of file +} diff --git a/docker/test.conf b/docker/test.conf index be4e02d7..65bba6bf 100644 --- a/docker/test.conf +++ b/docker/test.conf @@ -34,4 +34,4 @@ upstream test-drain { zone test-drain 64k; server 127.0.0.1:9001 drain; -} \ No newline at end of file +} From 564bbba2f45d7128f7d4a7c63f014525b548a03e Mon Sep 17 00:00:00 2001 From: Oliver O'Mahony Date: Thu, 24 Aug 2023 13:24:15 +0100 Subject: [PATCH 8/8] updated readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d4b04da..d86bc671 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ the API was first introduced. | 6 | R20 | | 7 | R25 | | 8 | R27 | +| 9 | R30 | ## Using the Client