Skip to content

Commit

Permalink
Merge pull request #218 from arangodb/feature/load-balancing-tests
Browse files Browse the repository at this point in the history
Load balancing tests
  • Loading branch information
ewoutp authored Aug 6, 2018
2 parents 4c5a2d3 + 289e776 commit 8c9fee8
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 49 deletions.
3 changes: 2 additions & 1 deletion pkg/deployment/client_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (cc *clientCache) GetDatabase(ctx context.Context) (driver.Client, error) {
}

// Not found, create a new client
c, err := arangod.CreateArangodDatabaseClient(ctx, cc.kubecli.CoreV1(), cc.apiObject)
shortTimeout := false
c, err := arangod.CreateArangodDatabaseClient(ctx, cc.kubecli.CoreV1(), cc.apiObject, shortTimeout)
if err != nil {
return nil, maskAny(err)
}
Expand Down
52 changes: 42 additions & 10 deletions pkg/util/arangod/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
Proxy: nhttp.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
KeepAlive: 90 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
Expand All @@ -77,7 +77,7 @@ var (
Proxy: nhttp.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
KeepAlive: 90 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
Expand All @@ -86,24 +86,49 @@ var (
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
sharedHTTPTransportShortTimeout = &nhttp.Transport{
Proxy: nhttp.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 100 * time.Millisecond,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 100 * time.Millisecond,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
sharedHTTPSTransportShortTimeout = &nhttp.Transport{
Proxy: nhttp.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 100 * time.Millisecond,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 100 * time.Millisecond,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
)

// CreateArangodClient creates a go-driver client for a specific member in the given group.
func CreateArangodClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, group api.ServerGroup, id string) (driver.Client, error) {
// Create connection
dnsName := k8sutil.CreatePodDNSName(apiObject, group.AsRole(), id)
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName)
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName, false)
if err != nil {
return nil, maskAny(err)
}
return c, nil
}

// CreateArangodDatabaseClient creates a go-driver client for accessing the entire cluster (or single server).
func CreateArangodDatabaseClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment) (driver.Client, error) {
func CreateArangodDatabaseClient(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, shortTimeout bool) (driver.Client, error) {
// Create connection
dnsName := k8sutil.CreateDatabaseClientServiceDNSName(apiObject)
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName)
c, err := createArangodClientForDNSName(ctx, cli, apiObject, dnsName, shortTimeout)
if err != nil {
return nil, maskAny(err)
}
Expand All @@ -117,7 +142,8 @@ func CreateArangodAgencyClient(ctx context.Context, cli corev1.CoreV1Interface,
dnsName := k8sutil.CreatePodDNSName(apiObject, api.ServerGroupAgents.AsRole(), m.ID)
dnsNames = append(dnsNames, dnsName)
}
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, dnsNames)
shortTimeout := false
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, dnsNames, shortTimeout)
if err != nil {
return nil, maskAny(err)
}
Expand Down Expand Up @@ -147,16 +173,16 @@ func CreateArangodAgencyClient(ctx context.Context, cli corev1.CoreV1Interface,
func CreateArangodImageIDClient(ctx context.Context, deployment k8sutil.APIObject, role, id string) (driver.Client, error) {
// Create connection
dnsName := k8sutil.CreatePodDNSName(deployment, role, id)
c, err := createArangodClientForDNSName(ctx, nil, nil, dnsName)
c, err := createArangodClientForDNSName(ctx, nil, nil, dnsName, false)
if err != nil {
return nil, maskAny(err)
}
return c, nil
}

// CreateArangodClientForDNSName creates a go-driver client for a given DNS name.
func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsName string) (driver.Client, error) {
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, []string{dnsName})
func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsName string, shortTimeout bool) (driver.Client, error) {
connConfig, err := createArangodHTTPConfigForDNSNames(ctx, cli, apiObject, []string{dnsName}, shortTimeout)
if err != nil {
return nil, maskAny(err)
}
Expand All @@ -183,12 +209,18 @@ func createArangodClientForDNSName(ctx context.Context, cli corev1.CoreV1Interfa
}

// createArangodHTTPConfigForDNSNames creates a go-driver HTTP connection config for a given DNS names.
func createArangodHTTPConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string) (http.ConnectionConfig, error) {
func createArangodHTTPConfigForDNSNames(ctx context.Context, cli corev1.CoreV1Interface, apiObject *api.ArangoDeployment, dnsNames []string, shortTimeout bool) (http.ConnectionConfig, error) {
scheme := "http"
transport := sharedHTTPTransport
if shortTimeout {
transport = sharedHTTPTransportShortTimeout
}
if apiObject != nil && apiObject.Spec.IsSecure() {
scheme = "https"
transport = sharedHTTPSTransport
if shortTimeout {
transport = sharedHTTPSTransportShortTimeout
}
}
connConfig := http.ConnectionConfig{
Transport: transport,
Expand Down
12 changes: 6 additions & 6 deletions tests/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestAuthenticationSingleDefaultSecret(t *testing.T) {

// Create a database client
ctx := arangod.WithRequireAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestAuthenticationSingleCustomSecret(t *testing.T) {

// Create a database client
ctx := arangod.WithRequireAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAuthenticationNoneSingle(t *testing.T) {

// Create a database client
ctx := arangod.WithSkipAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestAuthenticationClusterDefaultSecret(t *testing.T) {

// Create a database client
ctx := arangod.WithRequireAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestAuthenticationClusterCustomSecret(t *testing.T) {

// Create a database client
ctx := arangod.WithRequireAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestAuthenticationNoneCluster(t *testing.T) {

// Create a database client
ctx := arangod.WithSkipAuthentication(context.Background())
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t)
client := mustNewArangodDatabaseClient(ctx, kubecli, apiObject, t, nil)

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/change_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestChangeArgsAgents(t *testing.T) {

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

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestChangeArgsDBServer(t *testing.T) {

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

// Wait for cluster available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions tests/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestCursorSingle(t *testing.T) {

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

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestCursorActiveFailover(t *testing.T) {

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

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestCursorCluster(t *testing.T) {

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

// Wait for single server available
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions tests/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage

// Create a database client
ctx := context.Background()
DBClient := mustNewArangodDatabaseClient(ctx, kubecli, deployment, t)
DBClient := mustNewArangodDatabaseClient(ctx, kubecli, deployment, t, nil)
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment, DBClient, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))

// Cleanup
Expand Down Expand Up @@ -142,9 +142,9 @@ func TestMultiDeployment(t *testing.T) {

// Create a database clients
ctx := context.Background()
DBClient1 := mustNewArangodDatabaseClient(ctx, kubecli, deployment1, t)
DBClient1 := mustNewArangodDatabaseClient(ctx, kubecli, deployment1, t, nil)
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
DBClient2 := mustNewArangodDatabaseClient(ctx, kubecli, deployment2, t)
DBClient2 := mustNewArangodDatabaseClient(ctx, kubecli, deployment2, t, nil)
require.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, kubecli, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))

// Test if we are able to create a collections in both deployments.
Expand Down
2 changes: 1 addition & 1 deletion tests/immutable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestImmutableFields(t *testing.T) {

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

// Wait for single server to be completely ready
if err := waitUntilVersionUp(client, nil); err != nil {
Expand Down
Loading

0 comments on commit 8c9fee8

Please sign in to comment.