diff --git a/client/nginx_client.go b/client/nginx_client.go index 682ddde8..3950979f 100644 --- a/client/nginx_client.go +++ b/client/nginx_client.go @@ -12,7 +12,7 @@ import ( // APIVersion is a version of NGINX Plus API. const APIVersion = 2 -// NginxClient lets you add/remove servers to/from NGINX Plus via its API. +// NginxClient lets you access NGINX Plus API. type NginxClient struct { apiEndpoint string httpClient *http.Client @@ -108,6 +108,7 @@ type Responses struct { Responses3xx uint64 `json:"3xx"` Responses4xx uint64 `json:"4xx"` Responses5xx uint64 `json:"5xx"` + Total uint64 } // Upstreams is a map of upstream stats by upstream name. @@ -146,7 +147,7 @@ type Peer struct { Received uint64 Fails uint64 Unavail uint64 - HealthChecks HealthChecks + HealthChecks HealthChecks `json:"health_checks"` Downtime uint64 Downstart string Selected string diff --git a/docker/test.conf b/docker/test.conf index 386febee..81506409 100644 --- a/docker/test.conf +++ b/docker/test.conf @@ -16,5 +16,10 @@ server { } api write=on; } + + location /test { + proxy_pass http://test; + health_check interval=10 fails=3 passes=1; + } status_zone test; } diff --git a/tests/client_test.go b/tests/client_test.go index 7fef8bde..b415c663 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -399,7 +399,7 @@ func TestStats(t *testing.T) { // need upstream for stats server := client.UpstreamServer{ - Server: "127.0.0.1:2000", + Server: "127.0.0.1:8080", } err = c.AddHTTPServer(upstream, server) if err != nil { @@ -435,6 +435,12 @@ func TestStats(t *testing.T) { if ups.Peers[0].State != "up" { t.Errorf("upstream server state should be 'up'") } + if ups.Peers[0].Responses.Total < 0 { + t.Errorf("upstream should have total responses value") + } + if ups.Peers[0].HealthChecks.LastPassed { + t.Errorf("upstream server health check should report last failed") + } } } else { t.Errorf("Upstream 'test' not found")