Skip to content
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

Merged
merged 9 commits into from
Sep 4, 2018

Conversation

Dean-Coakley
Copy link
Contributor

  • 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
@Dean-Coakley Dean-Coakley added the enhancement Pull requests for new features/feature enhancements label Aug 28, 2018
@Dean-Coakley Dean-Coakley self-assigned this Aug 28, 2018
Copy link
Contributor

@isaachawley isaachawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@pleshakov pleshakov left a 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.

t.Fatalf("Error connecting to nginx: %v", err)
}

// need upstream for stats
Copy link
Contributor

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

t.Errorf("Error adding stream upstream server: %v", err)
}

// make request so we have stream server zone stats, expect 5xx error
Copy link
Contributor

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

if stats.Connections.Active == 0 {
t.Errorf("Bad connections: %v", stats.Connections)
}
// SSL metrics blank in this example
Copy link
Contributor

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?

if upstream.Peers[0].Connections < 0 {
t.Errorf("stream upstream should have connects value")
}
if upstream.Peers[0].HealthChecks.LastPassed {
Copy link
Contributor

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

Copy link
Contributor

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

client/nginx.go Show resolved Hide resolved
client/nginx.go Show resolved Hide resolved
Copy link
Contributor

@pleshakov pleshakov left a 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
Copy link
Contributor

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

Copy link
Contributor

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 Show resolved Hide resolved
client/nginx.go Show resolved Hide resolved
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()),
Copy link
Contributor

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.

Copy link
Contributor

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.

t.Errorf("Error getting stats: %v", err)
}

if stats.Connections.Active == 0 {
Copy link
Contributor

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?

Copy link
Contributor

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.

isaac added 2 commits August 31, 2018 09:39
- 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/*
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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{},
Copy link
Contributor

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))
Copy link
Contributor

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))
Copy link
Contributor

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()
Copy link
Contributor

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",
Copy link
Contributor

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

isaac added 2 commits August 31, 2018 13:21
- Fix StatusOK vs StatusCreated copy/paste typo
- Re-order stats calls
- Implicit empty apiError
@isaachawley isaachawley merged commit c9fb4ac into master Sep 4, 2018
@isaachawley isaachawley deleted the stream-metrics-support branch September 4, 2018 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants