Skip to content

GODRIVER-3061 Support Load Balancing in Docker Container #1494

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 24 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ timeout:
ls -la
functions:
fetch-source:
# Executes git clone and applies the submitted patch, if any
# Executes clone and applies the submitted patch, if any
- command: git.get_project
type: system
params:
Expand Down Expand Up @@ -1526,8 +1526,8 @@ tasks:
- func: run-atlas-data-lake-test

- name: test-docker-runner
tags: ["pullrequest"]
commands:
- func: bootstrap-mongo-orchestration
- func: run-docker-test

- name: test-load-balancer-noauth-nossl
Expand Down Expand Up @@ -2585,6 +2585,7 @@ buildvariants:
- name: "test-atlas-data-lake"

- name: docker-runner-test
tags: ["pullrequest"]
display_name: "Docker Runner Test"
run_on:
- ubuntu2204-large
Expand Down
1 change: 0 additions & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fi

export GOROOT="${GOROOT}"
export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
export PATH="${MONGODB_BINARIES:-$DRIVERS_TOOLS/mongodb/bin}:$PATH"
export PROJECT="${project}"
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64
Expand Down
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ COPY etc/install-libmongocrypt.sh /root/install-libmongocrypt.sh
RUN cd /root && bash ./install-libmongocrypt.sh


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

# Install common deps.
RUN export DEBIAN_FRONTEND=noninteractive && \
export TZ=Etc/UTC && \
apt-get -qq update && \
apt-get -qqy install --reinstall --no-install-recommends \
git \
ca-certificates \
curl \
wget \
sudo \
tzdata \
ca-certificates \
pkg-config \
Expand All @@ -50,4 +54,6 @@ COPY ./etc/docker_entry.sh /root/docker_entry.sh

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

ENV DOCKER_RUNNING=true

ENTRYPOINT ["/bin/bash", "/root/docker_entry.sh"]
41 changes: 39 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,56 @@ The usage of host.docker.internal comes from the [Docker networking documentatio

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.

### Load Balancer

To launch the load balancer on MacOS, run the following.

- `brew install haproxy`
- Clone drivers-evergreen-tools and save the path as `DRIVERS_TOOLS`.
- Start the servers using (or use the docker-based method below):

```bash
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
```

- Start the load balancer using:

```bash
MONGODB_URI='mongodb://localhost:27017,localhost:27018/' $PWD/drivers-evergreen-tools/.evergreen/run-load-balancer.sh start
```

- Run the load balancer tests (or use the docker runner below with `evg-test-load-balancers`):

```bash
make evg-test-load-balancers
```

### Testing in Docker

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.

1. First, start the drivers-tools server docker container, as:

```bash
bash $DRIVERS_TOOLS/.evergreen/docker/start-server.sh
```

See the readme in `$DRIVERS_TOOLS/.evergreen/docker` for more information on usage.

2. Next, start any other required services in another terminal, like a load balancer.

1. Finally, run the Go Driver tests using the following script in this repo:

```bash
bash etc/run_docker.sh
```

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

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

```bash
TOPOLOGY=sharded_cluster bash etc/run_docker.sh evg-test-enterprise-auth
Expand Down
7 changes: 2 additions & 5 deletions etc/docker_entry.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/usr/bin/env bash
#
# Entry point for Dockerfile for launching a server and running a go test.
# Entry point for Dockerfile for running a go test.
#
set -eux

# Start the server.
bash /root/base-entrypoint.sh
source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh

# Prep files.
cd /src
rm -f test.suite
cp -r $HOME/install ./install

export PATH="$MONGODB_BINARIES:$PATH"

# Run the test.
Expand Down
24 changes: 4 additions & 20 deletions etc/run_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,17 @@ if [ -z "$DRIVERS_TOOLS" ]; then
exit 1
fi
PLATFORM=${DOCKER_PLATFORM:-}

pushd $DRIVERS_TOOLS/.evergreen/docker/ubuntu20.04
docker build $PLATFORM -t drivers-evergreen-tools .
popd
docker build $PLATFORM -t go-test .

# Handle environment variables and optional positional arg for the makefile target.

MAKEFILE_TARGET=${1:-evg-test-versioned-api}
MONGODB_VERSION=${MONGODB_VERSION:-latest}
TOPOLOGY=${TOPOLOGY:-replica_set}
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json}
AUTH=${AUTH:-""}
SSL=${SSL:=""}
GO_BUILD_TAGS=${GO_BUILD_TAGS:-""}

ENV="-e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY"
ENV="$ENV -e MAKEFILE_TARGET=$MAKEFILE_TARGET -e AUTH=$AUTH"
ENV="$ENV -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE -e SSL=$SSL"
ENV="$ENV -e GO_BUILD_TAGS=$GO_BUILD_TAGS"

VOL="-v `pwd`:/src"
VOL="$VOL -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools"
USE_TTY=""
test -t 1 && USE_TTY="-t"
ARGS=" -e MAKEFILE_TARGET=$MAKEFILE_TARGET"
ARGS="$ARGS -e GO_BUILD_TAGS=$GO_BUILD_TAGS"
ARGS="$ARGS go-test"

docker run $PLATFORM --rm $VOL $ENV -i $USE_TTY go-test
$DRIVERS_TOOLS/.evergreen/docker/run-client.sh $ARGS
if [ -f "test.suite" ]; then
tail test.suite
fi
3 changes: 3 additions & 0 deletions mongo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ func TestClient(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("skipping test in docker environment")
}

t.Run(tc.name, func(t *testing.T) {
// Setup a client and skip the test based on server version.
Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/mtest/opmsg_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
serverAddress = address.Address("localhost:27017")
serverAddress = address.Address("127.0.0.1:27017")
maxDocumentSize uint32 = 16777216
maxMessageSize uint32 = 48000000
maxBatchCount uint32 = 100000
Expand Down
4 changes: 4 additions & 0 deletions mongo/with_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"math"
"os"
"strconv"
"strings"
"testing"
Expand All @@ -37,6 +38,9 @@ func TestConvenientTransactions(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("skipping test in docker environment")
}

client := setupConvenientTransactions(t)
db := client.Database("TestConvenientTransactions")
Expand Down
9 changes: 9 additions & 0 deletions x/mongo/driver/operation/hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package operation

import (
"fmt"
"os"
"runtime"
"testing"

Expand Down Expand Up @@ -142,6 +143,10 @@ func TestAppendClientDriver(t *testing.T) {
func TestAppendClientEnv(t *testing.T) {
clearTestEnv(t)

if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("These tests gives different results when run in Docker due to extra environment data.")
}

tests := []struct {
name string
omitEnvFields bool
Expand Down Expand Up @@ -377,6 +382,10 @@ func TestAppendClientPlatform(t *testing.T) {
func TestEncodeClientMetadata(t *testing.T) {
clearTestEnv(t)

if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("These tests gives different results when run in Docker due to extra environment data.")
}

type application struct {
Name string `bson:"name"`
}
Expand Down
3 changes: 3 additions & 0 deletions x/mongo/driver/topology/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func TestServerHeartbeatTimeout(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
if os.Getenv("DOCKER_RUNNING") != "" {
t.Skip("Skipping this test in docker.")
}

networkTimeoutError := &net.DNSError{
IsTimeout: true,
Expand Down