Skip to content

CDRIVER-4062 test load balancer on evg #837

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 31 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a6820cc
use SINGLE_MONGOS_LB_URI as test_framework_get_uri
kevinAlbs Jul 28, 2021
1e27b95
resync retryable reads tests
kevinAlbs Jul 30, 2021
ab80362
add load-balanced to runOn check
kevinAlbs Jul 30, 2021
783710c
resync retryable writes tests to d2de77692b727b805168eeba02c3ab29e6a1…
kevinAlbs Jul 30, 2021
47e3f7c
RISK: run retryable writes spec tests on all topologies
kevinAlbs Jul 30, 2021
33aa413
support useMultipleMongos on LB in retryable writes
kevinAlbs Jul 30, 2021
557184f
remove out-dated retryableErrors test, update skip
kevinAlbs Jul 30, 2021
eaaf361
resync change stream tests; add unified test (CDRIVER-3889)
kevinAlbs Jul 30, 2021
72d0065
apply SINGLE/MULTI_LB_MONGOS_URI to unified test runner
kevinAlbs Jul 31, 2021
9a8ce2d
sync new load balancer unified tests
kevinAlbs Jul 31, 2021
57e52e1
add service_id to captured events; ignore cmap evts
kevinAlbs Jul 31, 2021
7d000b0
add example of unsupported batchSize on listIndexes / listCollections
kevinAlbs Aug 1, 2021
f448895
Add a findcursor entity for lazy cursor handling.
kevinAlbs Aug 1, 2021
9fdd109
skip waitQueueTimeoutMS test; add appname URI option
kevinAlbs Aug 1, 2021
4171f56
initialize bson reply
kevinAlbs Aug 1, 2021
326acae
allow NULL for reply
kevinAlbs Aug 1, 2021
9411cc4
support --skip, --after, and multiple -l in test-libmongoc
kevinAlbs Jul 14, 2021
39b093a
add --match as an alias
kevinAlbs Aug 3, 2021
1b8c27e
add WIP ASAN test tasks
kevinAlbs Aug 3, 2021
a651033
fix test-libmongoc path
kevinAlbs Aug 3, 2021
c4d1f4c
use test framwork to construct client for /loadbalanced/ tests
kevinAlbs Aug 3, 2021
b303183
add 5.0 task
kevinAlbs Aug 3, 2021
d0ecd1f
generate evg config
kevinAlbs Aug 4, 2021
535befa
remove --after and --skip
kevinAlbs Aug 4, 2021
7031fb0
removed unused function
kevinAlbs Aug 4, 2021
3dc5887
remove AUTHSOURCE: thisDB, remove logs
kevinAlbs Aug 4, 2021
143b21a
fix pre-opmsg command construction for auth
kevinAlbs Aug 4, 2021
86582a7
update run-tests.sh
kevinAlbs Aug 4, 2021
17789c4
add comment
kevinAlbs Aug 4, 2021
2a0922c
remove redundant test; format
kevinAlbs Aug 4, 2021
808424c
jesse + jeremy comments
kevinAlbs Aug 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ functions:
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
fi
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note the Evergreen config file is generated from Python scripts. The relevant changes are in tasks.py, functions.py, and variants.py.

export LOADBALANCED=${LOADBALANCED}
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
set -o errexit
sh .evergreen/run-tests.sh
run tests bson:
Expand Down Expand Up @@ -26547,6 +26550,114 @@ tasks:
set -o errexit
export LD_LIBRARY_PATH=$(pwd)/install-dir/lib
CERT_TYPE=ecdsa .evergreen/run-ocsp-cache-test.sh
- name: test-loadbalanced-asan-auth-openssl-5.0
tags:
- '5.0'
- test-asan
exec_timeout_secs: 3600
depends_on:
name: debug-compile-asan-clang-openssl
commands:
- func: fetch build
vars:
BUILD_NAME: debug-compile-asan-clang-openssl
- func: bootstrap mongo-orchestration
vars:
AUTH: auth
SSL: ssl
TOPOLOGY: sharded_cluster
VERSION: '5.0'
- func: clone drivers-evergreen-tools
- func: start load balancer
vars:
MONGODB_URI: mongodb://localhost:27017,localhost:27018
- func: run tests
vars:
ASAN: 'on'
AUTH: auth
LOADBALANCED: loadbalanced
SSL: ssl
- name: test-loadbalanced-asan-auth-openssl-latest
tags:
- latest
- test-asan
exec_timeout_secs: 3600
depends_on:
name: debug-compile-asan-clang-openssl
commands:
- func: fetch build
vars:
BUILD_NAME: debug-compile-asan-clang-openssl
- func: bootstrap mongo-orchestration
vars:
AUTH: auth
SSL: ssl
TOPOLOGY: sharded_cluster
VERSION: latest
- func: clone drivers-evergreen-tools
- func: start load balancer
vars:
MONGODB_URI: mongodb://localhost:27017,localhost:27018
- func: run tests
vars:
ASAN: 'on'
AUTH: auth
LOADBALANCED: loadbalanced
SSL: ssl
- name: test-loadbalanced-asan-noauth-nossl-5.0
tags:
- '5.0'
- test-asan
exec_timeout_secs: 3600
depends_on:
name: debug-compile-asan-clang-openssl
commands:
- func: fetch build
vars:
BUILD_NAME: debug-compile-asan-clang-openssl
- func: bootstrap mongo-orchestration
vars:
AUTH: noauth
SSL: nossl
TOPOLOGY: sharded_cluster
VERSION: '5.0'
- func: clone drivers-evergreen-tools
- func: start load balancer
vars:
MONGODB_URI: mongodb://localhost:27017,localhost:27018
- func: run tests
vars:
ASAN: 'on'
AUTH: noauth
LOADBALANCED: loadbalanced
SSL: nossl
- name: test-loadbalanced-asan-noauth-nossl-latest
tags:
- latest
- test-asan
exec_timeout_secs: 3600
depends_on:
name: debug-compile-asan-clang-openssl
commands:
- func: fetch build
vars:
BUILD_NAME: debug-compile-asan-clang-openssl
- func: bootstrap mongo-orchestration
vars:
AUTH: noauth
SSL: nossl
TOPOLOGY: sharded_cluster
VERSION: latest
- func: clone drivers-evergreen-tools
- func: start load balancer
vars:
MONGODB_URI: mongodb://localhost:27017,localhost:27018
- func: run tests
vars:
ASAN: 'on'
AUTH: noauth
LOADBALANCED: loadbalanced
SSL: nossl
buildvariants:
- name: releng
display_name: '**Release Archive Creator'
Expand Down
10 changes: 5 additions & 5 deletions .evergreen/download-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ get_mongodb_download_url_for ()
_DISTRO=$1
_VERSION=$2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an updated copy of the file in mongodb-labs/drivers-evergreen-tools.

VERSION_50="5.0.0-rc0"
VERSION_44="4.4.3"
VERSION_42="4.2.11"
VERSION_40="4.0.22"
VERSION_36="3.6.21"
VERSION_50="5.0.0"
VERSION_44="4.4.6"
VERSION_42="4.2.15"
VERSION_40="4.0.25"
VERSION_36="3.6.23"
VERSION_34="3.4.24"
VERSION_32="3.2.22"
VERSION_30="3.0.15"
Expand Down
24 changes: 24 additions & 0 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SSL=${SSL:-nossl}
URI=${URI:-}
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
DNS=${DNS:-nodns}
LOADBALANCED=${LOADBALANCED:-noloadbalanced}

# AddressSanitizer configuration
export ASAN_OPTIONS="detect_leaks=1 abort_on_error=1 symbolize=1"
Expand Down Expand Up @@ -91,6 +92,29 @@ check_mongocryptd() {

export MONGOC_TEST_MONITORING_VERBOSE=on

if [ "$LOADBALANCED" != "noloadbalanced" ]; then
if [ -z "$SINGLE_MONGOS_LB_URI" -o -z "$MULTI_MONGOS_LB_URI" ]; then
echo "SINGLE_MONGOS_LB_URI and MULTI_MONGOS_LB_URI environment variables required."
exit 1
fi

export MONGOC_TEST_LOADBALANCED=ON

TEST_ARGS="$TEST_ARGS -l /unified/*"
TEST_ARGS="$TEST_ARGS -l /retryable_reads/*"
TEST_ARGS="$TEST_ARGS -l /retryable_writes/*"
TEST_ARGS="$TEST_ARGS -l /change_streams/*"
TEST_ARGS="$TEST_ARGS -l /loadbalanced/*"
TEST_ARGS="$TEST_ARGS -l /load_balancers/*"
TEST_ARGS="$TEST_ARGS -l /crud/unified/*"
TEST_ARGS="$TEST_ARGS -l /transactions/unified/*"
TEST_ARGS="$TEST_ARGS -l /collection-management/*"
TEST_ARGS="$TEST_ARGS -l /sessions/unified/*"
TEST_ARGS="$TEST_ARGS -l /change_streams/unified/*"
TEST_ARGS="$TEST_ARGS -l /versioned_api/*"
TEST_ARGS="$TEST_ARGS -l /command_monitoring/unified/*"
fi

case "$OS" in
cygwin*)
export PATH=$PATH:/cygdrive/c/mongodb/bin:/cygdrive/c/libmongocrypt/bin
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ To test with a declared API version, you can pass the API version using an envir

This will ensure that all tests declare the indicated API version when connecting to a server.

To test a load balanced deployment, set the following environment variables:

* `MONGOC_TEST_LOADBALANCED=on`
* `SINGLE_MONGOS_LB_URI=<string>` to a MongoDB URI with a host of a load balancer fronting one mongos.
* `MULTI_MONGOS_LB_URI=<string>` to a MongoDB URI with a host of a load balancer fronting multiple mongos processes.

All tests should pass before submitting a patch.

## Configuring the test runner
Expand Down
3 changes: 3 additions & 0 deletions build/evergreen_config_lib/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
fi
export LOADBALANCED=${LOADBALANCED}
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
Copy link
Member

Choose a reason for hiding this comment

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

Are these values coming from the Evergreen project configuration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, these are Evergreen expansions that are created when the Evergreen task is run.

In config.yml, the "start load balancer" function runs the run-load-balancer.sh script from driver-evergreen-tools. It generates these URIs and writes them to a file on this line. The "start load balancer" function then uses the expansions.update command to load these values as Evergreen expansions.

set -o errexit
sh .evergreen/run-tests.sh
'''),
Expand Down
67 changes: 67 additions & 0 deletions build/evergreen_config_lib/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,4 +1074,71 @@ def _check_allowed(self):

all_tasks = chain(all_tasks, OCSPTask.matrix())

class LoadBalancedTask(MatrixTask):
axes = OD([
('asan', [True]),
('build_ssl', ['openssl']), # The SSL library the C driver is built with.
('test_ssl', [True, False]), # Whether tests are run with SSL connections.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there are two Booleans there, does this mean "either true or false" or does one flag signify something else?

Copy link
Member

Choose a reason for hiding this comment

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

@kevinAlbs can confirm, but I think the list of values is used to build the matrix. So we'll end up with LB tests running both with and without SSL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jmikola is right. This is to build a matrix to test with SSL and without SSL. This is to satisfy the requirement in the load balancer test readme:

drivers MUST add two Evergreen tasks: one with a sharded cluster with both authentication and TLS enabled and one with a sharded cluster with authentication and TLS disabled.

The _check_allowed function below prevents generating tasks where authentication and TLS do not match.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, got it, thanks.

('test_auth', [True, False]),
('version', ['5.0', 'latest'])
])

def _check_allowed (self):
# Test with both SSL and auth, or neither.
prohibit (self.test_ssl != self.test_auth)

def __init__(self, *args, **kwargs):
super(LoadBalancedTask, self).__init__(*args, **kwargs)
if self.asan and self.build_ssl == "openssl":
self.add_dependency ('debug-compile-asan-clang-openssl')
self.add_tags('test-asan')
else:
raise RuntimeError ("unimplemented configuration for LoadBalancedTask")

self.add_tags(self.version)
self.options['exec_timeout_secs'] = 3600

# Return the task name.
# Example: test-loadbalanced-asan-auth-openssl-latest
@property
def name(self):
name = "test-loadbalanced"
if self.asan:
name += "-asan"
if self.test_auth:
name += "-auth"
else:
name += "-noauth"
if self.test_ssl:
name += "-" + self.build_ssl
else:
name += "-nossl"
if self.version:
name += "-" + self.version
return name

def to_dict(self):
task = super(MatrixTask, self).to_dict()
commands = task['commands']
commands.append(
func('fetch build', BUILD_NAME=self.depends_on['name']))


orchestration = bootstrap(TOPOLOGY='sharded_cluster',
AUTH='auth' if self.test_auth else 'noauth',
SSL='ssl' if self.test_ssl else 'nossl',
VERSION=self.version)
commands.append(orchestration)
commands.append (func("clone drivers-evergreen-tools"))
commands.append (func("start load balancer",
MONGODB_URI="mongodb://localhost:27017,localhost:27018"))
commands.append(run_tests(ASAN='on' if self.asan else 'off',
SSL='ssl' if self.test_ssl else 'nossl',
AUTH='auth' if self.test_auth else 'noauth',
LOADBALANCED='loadbalanced'))

return task

all_tasks = chain(all_tasks, LoadBalancedTask.matrix())

all_tasks = list(all_tasks)
2 changes: 1 addition & 1 deletion build/evergreen_config_lib/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def days(n):
], {}, batchtime=days(7)),
Variant ('packaging', 'Linux Distro Packaging', 'ubuntu1804-test', [
'debian-package-build',
OD([('name', 'rpm-package-build'), ('distros', ['rhel80-test'])]),
OD([('name', 'rpm-package-build'), ('distros', ['rhel82-arm64-small'])]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive-by fix. The config.yml file was manually updated in CDRIVER-4112 without the python generation files being updated.

], {}, batchtime=days(1)),
Variant('tsan-ubuntu',
'Thread Sanitizer (TSAN) Tests (Ubuntu 18.04)',
Expand Down
1 change: 1 addition & 0 deletions src/libmongoc/src/mongoc/mongoc-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,7 @@ _mongoc_cluster_stream_for_server (mongoc_cluster_t *cluster,
mongoc_server_stream_cleanup (server_stream);
mongoc_cluster_disconnect_node (cluster, server_id);
bson_mutex_unlock (&topology->mutex);
_mongoc_bson_init_if_set (reply);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a bug fix. If a reply argument is passed, callers expect it to always be initialized (even on error).

Copy link
Member

Choose a reason for hiding this comment

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

I assume no ticket is needed for this since it's fixing a bug from a previous PR that was never released. Correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, this was introduced in CDRIVER-4056: 4919d4f#diff-7723202fa2b19410a0b6dd42b6dda8d3708c52f85e7b553977c0bbe324031b41R2299

I do not think a ticket is necessary since CDRIVER-4056 is unreleased and is part of load balancer support.

return NULL;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libmongoc/src/mongoc/mongoc-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,9 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
}

ret = true;
} else if (server_type == MONGOC_SERVER_MONGOS) {
} else if (server_type == MONGOC_SERVER_MONGOS ||
server_stream->topology_type == MONGOC_TOPOLOGY_LOAD_BALANCED) {
/* TODO (CDRIVER-4117) remove the check of the topology description type. */
_mongoc_cmd_parts_assemble_mongos (parts, server_stream);
ret = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,10 @@ bool
mongoc_server_description_has_service_id (
const mongoc_server_description_t *description);

/* mongoc_global_mock_service_id is only used for testing. The test runner sets
* this to true when testing against a load balanced deployment to mock the
* presence of a serviceId field in the "hello" response. The purpose of this is
* further described in the Load Balancer test README. */
extern bool mongoc_global_mock_service_id;

#endif
12 changes: 12 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-server-description.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static bson_oid_t kObjectIdZero = {{0}};

const bson_oid_t kZeroServiceId = {{0}};

bool mongoc_global_mock_service_id = false;

static bool
_match_tag_set (const mongoc_server_description_t *sd,
bson_iter_t *tag_set_iter);
Expand Down Expand Up @@ -735,6 +737,16 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
}
}


if (mongoc_global_mock_service_id) {
bson_iter_t pid_iter;

if (bson_iter_init_find (&pid_iter, &sd->topology_version, "processId") &&
BSON_ITER_HOLDS_OID (&pid_iter)) {
bson_oid_copy (bson_iter_oid (&pid_iter), &sd->service_id);
}
}

if (is_shard) {
sd->type = MONGOC_SERVER_MONGOS;
} else if (sd->set_name) {
Expand Down
Loading