Skip to content

Commit 8fb0173

Browse files
author
Uzziah Eyee
committed
Configured user-simulator to send spans to jaeger-agent.
1 parent 919cfe1 commit 8fb0173

File tree

7 files changed

+133
-80
lines changed

7 files changed

+133
-80
lines changed

docker-compose.dev.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
version: '3'
22

33
services:
4-
user-simulator:
4+
user-simulator:
55
build: user-simulator
66
env_file: user-simulator/.env
7+
environment:
8+
NODE_ENV: development
9+
JAEGER_SERVICE_NAME: user-simulator
10+
JAEGER_AGENT_HOST: jaeger-agent
11+
JAEGER_AGENT_PORT: 6832
12+
JAEGER_SAMPLER_TYPE: const
13+
JAEGER_SAMPLER_PARAM: 1
714
depends_on:
815
- api-server
916
- log-shipper
17+
ports:
18+
- "9230:9229" # nodejs debugging port
19+
command: wait.sh http://api-server:3000/health 5 20 "nodemon --inspect=0.0.0.0 ."
20+
volumes:
21+
- ./user-simulator/src:/usr/src/app
1022
networks:
1123
- aparnet
12-
24+
1325
api-server:
1426
build: api-server
1527
env_file: api-server/.env

user-simulator/.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.env
2-
/node_modules
2+
node_modules
33
npm-debug.log
44
.DS_Store

user-simulator/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.env
2-
/node_modules
2+
node_modules
33
npm-debug.log
44
.DS_Store

user-simulator/Dockerfile

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ FROM node:10.10.0-alpine
22

33
WORKDIR /usr/src/app
44

5+
RUN apk add --no-cache bash curl \
6+
&& npm install -g nodemon
7+
8+
COPY wait.sh /usr/local/bin/
9+
RUN chmod +x /usr/local/bin/wait.sh
10+
511
# optimization to only rebuild npm modules iff package[-lock].json changes
612
COPY src/package*.json ./
7-
813
# For production `RUN npm install --only=production`
914
RUN npm install
10-
1115
COPY src .
1216

13-
CMD ["npm", "start"]
17+
18+
CMD ["node", "."]

user-simulator/src/package-lock.json

+71-71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

user-simulator/src/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"axios": "^0.18.0",
14-
"dotenv": "^6.0.0",
15-
"node-cron": "^1.2.1"
14+
"node-cron": "^1.2.1",
15+
"jaeger-client": "^3.14.4"
1616
}
1717
}

user-simulator/wait.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Requires a container with Bash and Curl installed.
4+
5+
is_healthy () {
6+
retryInterval=${2:-5}
7+
maxAttempts=${3:-1000000}
8+
9+
i=0
10+
while [ $i -lt $maxAttempts ]
11+
do
12+
status=$(curl -s -L -o /dev/null -w %{http_code} $1)
13+
14+
# stop trying if we get a success response
15+
if [ $status -ge 200 ] && [ $status -lt 300 ]
16+
then
17+
return 0
18+
fi
19+
20+
((i++))
21+
echo "Attempt $i of $maxAttempts: Endpoint $1 returned code $status. Retrying in $retryInterval seconds."
22+
sleep $retryInterval
23+
done
24+
25+
return 1
26+
}
27+
28+
# args: endpoint, retryInterval (secs), maxAttempts, command
29+
if is_healthy $1 $2 $3
30+
then
31+
echo "Running command: $4"
32+
# vulnerable to input-injection attacts (but I don't care :)
33+
eval "$4"
34+
else
35+
echo "Exiting: Cannot run command because health-check failed."
36+
fi

0 commit comments

Comments
 (0)