-
Notifications
You must be signed in to change notification settings - Fork 25
Add stream upstream, stream server zones metrics support #7
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
Changes from 3 commits
3955897
0c34234
2b059ca
6adc4f1
06d8dbe
2745a45
1ae242a
fbe16c5
94ad6a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,6 +453,75 @@ func TestStats(t *testing.T) { | |
} | ||
} | ||
|
||
func TestStreamStats(t *testing.T) { | ||
httpClient := &http.Client{} | ||
c, err := client.NewNginxClient(httpClient, "http://127.0.0.1:8080/api") | ||
if err != nil { | ||
t.Fatalf("Error connecting to nginx: %v", err) | ||
} | ||
|
||
// need upstream for stats | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> need an upstream for stats |
||
server := client.StreamUpstreamServer{ | ||
Server: "127.0.0.1:8080", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're using the virtual server for the API. perhaps it makes sense to have a separate server for testing defined in the stream block. Please take a look at http://nginx.org/en/docs/stream/ngx_stream_return_module.html#return |
||
} | ||
err = c.AddStreamServer(streamUpstream, server) | ||
if err != nil { | ||
t.Errorf("Error adding stream upstream server: %v", err) | ||
} | ||
|
||
// make request so we have stream server zone stats, expect 5xx error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we're dealing with stream module here, to make things less confusing, try to establish a TCP connection using "net" package instead of using the httpclient. See https://golang.org/pkg/net/ Change the comment to something like below:
Do not expect an error. If you want to have a simple stream server that responds something, see http://nginx.org/en/docs/stream/ngx_stream_return_module.html#return |
||
streamClient := &http.Client{} | ||
_, err = streamClient.Get("http://127.0.0.1:8081") | ||
if err != nil { | ||
t.Errorf("Error making request: %v", err) | ||
} | ||
|
||
stats, err := c.GetStats() | ||
if err != nil { | ||
t.Errorf("Error getting stats: %v", err) | ||
} | ||
|
||
if stats.Connections.Active == 0 { | ||
t.Errorf("Bad connections: %v", stats.Connections) | ||
} | ||
// SSL metrics blank in this example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this comment for? |
||
if len(stats.StreamServerZones) < 1 { | ||
t.Errorf("No StreamServerZone metrics: %v", stats.StreamServerZones) | ||
} | ||
|
||
if streamServerZone, ok := stats.StreamServerZones[streamUpstream]; ok { | ||
if streamServerZone.Connections < 1 { | ||
t.Errorf("StreamServerZone stats missing: %v", streamServerZone) | ||
} | ||
} else { | ||
t.Errorf("StreamServerZone 'stream_test' not found") | ||
} | ||
|
||
if upstream, ok := stats.StreamUpstreams[streamUpstream]; ok { | ||
if len(upstream.Peers) < 1 { | ||
t.Errorf("stream upstream server not visible in stats") | ||
} else { | ||
if upstream.Peers[0].State != "up" { | ||
t.Errorf("stream upstream server state should be 'up'") | ||
} | ||
if upstream.Peers[0].Connections < 0 { | ||
t.Errorf("stream upstream should have connects value") | ||
} | ||
if upstream.Peers[0].HealthChecks.LastPassed { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to test this, you must configure stream health checks http://nginx.org/en/docs/stream/ngx_stream_upstream_hc_module.html#health_check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test that the last health check has passed |
||
t.Errorf("stream upstream server health check should report last failed") | ||
} | ||
} | ||
} else { | ||
t.Errorf("Stream upstream 'stream_test' not found") | ||
} | ||
|
||
// cleanup stream upstream servers | ||
_, _, err = c.UpdateStreamServers(streamUpstream, []client.StreamUpstreamServer{}) | ||
if err != nil { | ||
t.Errorf("Couldn't remove stream servers: %v", err) | ||
} | ||
} | ||
|
||
func compareUpstreamServers(x []client.UpstreamServer, y []client.UpstreamServer) bool { | ||
var xServers []string | ||
for _, us := range x { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move it after getUpstreams call