Skip to content

GODRIVER-1931 Run tests against LBs in Evergreen #648

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

Merged
merged 6 commits into from
Apr 28, 2021

Conversation

divjotarora
Copy link
Contributor

@divjotarora divjotarora commented Apr 23, 2021

This PR contains the changes needed to run load balancers in Evergreen and some updates to the mtest packakge to handle load balancer URIs. I also added a load_balancer_prose_test.go file to fill in some missing test coverage. There were a couple of missing/untested operations in the unified test runner so there are some changes required for that as well.

I called out some notable changes in PR comments, but there are additional changes that span multiple files:

  1. There is currently no upstream service (e.g. mongos) that supports running behind an LB. To test against a sharded cluster without waiting for upstream support, this PR introduces a SetServiceID flag in internal/const.go. This flag is used in description/server.go when parsing hello command responses and enables a mode in which we mock the server returning serviceId. It's set to true in mongo/integration/main_test.go and mongo/integration/unified/main_test.go if required.
  2. I realized there are some cases where we need to skip a test in the unified test runner, but don't become aware of this until after we've started constructing entities or running operations. We could account for these tests in skippedTestDescriptions, but I thought it'd be better to add a more robust approach in which tests execution functions can return a special error type that is checked at a higher level, so I added the skipTestError type in unified_spec_runner.go.

dataLake bool
requireAPIVersion bool
serverParameters bson.Raw
singleMongosLoadBalancerURI string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only changes were the addition of singleMongosLoadBalancerURI and multiMongosLoadBalancerURI. The diff looks larger due to auto-alignment by gofmt.

// ConnString gets the globally configured connection string.
func getConnString() (connstring.ConnString, error) {
// getClusterConnString gets the globally configured connection string.
func getClusterConnString() (connstring.ConnString, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Name changed for clarity.

@@ -186,6 +188,20 @@ func Setup(setupOpts ...*SetupOptions) error {
}
}

if testContext.topoKind == LoadBalanced {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is due to a spec/setup requirement - when mongo-orchestration starts up a cluster, it provides a URI that includes authentication information (if needed) but does not include TLS information (e.g. CA file path). We normally work around this by manually modifying the cluster URI, which is done in getClusterConnString(), which internally calls addTLSConfig(). For LB testing, we have to make the same modification for the URIs of the LBs themselves as well, so we do all of that here and then store the processed URI in testContext.

@@ -126,26 +122,19 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp
return entity, nil
}

func getURIForClient(opts *entityOptions) (string, error) {
func getURIForClient(opts *entityOptions) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function originally returned an error because it would dynamically fetch the LB URI from an environment variable, which could be empty. The error is no longer needed because the env var checking is done in mtest#Setup so we can fetch the required URI via the mtest functions here.

@@ -344,8 +333,14 @@ func setClientOptionsFromURIOptions(clientOpts *options.ClientOptions, uriOpts b

for key, value := range uriOpts {
switch key {
case "appname":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All additions here are due to missing client options that were not required by previous tests.

@@ -748,6 +748,38 @@ func executeInsertOne(ctx context.Context, operation *operation) (*operationResu
return newDocumentResult(raw, err), nil
}

func executeListIndexes(ctx context.Context, operation *operation) (*operationResult, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was previously missed because no other test required it.

@@ -89,7 +89,7 @@ func executeListCollections(ctx context.Context, operation *operation) (*operati
defer cursor.Close(ctx)

var docs []bson.Raw
if err := cursor.All(ctx, &cursor); err != nil {
if err := cursor.All(ctx, &docs); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug but there was no unified test that executed listCollections.

@@ -518,6 +518,33 @@ functions:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
LD_LIBRARY_PATH=$LD_LIBRARY_PATH

run-load-balancer-tests:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The script here is mostly a copy/paste of the run-tests function.


export GOFLAGS=-mod=vendor
set +o xtrace
AUTH="${AUTH}" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notable change in env var settings between this invocation and run-tests: there are no CSFLE env vars set here (e.g. AWS_ACCESS_KEY_ID) because the CSFLE tests are not run against LBs.

@divjotarora divjotarora force-pushed the godriver1931-evg-work branch 2 times, most recently from 4395ef7 to 986dd67 Compare April 26, 2021 15:33
fi
fi

# Verify that the required LB URI env vars are set to ensure that the test runner can correctly connect to
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We check for empty LB URIs both here and in mongo/integration/mtest/setup.go. This might be redundant, but it accounts for both running in CI and locally. If we only checked in setup.go, we could have an issue where SINGLE_MONGOS_LB_URI is unset, so MONGODB_URI would also be unset. In this case, the setup function defaults to localhost:27017 and based on topology discovery, thinks it's connecting to a mongos rather than an LB cluster, so important tests that only run against LBs would be incorrectly skipped. Having the check in both places prevents that from happening.

Note that this may not be required once an upstream service fully supports running behind an LB because the service should error if it's configured in LB mode but the driver connects without loadBalanced=true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, the extra check to avoid accidentally skipping these tests is a good precaution.

Note that this may not be required once an upstream service fully supports running behind an LB because the service should error if it's configured in LB mode but the driver connects without loadBalanced=true.

Right, since drivers send loadBalanced: true as part of the hello command, the server could reject non load balanced connections if it knows it is running behind a load balancer.

@@ -866,6 +922,7 @@ post:
files:
- "src/go.mongodb.org/mongo-driver/*.suite"
- func: upload-mo-artifacts
- func: stop-load-balancer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added as a post task to ensure that the LB is shut down even if the tests fail.

@@ -355,6 +350,8 @@ func setClientOptionsFromURIOptions(clientOpts *options.ClientOptions, uriOpts b
case "w":
wc.W = value
wcSet = true
case "waitQueueTimeoutMS":
return newSkipTestError("the waitQueueTimeoutMS client option is not supported")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an example of dynamically detecting that the test needs to be skipped as mentioned in the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why do we not support WaitQueueTimeoutMS in Go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CMAP spec states that supporting waitQueueTimeoutMS is optional and not required if the language already has an idiomatic timeout mechanism. Go has contexts, so we don't support the option.

@divjotarora divjotarora force-pushed the godriver1931-evg-work branch from be21ade to b753c20 Compare April 26, 2021 22:03
@divjotarora divjotarora force-pushed the godriver1931-evg-work branch from 8ba56a8 to 7874a68 Compare April 26, 2021 23:10
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Looking great!

fi
fi

# Verify that the required LB URI env vars are set to ensure that the test runner can correctly connect to
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, the extra check to avoid accidentally skipping these tests is a good precaution.

Note that this may not be required once an upstream service fully supports running behind an LB because the service should error if it's configured in LB mode but the driver connects without loadBalanced=true.

Right, since drivers send loadBalanced: true as part of the hello command, the server could reject non load balanced connections if it knows it is running behind a load balancer.

Divjot Arora and others added 2 commits April 27, 2021 15:26
@divjotarora divjotarora requested a review from kevinAlbs April 27, 2021 19:27
Copy link
Contributor

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

Just some questions/nits! I don't really understand SetMockServiceID so I'll ask offline.

@@ -355,6 +350,8 @@ func setClientOptionsFromURIOptions(clientOpts *options.ClientOptions, uriOpts b
case "w":
wc.W = value
wcSet = true
case "waitQueueTimeoutMS":
return newSkipTestError("the waitQueueTimeoutMS client option is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why do we not support WaitQueueTimeoutMS in Go ?

Divjot Arora and others added 2 commits April 27, 2021 16:18
@divjotarora divjotarora requested a review from benjirewis April 27, 2021 20:20
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Looks good! Just a quick question.

Copy link
Contributor

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM!

@divjotarora divjotarora merged commit b1d1e30 into mongodb:master Apr 28, 2021
@divjotarora divjotarora deleted the godriver1931-evg-work branch April 28, 2021 15:43
stlimtat pushed a commit to stlimtat/mongo-go-driver that referenced this pull request May 17, 2021
* 'master' of https://github.com/mongodb/mongo-go-driver: (39 commits)
  GODRIVER-2004 Add Versioned API connection examples for Docs (mongodb#665)
  GODRIVER-1961 Run OCSP tests against RHEL 7.0 (mongodb#664)
  GODRIVER-1844 finer precision for getSecondsSinceEpoch (mongodb#666)
  GODRIVER-1973 create internal copy of aws v4 signing code (mongodb#657)
  GODRIVER-1951 Update the Go version for Evergreen builds to 1.16 (mongodb#663)
  GODRIVER-1949 add more ignored killAllSessions errors for unified tes… (mongodb#658)
  GODRIVER-1963 remove dropDatabase result (mongodb#660)
  GODRIVER-1180 Remove legacy transform functions from mongo (mongodb#583)
  GODRIVER-1937 Update legacy ListCollections to support the BatchSize option for server version 2.6 (mongodb#656)
  GODRIVER-1933 remove xtrace from shell scripts (mongodb#661)
  fix README error handling of FindOne (mongodb#636)
  GODRIVER-1938 update mongocryptd serverSelectionTimeout to 10 seconds (mongodb#659)
  GODRIVER-1925 Surface cursor errors in DownloadStream fillBuffer (mongodb#653)
  GODRIVER-1955 create labeledError interface (mongodb#651)
  GODRIVER-1947 Unmarshal unicode surrogate pairs correctly in UnmarshalExtJSON. (mongodb#649)
  Changed order of actions in ObjectIDFromHex func (mongodb#637)
  GODRIVER-1750 Ensure contexts are always cancelled during server monitoring (mongodb#654)
  GODRIVER-1931 Sync new cursors and SDAM LB tests (mongodb#655)
  GODRIVER-1981 Sync new transactions tests (mongodb#652)
  GODRIVER-1931 Run tests against LBs in Evergreen (mongodb#648)
  ...
faem pushed a commit to kubedb/mongo-go-driver that referenced this pull request Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants