A simple C++ server calculating fibonacci numbers times 2, to run in Istio Service Meshes.
To build the server, you need boost
and opentelemetry
to be installed.
The server uses boost/beast
as the HTTP/TCP library. And uses opentelemetry/otlp/http
as the exporter to send traces to jaeger (Jaeger Thrift
and OpenTracing API are deprecated as of early 2023).
Istio and minikube installation are required. Follow the Set Up Guide to do the installation.
Clone and enter the working directory:
git clone git@github.com:nishikinocurtis/bdml-lab1.git
cd bdml-lab1
Deploy jaeger:
kubectl apply -f jaeger.yaml
Build binary and docker image:
make
Load image to minikube:
minikube image load fib_server:v1.0
Deploy our service mesh:
kubectl apply -f fib.yaml
Start minikube tunnel (for istio ingress-gateway)
minikube tunnel
Setup istio gateway (Refer to this and this):
kubectl apply -f fib_gateway.yaml
export INGRESS_NAME=istio-ingressgateway
export INGRESS_NS=istio-system
export INGRESS_HOST=$(kubectl -n "$INGRESS_NS" get service "$INGRESS_NAME" -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n "$INGRESS_NS" get service "$INGRESS_NAME" -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
curl "http://${GATEWAY_URL}/fib?n=5"
Use the final command to verify everything runs normally.
Now that jaeger and our service are all set, launch Jaeger UI to view traces:
istioctl dashboard jaeger
Initially, there might be no trace at all, as the sampling rate is 1% at default. Make 100 more requests to see traces:
for i in $(seq 1 100); do curl -s -o /dev/null "http://${GATEWAY_URL}/fib?n=7"; done
Click into a trace can see the detailed information.
Now we can adjust the sampling rate.
Istio provides a way to adjust tracing settings
(and definitely more) via meshConfig
API.
By applying rate.yaml
to Istio globally,
we can set the sampling rate to 50%.
istioctl install -f rate.yaml
Now let's send another 20 requests to the server: change the parameter to distinguish them from previous ones.
for i in $(seq 1 20); do curl -s -o /dev/null "http://${GATEWAY_URL}/fib?n=8"; done
(We can verify) There are 7 traces collected for this round of requests. That's acceptable around 50%.
We can do more powerful trace after instrumenting codes.
You may also dump a JSON file through the dashboard, view the JSON file to see what it looks like.
We are all done! Remember to clean up the environment.
kubectl delete -f fib_gateway.yaml
kubectl delete -f fib.yaml
kubectl delete -f jaeger.yaml
And shutdown the minikube tunnel.