Skip to content
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

[build/dev] DSS local-instance cluster setup with haproxy #752

Merged
merged 6 commits into from
Apr 6, 2022

Conversation

pratibhagupta2109
Copy link
Contributor

No description provided.

DC_COMMAND=$*

if [[ "$DC_COMMAND" == "down" ]]; then
cleanup || true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to call cleanup function created below to stop the instances, but this call is not working at the moment. Let me know what is the right way to call this function. call :cleanup is also not working.

Copy link
Member

Choose a reason for hiding this comment

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

I think the function has to be declared before it is called in shell script

docker exec -it roacha cat haproxy.cfg > ~/Downloads/haproxy/haproxy.cfg

echo "Start the HAProxy container by mounting the cfg file."
docker run -d --name dss-crdb-cluster-for-testing --network dss_sandbox_default -p 26257:26257 -v ~/Downloads/haproxy:/usr/local/etc/haproxy:ro haproxy:1.7
Copy link
Contributor Author

Choose a reason for hiding this comment

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

atm, I am using ~/Downloads/haproxy from local machine to mount the volume for haproxy. Let me know if I should be using something else. I tried using /var/tmp/, but it didn't work.

Copy link
Member

Choose a reason for hiding this comment

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

Let's write haproxy.cfg to this folder (probably with a .gitignore entry to avoid committing to the repo) and then mount it as a single file: $(pwd)/haproxy.haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro


# Testing

In a different window, run [`./check_dss.sh`](check_dss.sh) to run a
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Invalid access token audience: localhost error is thrown while trying to run the test scripts. Is there anything I am missing while testing?

Copy link
Member

Choose a reason for hiding this comment

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

On line 159 of haproxy_local_setup.sh, core-service is started with -accepted_jwt_audiences local-gateway which means it's expecting any access tokens it receives to have the audience local-gateway. The various check*.sh all generate tokens with localhost, I think (though some might use host.docker.internal; I haven't checked). Probably the easiest way to solve the issue is to also accept tokens intended for localhost with -accepted_jwt_audiences local-gateway,localhost

DC_COMMAND=$*

if [[ "$DC_COMMAND" == "down" ]]; then
cleanup || true
Copy link
Member

Choose a reason for hiding this comment

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

I think the function has to be declared before it is called in shell script

echo "Starting roacha with admin port on :8080"
docker run -d --rm --name roacha \
-p 8080:8080 \
"$FLAGS" > /dev/null
Copy link
Member

Choose a reason for hiding this comment

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

We have to remove the quotes here because otherwise we get the error unknown flag: --network dss_sandbox_default cockroachdb/cockroach:v21.2.3 start --insecure --join. To turn off the shell lint error, add # shellcheck disable=SC2086.

docker rm -f dss-crdb-cluster-for-testing &> /dev/null || true

echo "Starting roacha with admin port on :8080"
docker run -d --rm --name roacha \
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting an error here because network dss_sandbox_default not found -- if we want to create the network first, we need docker network create dss_sandbox_default (this network is created automatically when the docker-compose run_locally system is brought up, but it is deleted when that system is brought down)

docker exec -it roacha cat haproxy.cfg > ~/Downloads/haproxy/haproxy.cfg

echo "Start the HAProxy container by mounting the cfg file."
docker run -d --name dss-crdb-cluster-for-testing --network dss_sandbox_default -p 26257:26257 -v ~/Downloads/haproxy:/usr/local/etc/haproxy:ro haproxy:1.7
Copy link
Member

Choose a reason for hiding this comment

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

Let's write haproxy.cfg to this folder (probably with a .gitignore entry to avoid committing to the repo) and then mount it as a single file: $(pwd)/haproxy.haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro


# Testing

In a different window, run [`./check_dss.sh`](check_dss.sh) to run a
Copy link
Member

Choose a reason for hiding this comment

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

On line 159 of haproxy_local_setup.sh, core-service is started with -accepted_jwt_audiences local-gateway which means it's expecting any access tokens it receives to have the audience local-gateway. The various check*.sh all generate tokens with localhost, I think (though some might use host.docker.internal; I haven't checked). Probably the easiest way to solve the issue is to also accept tokens intended for localhost with -accepted_jwt_audiences local-gateway,localhost


Setting up HAProxy requires generating a configuration file by running `cockroach gen haproxy` on one of the cluster nodes. that is preset to work with the running cluster. Generated `haproxy.cfg` file is then mounted to HAProxy container via local machine's ~/Download/haproxy/ folder.

# Testing
Copy link
Member

Choose a reason for hiding this comment

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

The important thing about this setup is that it enables resiliency to loss of database nodes. Let's add documentation to minimally demonstrate that. I would expect additional steps to kill a node, show the system still works, restore that node and kill a different one, show the system still works, etc

@BenjaminPelletier
Copy link
Member

Also, let's add a note in the documentation that the system can be cleaned up with ./haproxy_local_setup.sh down

@BenjaminPelletier BenjaminPelletier changed the title DSS local-instance cluster Setup [build/dev] DSS local-instance cluster setup with haproxy Apr 6, 2022
@BenjaminPelletier BenjaminPelletier merged commit 637a91c into interuss:master Apr 6, 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.

2 participants