Skip to content

Small fixes to the NGINX Plus client #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/nginx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docker/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 7 additions & 1 deletion tests/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down