Skip to content

Commit 5473734

Browse files
committed
added version 9 of API and new worker metrics. Updated pipeline for R30
1 parent 8460a36 commit 5473734

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
NGINX_PLUS_VERSION=r29
1+
NGINX_PLUS_VERSION=r30
22
DOCKER_NETWORK?=test
33
DOCKER_NETWORK_ALIAS=nginx-plus-test
44
DOCKER_NGINX_PLUS?=nginx-plus
55
DOCKER_NGINX_PLUS_HELPER?=nginx-plus-helper
6+
NGINX_REPO_URL?=pkgs-test.nginx.com
7+
NGINX_CERT_DIR?=docker
68

79
GOLANG_CONTAINER=golang:1.19
810

@@ -16,7 +18,7 @@ lint:
1618
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
1719

1820
docker-build:
19-
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
21+
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
2022

2123
run-nginx-plus:
2224
docker network create --driver bridge $(DOCKER_NETWORK)

client/nginx.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const (
1717
// APIVersion is the default version of NGINX Plus API supported by the client.
18-
APIVersion = 8
18+
APIVersion = 9
1919

2020
pathNotFoundCode = "PathNotFound"
2121
streamContext = true
@@ -24,7 +24,7 @@ const (
2424
)
2525

2626
var (
27-
supportedAPIVersions = versions{4, 5, 6, 7, 8}
27+
supportedAPIVersions = versions{4, 5, 6, 7, 8, 9}
2828

2929
// Default values for servers in Upstreams.
3030
defaultMaxConns = 0
@@ -132,6 +132,7 @@ type Stats struct {
132132
HTTPLimitRequests HTTPLimitRequests
133133
HTTPLimitConnections HTTPLimitConnections
134134
StreamLimitConnections StreamLimitConnections
135+
Workers []*Workers
135136
}
136137

137138
// NginxInfo contains general information about NGINX Plus.
@@ -494,6 +495,19 @@ type HTTPLimitConnections map[string]LimitConnection
494495
// StreamLimitConnections represents limit connections related stats
495496
type StreamLimitConnections map[string]LimitConnection
496497

498+
// Workers represents worker connections related stats
499+
type Workers struct {
500+
ID int
501+
ProcessID uint64 `json:"pid"`
502+
HTTP WorkersHTTP `json:"http"`
503+
Connections Connections
504+
}
505+
506+
// WorkersHTTP represents HTTP worker connections
507+
type WorkersHTTP struct {
508+
HTTPRequests HTTPRequests `json:"requests"`
509+
}
510+
497511
// NewNginxClient creates an NginxClient with the latest supported version.
498512
func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient, error) {
499513
return NewNginxClientWithVersion(httpClient, apiEndpoint, APIVersion)
@@ -1186,6 +1200,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
11861200
return nil, fmt.Errorf("failed to get stats: %w", err)
11871201
}
11881202

1203+
workers, err := client.GetWorkers()
1204+
if err != nil {
1205+
return nil, fmt.Errorf("failed to get stats: %w", err)
1206+
}
1207+
11891208
return &Stats{
11901209
NginxInfo: *info,
11911210
Caches: *caches,
@@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
12041223
HTTPLimitRequests: *limitReqs,
12051224
HTTPLimitConnections: *limitConnsHTTP,
12061225
StreamLimitConnections: *limitConnsStream,
1226+
Workers: workers,
12071227
}, nil
12081228
}
12091229

@@ -1639,3 +1659,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections,
16391659
}
16401660
return &limitConns, nil
16411661
}
1662+
1663+
// GetWorkers returns workers stats.
1664+
func (client *NginxClient) GetWorkers() ([]*Workers, error) {
1665+
var workers []*Workers
1666+
if client.version < 8 {
1667+
return workers, nil
1668+
}
1669+
err := client.get("workers", &workers)
1670+
if err != nil {
1671+
return nil, fmt.Errorf("failed to get workers: %w", err)
1672+
}
1673+
return workers, nil
1674+
}

docker/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# syntax=docker/dockerfile:1.4
2-
FROM debian:bullseye-slim
2+
FROM debian:bullseye
33

44
LABEL maintainer="NGINX Docker Maintainers <integrations@nginx.com>"
55

66
ARG NGINX_PLUS_VERSION
7+
ARG NGINX_REPO_URL
78

89
# Install NGINX Plus
910
# 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
1617
curl -fsSL https://cs.nginx.com/static/keys/nginx_signing.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nginx_signing.gpg
1718
curl -fsSL -o /etc/apt/apt.conf.d/90pkgs-nginx https://cs.nginx.com/static/files/90pkgs-nginx
1819
DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release)
19-
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
20+
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
2021
apt-get update
2122
apt-get install -y nginx-plus
2223
apt-get remove --purge --auto-remove -y gnupg

docker/nginx.conf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11

22
user nginx;
3-
worker_processes auto;
3+
worker_processes 4;
44

55
error_log /var/log/nginx/error.log notice;
66
pid /var/run/nginx.pid;
77

8-
98
events {
109
worker_connections 1024;
1110
}
1211

13-
1412
http {
1513
include /etc/nginx/mime.types;
1614
default_type application/octet-stream;
@@ -22,12 +20,9 @@ http {
2220
access_log /var/log/nginx/access.log main;
2321

2422
sendfile on;
25-
#tcp_nopush on;
2623

2724
keepalive_timeout 65;
2825

29-
#gzip on;
30-
3126
keyval_zone zone=zone_one:32k;
3227
keyval $arg_text $text zone=zone_one;
3328

docker/nginx_no_stream.conf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
user nginx;
3-
worker_processes auto;
3+
worker_processes 4;
44

55
error_log /var/log/nginx/error.log notice;
66
pid /var/run/nginx.pid;
@@ -10,7 +10,6 @@ events {
1010
worker_connections 1024;
1111
}
1212

13-
1413
http {
1514
include /etc/nginx/mime.types;
1615
default_type application/octet-stream;
@@ -22,11 +21,8 @@ http {
2221
access_log /var/log/nginx/access.log main;
2322

2423
sendfile on;
25-
#tcp_nopush on;
2624

2725
keepalive_timeout 65;
2826

29-
#gzip on;
30-
3127
include /etc/nginx/conf.d/*.conf;
3228
}

docker/test.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ server {
2727
health_check interval=10 fails=3 passes=1;
2828
}
2929
status_zone test;
30-
3130
}
3231

3332
upstream test-drain {

tests/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ func TestStats(t *testing.T) {
627627
t.Errorf("Bad connections: %v", stats.Connections)
628628
}
629629

630+
if len(stats.Workers) < 1 {
631+
t.Errorf("Bad workers: %v", stats.Workers)
632+
}
633+
630634
if val, ok := stats.Caches[cacheZone]; ok {
631635
if val.MaxSize != 104857600 { // 100MiB
632636
t.Errorf("Cache max size stats missing: %v", val.Size)

0 commit comments

Comments
 (0)