Skip to content

Commit

Permalink
[Example] Improve Cipher demo (#16)
Browse files Browse the repository at this point in the history
* Add `MakeFile`s that make it easy to spin up the needed infra,
  startup the Cipher server, and Go workers
* Update README.md for the Cipher demo

Signed-off-by: lloydmeta <[email protected]>
  • Loading branch information
lloydmeta authored Mar 2, 2020
1 parent ef65298 commit 6111a8b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
19 changes: 19 additions & 0 deletions example/ciphers/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GO_WORKER_COUNT ?= 5

install-eck:
@$(MAKE) install-eck -C k8s

k8s-deploy:
@$(MAKE) deploy -C k8s

k8s-teardown:
@$(MAKE) teardown -C k8s

k8s-show-credentials:
@$(MAKE) show-credentials -C k8s

start-go-workers:
@worker-go/start-workers ${GO_WORKER_COUNT}

start-cipher-server:
@server/start-server
31 changes: 19 additions & 12 deletions example/ciphers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ This is an example server-worker app.

### Setup

If you have k8s installed, you can use the Makefile in the `k8s` dir to install ECK, spin up the needed infra,
and get credentials that you can put into the relevant config files.
If you don't have [Kubernetes](https://kubernetes.io) installed, install it.

If you don't you'll need to spin these up separately.
If you don't have EC installed, run `make install-eck` to install the [ECK](https://www.elastic.co/guide/en/cloud-on-k8s/current/index.html) operator.

### Run the Tasques server

In the project root dir, start a Tasques server (`go run ./app`)
Run `make k8s-deploy` to deploy all the needed infra, such as Tasques, including ES clusters (for tasques and our demo app),
Kibana, and APM.

### Run the Ciphers server

On `example/ciphers/server`, run `go run main.go`
Run `make start-cipher-server` to start the web server for Ciphers. It will wait for the previous services to be ready before
starting.

#### Add some Messages to cipher

Go to the server at [localhost:9000](http://localhost:9000) (default) and create messages, which will create jobs.
Once the Ciphers server is up, go to the server at [localhost:9000](http://localhost:9000) (default) and use the form to
create plain text messages, which will create jobs to have them encoded by workers.

### Start the Go worker
### Run the Ciphers Go workers

In `example/ciphers/worker-go`, run `go run main.go --worker-id worker1` replacing `worker1` with a unique worker id
per worker process.
Run `make start-go-workers` to start a number of Go Cipher workers. By default, we start 5, but you can customise this using
`GO_WORKER_COUNT` (e.g. `GO_WORKER_COUNT=10 make start-go-workers`). Also note that half of the workers are configured
to have a chance of failure, and all have an artificial pause to simulate load.

#### Workers in other languages

There are example workers in Java and Rust as well (`worker-$lang`)
There are example workers in Java and Rust as well (`worker-$lang`)

### Kibana Dashboard

1. To log into the Tasques server's Kibana, run `make k8s-show-credentials` and get the password of the **Tasques** cluster.
2. Then go to [localhost:5601](http://localhost:5601) and use `elastic` and the password retrieved in the previous step.
3. Use the Kibana navigation bar to go to Dashboards, then select the `tasques` dashboard from the list.
15 changes: 15 additions & 0 deletions example/ciphers/server/start-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

cd "$(dirname "$0")"

while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080/recurring_tasques)" != "200" ]]; do
echo "Waiting for Tasques server to come online ..."
sleep 5;
done

while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9201)" != "200" ]]; do
echo "Waiting for Cipher ES server to come online ..."
sleep 5;
done

go run main.go
47 changes: 47 additions & 0 deletions example/ciphers/worker-go/start-workers
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"
worker_process_ids=()

function kill_workers() {
echo "Sending SIGINT to workers workers"
for pid in "${worker_process_ids[@]}"; do
kill -2 $pid
done
exit 0
}

number_of_workers=$1

number_re='^[0-9]+$'
if ! [[ $number_of_workers =~ $number_re ]]; then
echo "Error: Worker number argument (first and only) not a number" >&2; exit 1
fi

trap kill_workers SIGINT SIGTERM SIGHUP

while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080/recurring_tasques)" != "200" ]]; do
echo "Waiting for Tasques server to come online ..."
sleep 5;
done

while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9201)" != "200" ]]; do
echo "Waiting for Cipher ES server to come online ..."
sleep 5;
done

for ((i=0; i<number_of_workers; i++)); do
worker_id="go-worker-${i}"
echo "Starting ${worker_id} .."
if [ $((i%2)) -eq 0 ]; then
go run main.go --worker-id ${worker_id} &
else
go run main.go --worker-id ${worker_id} -f true &
fi
worker_process_ids+=($!)
done

echo "Workers started, hit CTRL+C to stop"

while true; do
sleep 1;
done

0 comments on commit 6111a8b

Please sign in to comment.