-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add stream upstream, stream server zones metrics support #7
Conversation
Dean-Coakley
commented
Aug 28, 2018
- Added support for stream upstream metrics
- Added support for stream server zone metrics
- Added stream server zone to nginx.conf for testing purposes
- Extended GetStats to include stream metrics
- Added integration test to validate that stream metrics are correct
- Fixed typo reponse-> response
* Added support for stream upstream metrics * Added support for stream server zone metrics * Added stream server zone to nginx.conf for testing purposes * Extended GetStats to include stream metrics * Added integration test to validate that stream metrics are returned
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.
👍
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 see my suggestions.
tests/client_test.go
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
-> need an upstream for stats
tests/client_test.go
Outdated
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 comment
The 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:
// Establish a connection to the stream server, so that we have some stats available for the stream zone.
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
tests/client_test.go
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
what is this comment for?
tests/client_test.go
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
test that the last health check has passed
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 see my comments
Makefile
Outdated
@@ -1,17 +1,24 @@ | |||
NGINX_PLUS_VERSION=15-2 | |||
NGINX_IMAGE=nginxplus:$(NGINX_PLUS_VERSION) | |||
|
|||
test: docker-build run-nginx-plus test-run clean | |||
|
|||
test: docker-build run-nginx-plus test-run config-no-stream test-no-stream clean |
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.
what if we remove the targets config-no-stream
and test-no-stream
and put all that config manipulation in the test-run
target? I think it will make it less confusing
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.
I like it this way, so that we can change the config and make test-run
or make test-no-stream
without changing the state of the container.
I also don't find this confusing.
client/nginx.go
Outdated
if err != nil { | ||
return fmt.Errorf("%v; failed to read the response body: %v", mainErr, err) | ||
} | ||
|
||
return fmt.Errorf("%v; error: %v", mainErr, apiErr.toString()) | ||
return &internalError{ | ||
err: fmt.Sprintf("%v; error: %v", mainErr, apiErrResp.toString()), |
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.
I don't think we need to store the mainErr inside internalError, as the apiErr that we get from Plus describes the problem very well.
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.
This is the same thing it did before see master.
tests/client_no_stream_test.go
Outdated
t.Errorf("Error getting stats: %v", err) | ||
} | ||
|
||
if stats.Connections.Active == 0 { |
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.
why do we make this check?
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.
It's a sanity check. We should get some connections from the api even without the stream block. I'll make it clearer.
- Improve test error clarity
- Add internalError.Wrap for preserving context
Makefile
Outdated
|
||
test-run: | ||
go test client/* | ||
go test tests/client_test.go | ||
GOCACHE=off go test client/* |
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.
for unit tests in client, don't see why we need to GOCACHE=off
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.
Without it, changes in templates won't get tested. Because the go code doesn't change, the test results will be cached.
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.
for this ones https://github.com/nginxinc/nginx-plus-go-sdk/blob/master/client/nginx_test.go we don't need any template
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.
ugh alright
client/nginx.go
Outdated
return fmt.Errorf("%v; failed to read the response body: %v", mainErr, err) | ||
return &internalError{ | ||
err: fmt.Sprintf("failed to read the response body: %v", err), | ||
apiError: apiError{}, |
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.
apiError: apiError{}
is it necessary?
client/nginx.go
Outdated
return createResponseMismatchError(resp.Body, mainErr) | ||
return createResponseMismatchError(resp.Body).Wrap(fmt.Sprintf( | ||
"failed to complete delete request: expected %v response, got %v", | ||
http.StatusCreated, resp.StatusCode)) |
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.
http.StatusCreated -> http.StatusOK
client/nginx.go
Outdated
return createResponseMismatchError(resp.Body, mainErr) | ||
return createResponseMismatchError(resp.Body).Wrap(fmt.Sprintf( | ||
"expected %v response, got %v", | ||
http.StatusCreated, resp.StatusCode)) |
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.
http.StatusCreated -> http.StatusOK
@@ -594,17 +679,29 @@ func (client *NginxClient) GetStats() (*Stats, error) { | |||
return nil, fmt.Errorf("failed to get stats: %v", err) | |||
} | |||
|
|||
streamZones, err := client.getStreamServerZones() |
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
} | ||
|
||
server := client.StreamUpstreamServer{ | ||
Server: "127.0.0.1:8080", |
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.
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
- Fix StatusOK vs StatusCreated copy/paste typo - Re-order stats calls - Implicit empty apiError