Skip to content

Commit 76c610f

Browse files
authored
Small fixes to the NGINX Plus client (#4)
* Small fixes to the NGINX Plus client - Add Total responses to upstream struct - Add json tag to HealthChecks property so it parses - Update comment
1 parent 380a939 commit 76c610f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

client/nginx_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// APIVersion is a version of NGINX Plus API.
1313
const APIVersion = 2
1414

15-
// NginxClient lets you add/remove servers to/from NGINX Plus via its API.
15+
// NginxClient lets you access NGINX Plus API.
1616
type NginxClient struct {
1717
apiEndpoint string
1818
httpClient *http.Client
@@ -108,6 +108,7 @@ type Responses struct {
108108
Responses3xx uint64 `json:"3xx"`
109109
Responses4xx uint64 `json:"4xx"`
110110
Responses5xx uint64 `json:"5xx"`
111+
Total uint64
111112
}
112113

113114
// Upstreams is a map of upstream stats by upstream name.
@@ -146,7 +147,7 @@ type Peer struct {
146147
Received uint64
147148
Fails uint64
148149
Unavail uint64
149-
HealthChecks HealthChecks
150+
HealthChecks HealthChecks `json:"health_checks"`
150151
Downtime uint64
151152
Downstart string
152153
Selected string

docker/test.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ server {
1616
}
1717
api write=on;
1818
}
19+
20+
location /test {
21+
proxy_pass http://test;
22+
health_check interval=10 fails=3 passes=1;
23+
}
1924
status_zone test;
2025
}

tests/client_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func TestStats(t *testing.T) {
399399

400400
// need upstream for stats
401401
server := client.UpstreamServer{
402-
Server: "127.0.0.1:2000",
402+
Server: "127.0.0.1:8080",
403403
}
404404
err = c.AddHTTPServer(upstream, server)
405405
if err != nil {
@@ -435,6 +435,12 @@ func TestStats(t *testing.T) {
435435
if ups.Peers[0].State != "up" {
436436
t.Errorf("upstream server state should be 'up'")
437437
}
438+
if ups.Peers[0].Responses.Total < 0 {
439+
t.Errorf("upstream should have total responses value")
440+
}
441+
if ups.Peers[0].HealthChecks.LastPassed {
442+
t.Errorf("upstream server health check should report last failed")
443+
}
438444
}
439445
} else {
440446
t.Errorf("Upstream 'test' not found")

0 commit comments

Comments
 (0)