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

Load balancing tests #218

Merged
merged 17 commits into from
Aug 6, 2018
Merged

Load balancing tests #218

merged 17 commits into from
Aug 6, 2018

Conversation

dhly-etc
Copy link
Contributor

@dhly-etc dhly-etc commented Jul 11, 2018

Needs significant testing and probably fixes, additional code.

This PR now imports arangodb/go-driver#139

@dhly-etc dhly-etc added the 9 WIP label Jul 11, 2018
@ghost ghost assigned dhly-etc Jul 11, 2018
@ghost ghost added the 2 - Working label Jul 11, 2018
Copy link
Contributor

@ewoutp ewoutp left a comment

Choose a reason for hiding this comment

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

Needs several changes, but still I'm impressed for a go novice.

@@ -52,11 +52,12 @@ const (
keyIsSystem ContextKey = "arangodb-isSystem"
keyIgnoreRevs ContextKey = "arangodb-ignoreRevs"
keyEnforceReplicationFactor ContextKey = "arangodb-enforceReplicationFactor"
keyConfigured ContextKey = "arangodb-configured"
keyConfigured ContextKey = "arangodb-configured"
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The go-driver is vendored in this repo. Never change it here, without a PR in the go-driver repo first.
  2. VST is controlled by the type of Connection, no need to add anything to the context for that.

if err != nil {
return nil, maskAny(err)
}
// Create client
Copy link
Contributor

Choose a reason for hiding this comment

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

From this point on the code paths are the same. Only create conn in the if/else block.
Use var conn driver.Connection before the if/else block.
Then change conn, err := ... to conn, err = ...

if err != nil {
return nil, maskAny(err)
config := driver.ClientConfig{}
vst := driver.mustUseVST(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not use the context for this, but add an argument to the function.
To avoid changing all uses of this function, use vst ...bool and then if len(vst) > 0 && vst[0] { ...

func createArangodVSTConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (http.ConnectionConfig, error) {
scheme := "vst"
if apiObject != nil && apiObject.Spec.IsSecure() {
// TODO set security for transport
Copy link
Contributor

Choose a reason for hiding this comment

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

Secure connection is essential, since almost all kube-arangodb deployments use TLS.
To use a secure VST connection, set scheme = "https".

@@ -200,6 +218,22 @@ func createArangodHTTPConfigForDNSNames(ctx context.Context, cli corev1.CoreV1In
return connConfig, nil
}

// createArangodVSTConfigForDNSNames creates a go-driver VST connection config for a given DNS names.
func createArangodVSTConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (http.ConnectionConfig, error) {
scheme := "vst"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be "http". There is no "vst" scheme in the go-driver, just a VST connection that re-uses http/https schemes.

@@ -186,7 +204,7 @@ func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interfa
func createArangodHTTPConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (http.ConnectionConfig, error) {
scheme := "http"
transport := sharedHTTPTransport
if apiObject != nil && apiObject.Spec.IsSecure() {
if apiObject != nil && apiObject.Spec.IsSecure() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely you did not use go fmt.



// TestLoadBalancerCursorVST tests cursor forwarding with load-balanced VST
func TestLoadBalancerCursorVST(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Set the use of VST explicitly, not via context.
  2. I would "duplicate" this test for VST & HTTP. To do so, create a helper function that contains almost all of the test and from TestLoadBalancerCursorVST and TestLoadBalancerCursorHTTP call that function with 1 argument specifying VST/HTTP.


// Create a database client
ctx := context.Background()
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Extend this call to include VST/HTTP. (again as optional argument vst ...bool)

if apiObject != nil && apiObject.Spec.IsSecure() {
// TODO set security for transport
}
transport := vst.NewTransport(/* TODO configure transport */)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ewoutp I haven't found examples of how to configure the transport correctly for secure vs. non-secure. Do you have a link to somewhere this is done?

Copy link
Contributor

Choose a reason for hiding this comment

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


// Setup context alternatives
contexts := []queryTestContext{
queryTestContext{driver.WithUseVST(nil, true), false},
Copy link
Contributor

Choose a reason for hiding this comment

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

remove WithUseVST

DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
IdleConnTimeout: 100 * time.Millisecond,
Copy link
Contributor

Choose a reason for hiding this comment

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

These are shared instances, so you're now changings this for ALL. That is not good.

}

// tests cursor forwarding with load-balanced conn.
func LoadBalancingCursorSubtest(t *testing.T, useVst bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function should start with a lower-case letter.
Uppercase is used to export a member outside its package, which is not needed (and wanted) here.

}

func wasForwarded(r *driver.Response) bool {
h := (*r).Header("x-arango-request-served-by")
Copy link
Contributor

Choose a reason for hiding this comment

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

driver.Response is already an interface. Change r *driver.Response to r driver.Response.

// Close upon exit of the function
defer cursor.Close()
}
if test.ExpectSuccess {
Copy link
Contributor

Choose a reason for hiding this comment

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

This entire file needs go fmt. Since most editors do that automatically, any future change would cause a huge diff if you do not format now.

}

// CreateArangodDatabaseVSTClient creates a go-driver client for accessing the entire cluster (or single server) via VST
func CreateArangodDatabaseVSTClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment) (driver.Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

start with lowercase letter. Should not be exported.


func wasForwarded(r *driver.Response) bool {
h := (*r).Header("x-arango-request-served-by")
return h != ""
Copy link
Contributor

Choose a reason for hiding this comment

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

API question. Is this header only set if the request is forwarded?
The header key seems to suggest that it is always there.
So I expected that you want to look for different values for this header instead of non-empty values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it is only set if the request is served by a different server than the one the request was sent to. You are correct that this is less than intuitive, so I'll think a bit about a better name.

t.Error("HasMore returned false, but ReadDocument returns a document")
}
result = append(result, doc.Elem().Interface())
if (wasForwarded(&r)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In go, if expressions do not need brackets. A go fmt will remove them automatically.

@ghost ghost assigned ewoutp Jul 19, 2018
depl := newDeployment("test-lb-" + uniuri.NewLen(4))
depl.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
image := "dhly/arangodb:3.3.11-local"
depl.Spec.Image = &image
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but in order to be consistent with the rest of the tests, use:
depl.Spec.Image = util.NewString("...")

@ewoutp ewoutp merged commit 8c9fee8 into master Aug 6, 2018
@ewoutp ewoutp deleted the feature/load-balancing-tests branch August 6, 2018 14:03
@ghost ghost removed the 2 - Working label Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants