-
Notifications
You must be signed in to change notification settings - Fork 70
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
Load balancing tests #218
Conversation
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.
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" |
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.
- The go-driver is vendored in this repo. Never change it here, without a PR in the go-driver repo first.
- VST is controlled by the type of
Connection
, no need to add anything to the context for that.
pkg/util/arangod/client.go
Outdated
if err != nil { | ||
return nil, maskAny(err) | ||
} | ||
// Create 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.
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 = ...
pkg/util/arangod/client.go
Outdated
if err != nil { | ||
return nil, maskAny(err) | ||
config := driver.ClientConfig{} | ||
vst := driver.mustUseVST(context) |
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 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] { ...
pkg/util/arangod/client.go
Outdated
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 |
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.
Secure connection is essential, since almost all kube-arangodb deployments use TLS.
To use a secure VST connection, set scheme = "https"
.
pkg/util/arangod/client.go
Outdated
@@ -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" |
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.
Should be "http". There is no "vst" scheme in the go-driver, just a VST connection that re-uses http/https schemes.
pkg/util/arangod/client.go
Outdated
@@ -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() { |
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.
Likely you did not use go fmt
.
tests/load_balancer_test.go
Outdated
|
||
|
||
// TestLoadBalancerCursorVST tests cursor forwarding with load-balanced VST | ||
func TestLoadBalancerCursorVST(t *testing.T) { |
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.
- Set the use of VST explicitly, not via context.
- 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
andTestLoadBalancerCursorHTTP
call that function with 1 argument specifying VST/HTTP.
tests/load_balancer_test.go
Outdated
|
||
// Create a database client | ||
ctx := context.Background() | ||
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t) |
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.
Extend this call to include VST/HTTP. (again as optional argument vst ...bool
)
pkg/util/arangod/client.go
Outdated
if apiObject != nil && apiObject.Spec.IsSecure() { | ||
// TODO set security for transport | ||
} | ||
transport := vst.NewTransport(/* TODO configure transport */) |
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.
@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?
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.
https://github.com/arangodb/go-driver/blob/master/vst/connection.go#L96
that line is what makes this work
tests/load_balancer_test.go
Outdated
|
||
// Setup context alternatives | ||
contexts := []queryTestContext{ | ||
queryTestContext{driver.WithUseVST(nil, true), false}, |
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.
remove WithUseVST
pkg/util/arangod/client.go
Outdated
DualStack: true, | ||
}).DialContext, | ||
MaxIdleConns: 100, | ||
IdleConnTimeout: 90 * time.Second, | ||
IdleConnTimeout: 100 * time.Millisecond, |
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.
These are shared instances, so you're now changings this for ALL. That is not good.
tests/load_balancer_test.go
Outdated
} | ||
|
||
// tests cursor forwarding with load-balanced conn. | ||
func LoadBalancingCursorSubtest(t *testing.T, useVst bool) { |
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 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.
tests/load_balancer_test.go
Outdated
} | ||
|
||
func wasForwarded(r *driver.Response) bool { | ||
h := (*r).Header("x-arango-request-served-by") |
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.
driver.Response
is already an interface. Change r *driver.Response
to r driver.Response
.
tests/load_balancer_test.go
Outdated
// Close upon exit of the function | ||
defer cursor.Close() | ||
} | ||
if test.ExpectSuccess { |
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 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.
tests/test_util.go
Outdated
} | ||
|
||
// 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) { |
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.
start with lowercase letter. Should not be exported.
tests/load_balancer_test.go
Outdated
|
||
func wasForwarded(r *driver.Response) bool { | ||
h := (*r).Header("x-arango-request-served-by") | ||
return h != "" |
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.
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.
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.
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.
tests/load_balancer_test.go
Outdated
t.Error("HasMore returned false, but ReadDocument returns a document") | ||
} | ||
result = append(result, doc.Elem().Interface()) | ||
if (wasForwarded(&r)) { |
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.
In go, if expressions do not need brackets. A go fmt
will remove them automatically.
tests/load_balancer_test.go
Outdated
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 |
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 works, but in order to be consistent with the rest of the tests, use:
depl.Spec.Image = util.NewString("...")
Needs significant testing and probably fixes, additional code.
This PR now imports arangodb/go-driver#139