The steps to set up an environment on Kubernetes is discussed in the
example codebase. A summary of the steps is:
-
Start minikube
minikube start
minikube dashboard
-
Deploy Prometheus - using the Prometheus Operator project to
capture metrics from the services
kubectl create -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/bundle.yaml
# Wait until pods are green, then add configuration to locate service monitors based on label "team: frontend":
kubectl create -f https://raw.githubusercontent.com/objectiser/opentracing-prometheus-example/master/prometheus-kubernetes.yml
# Wait until these pods are green, then get the URL from the following command and open in browser:
minikube service prometheus --url
-
Deploy Jaeger - an OpenTracing compatible tracing system
kubectl create -f https://raw.githubusercontent.com/jaegertracing/jaeger-kubernetes/master/all-in-one/jaeger-all-in-one-template.yml
# Once pods are green, then get the Jaeger dashboard URL from the following command and open in a browser
minikube service jaeger-query --url
-
For this article, we also deployed Grafana
to display the metrics, although the Prometheus dashboard could be used. Once Grafana is installed:
-
Obtain the Prometheus server URL using minikube service prometheus --url
-
Configure a new Datasource named Prometheus of type Prometheus
and specify the URL obtained from the previous command
-
Download the example dashboard using the following command and import it into Grafana
wget https://raw.githubusercontent.com/objectiser/opentracing-prometheus-example/master/simple/GrafanaDashboard.json
Once they are all running, then the simple example with the two services can be deployed. For this you will need to
clone the example code repo, and follow
these instructions.
At this stage the Kubernetes dashboard would look like this:
Figure 1: Kubernetes dashboard
The example code includes a script that loops, randomly invoking the three REST endpoints provided by
ordermgr. Once some example requests have been created, you can view the tracing dashboard:
Figure 2: Jaeger tracing dashboard
Then you can select a specific trace instance and see further details:
Figure 3: Jaeger trace instance view
This shows that the trace instance has three spans, the first representing the receipt of the /buy
request on
ordermgr, the second where ordermgr is invoking accountmgr, and finally the accountmgr receiving the
/hello
request. In this particular trace instance, the accountmgr invocation has reported an error, indicated
by the error=true
tag.
Now we will look at the Grafana dashboard to see what metrics have been reported from the OpenTracing
instrumentation within the two services:
Figure 4: Grafana dashboard
This dashboard includes three graphs, the first showing the number of spans created (i.e. span count) by
our sell()
method, and we can use it to track how many times this business operation has been executed.
The second showing the average duration of the spans, and third showing the ratio between successful and
erronous spans.
The metrics reported by Prometheus are based on a range of labels - a metric exists for each unique combination
of those labels.
The standard labels included with the OpenTracing java-metrics project are: operation
, span.kind
and error
.
With this particular example, we also included the transaction
label.
However when the services are deployed to Kubernetes, the following additional labels are included for free: pod
,
instance
, service
, job
and namespace
.
In our example Prometheus queries, we have ignored most of the Kubernetes added labels (except service
) so that
the metrics are aggregated across the specific pods, namespaces, etc. However, having these labels available means
it is possible to segment the metrics in whatever way is required to analyse the data.
When using the java-metrics
project outside of Kubernetes, it is still possible to include the service
label, however you would configure this when setting up the tracer.
We can also filter the data, to focus on specific areas of interest:
Figure 5: Customized Grafana graph focusing on metrics for transaction 'sell' and service 'accountmgr'
In this image we have filtered the metrics based on the transaction='sell'
and service='accountmgr'
. This is
where using the metric label based on the baggage item transaction
can be useful, to understand the
usage of a particular shared service by a business transaction. With further work it would be possible
to show the distribution of requests for a service across the various business transactions.