Skip to content

Commit d46f29c

Browse files
GODRIVER-3061 Support Load Balancing in Docker Container (mongodb#1494)
Co-authored-by: Qingyang Hu <[email protected]>
1 parent 820366e commit d46f29c

File tree

11 files changed

+77
-34
lines changed

11 files changed

+77
-34
lines changed

.evergreen/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ timeout:
2727
ls -la
2828
functions:
2929
fetch-source:
30-
# Executes git clone and applies the submitted patch, if any
30+
# Executes clone and applies the submitted patch, if any
3131
- command: git.get_project
3232
type: system
3333
params:
@@ -1526,8 +1526,8 @@ tasks:
15261526
- func: run-atlas-data-lake-test
15271527

15281528
- name: test-docker-runner
1529-
tags: ["pullrequest"]
15301529
commands:
1530+
- func: bootstrap-mongo-orchestration
15311531
- func: run-docker-test
15321532

15331533
- name: test-load-balancer-noauth-nossl
@@ -2585,6 +2585,7 @@ buildvariants:
25852585
- name: "test-atlas-data-lake"
25862586

25872587
- name: docker-runner-test
2588+
tags: ["pullrequest"]
25882589
display_name: "Docker Runner Test"
25892590
run_on:
25902591
- ubuntu2204-large

.evergreen/run-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fi
1818

1919
export GOROOT="${GOROOT}"
2020
export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
21-
export PATH="${MONGODB_BINARIES:-$DRIVERS_TOOLS/mongodb/bin}:$PATH"
2221
export PROJECT="${project}"
2322
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
2423
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ COPY etc/install-libmongocrypt.sh /root/install-libmongocrypt.sh
1616
RUN cd /root && bash ./install-libmongocrypt.sh
1717

1818

19-
# Inherit from the drivers-evergreen-tools image and copy in the files
20-
# from the libmongocrypt build stage.
21-
FROM drivers-evergreen-tools
19+
# Copy in the files from the libmongocrypt build stage.
20+
FROM ubuntu:20.04
2221

2322
# Install common deps.
2423
RUN export DEBIAN_FRONTEND=noninteractive && \
2524
export TZ=Etc/UTC && \
2625
apt-get -qq update && \
2726
apt-get -qqy install --reinstall --no-install-recommends \
27+
git \
28+
ca-certificates \
29+
curl \
30+
wget \
31+
sudo \
2832
tzdata \
2933
ca-certificates \
3034
pkg-config \
@@ -50,4 +54,6 @@ COPY ./etc/docker_entry.sh /root/docker_entry.sh
5054

5155
COPY --from=libmongocrypt /root/install /root/install
5256

57+
ENV DOCKER_RUNNING=true
58+
5359
ENTRYPOINT ["/bin/bash", "/root/docker_entry.sh"]

docs/CONTRIBUTING.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,56 @@ The usage of host.docker.internal comes from the [Docker networking documentatio
152152

153153
There is currently no arm64 support for the go1.x runtime, see [here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). Known issues running on linux/arm64 include the inability to network with the localhost from the public.ecr.aws/lambda/go Docker image.
154154

155+
### Load Balancer
156+
157+
To launch the load balancer on MacOS, run the following.
158+
159+
- `brew install haproxy`
160+
- Clone drivers-evergreen-tools and save the path as `DRIVERS_TOOLS`.
161+
- Start the servers using (or use the docker-based method below):
162+
163+
```bash
164+
LOAD_BALANCER=true TOPOLOGY=sharded_cluster AUTH=noauth SSL=nossl MONGODB_VERSION=6.0 DRIVERS_TOOLS=$PWD/drivers-evergreen-tools MONGO_ORCHESTRATION_HOME=$PWD/drivers-evergreen-tools/.evergreen/orchestration $PWD/drivers-evergreen-tools/.evergreen/run-orchestration.sh
165+
```
166+
167+
- Start the load balancer using:
168+
169+
```bash
170+
MONGODB_URI='mongodb://localhost:27017,localhost:27018/' $PWD/drivers-evergreen-tools/.evergreen/run-load-balancer.sh start
171+
```
172+
173+
- Run the load balancer tests (or use the docker runner below with `evg-test-load-balancers`):
174+
175+
```bash
176+
make evg-test-load-balancers
177+
```
178+
155179
### Testing in Docker
156180

157181
We support local testing in Docker. To test using docker, you will need to set the `DRIVERS_TOOLs` environment variable to point to a local clone of the drivers-evergreen-tools repository. This is essential for running the testing matrix in a container. You can set the `DRIVERS_TOOLS` variable in your shell profile or in your project-specific environment.
158182

183+
1. First, start the drivers-tools server docker container, as:
184+
185+
```bash
186+
bash $DRIVERS_TOOLS/.evergreen/docker/start-server.sh
187+
```
188+
189+
See the readme in `$DRIVERS_TOOLS/.evergreen/docker` for more information on usage.
190+
191+
2. Next, start any other required services in another terminal, like a load balancer.
192+
193+
1. Finally, run the Go Driver tests using the following script in this repo:
194+
159195
```bash
160196
bash etc/run_docker.sh
161197
```
162198

163199
The script takes an optional argument for the `MAKEFILE_TARGET` and allows for some environment variable overrides.
164200
The docker container has the required binaries, including libmongocrypt.
165-
The entry script starts a MongoDB topology, and then executes the desired `MAKEFILE_TARGET`.
201+
The entry script executes the desired `MAKEFILE_TARGET`.
166202

167-
For example, to test against a sharded cluster, using enterprise auth, run:
203+
For example, to test against a sharded cluster (make sure you started the server with a sharded_cluster),
204+
using enterprise auth, run:
168205

169206
```bash
170207
TOPOLOGY=sharded_cluster bash etc/run_docker.sh evg-test-enterprise-auth

etc/docker_entry.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#!/usr/bin/env bash
22
#
3-
# Entry point for Dockerfile for launching a server and running a go test.
3+
# Entry point for Dockerfile for running a go test.
44
#
55
set -eux
66

7-
# Start the server.
8-
bash /root/base-entrypoint.sh
9-
source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh
10-
117
# Prep files.
128
cd /src
139
rm -f test.suite
1410
cp -r $HOME/install ./install
11+
1512
export PATH="$MONGODB_BINARIES:$PATH"
1613

1714
# Run the test.

etc/run_docker.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,17 @@ if [ -z "$DRIVERS_TOOLS" ]; then
88
exit 1
99
fi
1010
PLATFORM=${DOCKER_PLATFORM:-}
11-
12-
pushd $DRIVERS_TOOLS/.evergreen/docker/ubuntu20.04
13-
docker build $PLATFORM -t drivers-evergreen-tools .
14-
popd
1511
docker build $PLATFORM -t go-test .
1612

1713
# Handle environment variables and optional positional arg for the makefile target.
18-
1914
MAKEFILE_TARGET=${1:-evg-test-versioned-api}
20-
MONGODB_VERSION=${MONGODB_VERSION:-latest}
21-
TOPOLOGY=${TOPOLOGY:-replica_set}
22-
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json}
23-
AUTH=${AUTH:-""}
24-
SSL=${SSL:=""}
2515
GO_BUILD_TAGS=${GO_BUILD_TAGS:-""}
2616

27-
ENV="-e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY"
28-
ENV="$ENV -e MAKEFILE_TARGET=$MAKEFILE_TARGET -e AUTH=$AUTH"
29-
ENV="$ENV -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE -e SSL=$SSL"
30-
ENV="$ENV -e GO_BUILD_TAGS=$GO_BUILD_TAGS"
31-
32-
VOL="-v `pwd`:/src"
33-
VOL="$VOL -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools"
34-
USE_TTY=""
35-
test -t 1 && USE_TTY="-t"
17+
ARGS=" -e MAKEFILE_TARGET=$MAKEFILE_TARGET"
18+
ARGS="$ARGS -e GO_BUILD_TAGS=$GO_BUILD_TAGS"
19+
ARGS="$ARGS go-test"
3620

37-
docker run $PLATFORM --rm $VOL $ENV -i $USE_TTY go-test
21+
$DRIVERS_TOOLS/.evergreen/docker/run-client.sh $ARGS
3822
if [ -f "test.suite" ]; then
3923
tail test.suite
4024
fi

mongo/client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ func TestClient(t *testing.T) {
337337
if testing.Short() {
338338
t.Skip("skipping integration test in short mode")
339339
}
340+
if os.Getenv("DOCKER_RUNNING") != "" {
341+
t.Skip("skipping test in docker environment")
342+
}
340343

341344
t.Run(tc.name, func(t *testing.T) {
342345
// Setup a client and skip the test based on server version.

mongo/integration/mtest/opmsg_deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
const (
24-
serverAddress = address.Address("localhost:27017")
24+
serverAddress = address.Address("127.0.0.1:27017")
2525
maxDocumentSize uint32 = 16777216
2626
maxMessageSize uint32 = 48000000
2727
maxBatchCount uint32 = 100000

mongo/with_transactions_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"math"
14+
"os"
1415
"strconv"
1516
"strings"
1617
"testing"
@@ -37,6 +38,9 @@ func TestConvenientTransactions(t *testing.T) {
3738
if testing.Short() {
3839
t.Skip("skipping integration test in short mode")
3940
}
41+
if os.Getenv("DOCKER_RUNNING") != "" {
42+
t.Skip("skipping test in docker environment")
43+
}
4044

4145
client := setupConvenientTransactions(t)
4246
db := client.Database("TestConvenientTransactions")

x/mongo/driver/operation/hello_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package operation
88

99
import (
1010
"fmt"
11+
"os"
1112
"runtime"
1213
"testing"
1314

@@ -142,6 +143,10 @@ func TestAppendClientDriver(t *testing.T) {
142143
func TestAppendClientEnv(t *testing.T) {
143144
clearTestEnv(t)
144145

146+
if os.Getenv("DOCKER_RUNNING") != "" {
147+
t.Skip("These tests gives different results when run in Docker due to extra environment data.")
148+
}
149+
145150
tests := []struct {
146151
name string
147152
omitEnvFields bool
@@ -377,6 +382,10 @@ func TestAppendClientPlatform(t *testing.T) {
377382
func TestEncodeClientMetadata(t *testing.T) {
378383
clearTestEnv(t)
379384

385+
if os.Getenv("DOCKER_RUNNING") != "" {
386+
t.Skip("These tests gives different results when run in Docker due to extra environment data.")
387+
}
388+
380389
type application struct {
381390
Name string `bson:"name"`
382391
}

x/mongo/driver/topology/server_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func TestServerHeartbeatTimeout(t *testing.T) {
131131
if testing.Short() {
132132
t.Skip("skipping integration test in short mode")
133133
}
134+
if os.Getenv("DOCKER_RUNNING") != "" {
135+
t.Skip("Skipping this test in docker.")
136+
}
134137

135138
networkTimeoutError := &net.DNSError{
136139
IsTimeout: true,

0 commit comments

Comments
 (0)