Service mesh observability with Docker Compose
In this tutorial, you will create a local Consul service mesh and observability stack using Docker Compose. You will then explore your Consul service mesh with the observability suite.
The complexity of a service mesh environment requires advanced mechanisms to determine where services are running, the traffic patterns of the data flowing, and the health of the connections between them. Having this information makes it easier to not only understand failures occurring in your deployments, but also gives you the granularity needed to identify more subtle failures within your network such as performance degradation, packet loss, memory pressure, etc.
True service mesh observability consist of three core elements: metrics, logs and traces. To explore each of these elements, you will create an observability suite comprised of Prometheus (metrics), Loki (logs), Tempo (traces), and Grafana (visualization). Your Consul service mesh will host an example microservice application that will exhibit the ingress, API, and web layers. As you access the application; metrics, logs, and traces will be sent to your observability stack for you to explore.
This tutorial uses elements that are not suitable for production environments including an unsecured Consul datacenter, relaxed security policies, and container configurations only suited for development. The tutorial will teach you the core concepts for understanding and exploring observability in a Consul service mesh. Refer to the Consul Reference Architecture for Consul best practices and the Docker Documentation for Docker best practices.
Prerequisites
Linux or MacOS
Elements of this tutorial require a Linux or MacOS environment for deployment. See the Docker plugin page for more information about OS requirements.
Docker
You will need a local install of Docker running on your machine for this tutorial. You can find the instructions for installing Docker on your specific operating system here. Docker Engine 19.03.0 was tested in this tutorial.
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Visit the Docker Compose install guide for operating system specific installation instructions. Docker Compose format 3.7 was used in this tutorial.
Loki logging drivers
Install the Loki logging drivers for Docker. See the Loki Docker driver plugin page for more information.
GitHub repository
Clone the GitHub repository containing the configuration files and resources.
Change into the directory with the newly cloned repository. This directory contains the complete configuration files.
Environment overview
The observability suite provides insight into the metrics, logs, and traces that occur throughout the Consul service mesh. This diagram illustrates the components of the observability suite and Consul service mesh that you will create in this tutorial.
Create environment
From within your working directory, run the following Docker Compose command to create your local service mesh environment and observability suite.
Note
Your first run will take the longest as Docker will pull the respective images from the Docker Hub repository. Extra runs will not need you to download the image again and should only take a few seconds to complete.
Perform testing procedures
Perform the following steps of each section to explore the elements involved in the service mesh and observability suite.
Explore the Consul UI
Navigate to http://localhost:8500/ on your browser to access the Consul UI. Consul will navigate to the services tab by default.
Notice the services monitored by Consul. Each of the applications (ingress, web, and api) includes a sidecar proxy that makes up the service mesh.
Note
If your Consul UI details do not match the image above, restart your container stack environment.
Explore the sample application
Navigate to http://localhost:9090/ui/ and refresh the page to generate traffic.
The example application shows the architecture of your complete application stack. Each refresh of this page will generate extra logs, metrics, and traces that your observability suite will ingest.
Explore Prometheus targets
Navigate to http://localhost:9092/targets.
Notice that Prometheus is pre-configured to scrape metric-related data from four endpoints: Consul, Node-Exporter, Tempo, and itself.
Explore Grafana data sources
Navigate to http://localhost:3000/datasources.
Grafana is pre-configured with Prometheus, Loki, and Tempo as data sources. These sources enable Grafana to visualize metrics, logs, and traces.
Explore Logs and Traces
Navigate to http://localhost:3000/explore.
Execute a search with these parameters: {container_name="web"} |= "trace_id"
Open one of the log lines, locate the TraceID
field, then click the nearby Tempo
link to jump directly from logs to traces.
Using this functionality, notice how logs and traces provide insight into service mesh performance.
To learn more about how application communication traverses through the service mesh, see the distributed tracing article.
Explore Metrics
Navigate to http://localhost:3000/dashboards.
Explore the metrics-related dashboards: Consul Server Monitoring and Node Exporter.
The Consul Server Monitoring dashboard presents important application-level metrics for Consul while the Node Exporter dashboard presents system-level metrics. Each of these dimensions provides important insight into the health and performance of your service mesh.
To learn more about the various runtime metrics reported by Consul, see the Consul telemetry docs.
Clean up your environment
To clean up your environment, execute the following command.
Next steps
In this tutorial, you learned how to deploy and configure a local Consul service mesh and observability stack using Docker Compose. You also learned how to explore your Consul service mesh with the open source observability suite. Finally, you learned how to clean up your Docker environment.
You can continue learning the concepts of a secure Consul datacenter by completing the deploy a secure Consul datacenter with Docker Compose tutorial. This will teach you the concepts of Access Control Lists (ACLs), gossip encryption, and transport encryption.
You can also extend your Consul skills by exploring the following tutorials:
For additional reference documentation on the technologies and Docker images used in this guide, refer to the following websites: