Files
robot-shop/README.md

129 lines
6.1 KiB
Markdown
Raw Permalink Normal View History

2018-03-20 10:57:22 +00:00
# Sample Microservice Application
2018-01-10 16:42:37 +00:00
2018-03-20 10:57:22 +00:00
Stan's Robot Shop is a sample microservice application you can use as a sandbox to test and learn containerised application orchestration and monitoring techniques. It is not intended to be a comprehensive reference example of how to write a microservices application, although you will better understand some of those concepts by playing with Stan's Robot Shop. To be clear, the error handling is patchy and there is not any security built into the application.
2018-01-10 16:42:37 +00:00
2018-03-20 10:57:22 +00:00
You can get more detailed information from my [blog post](https://www.instana.com/blog/stans-robot-shop-sample-microservice-application/) about this sample microservice application.
2018-03-02 17:12:11 +01:00
2018-03-20 10:57:22 +00:00
This sample microservice application has been built using these technologies:
2018-02-19 10:01:12 +00:00
- NodeJS ([Express](http://expressjs.com/))
2020-09-01 16:49:43 +01:00
- Java ([Spring Boot](https://spring.io/))
2018-02-19 10:01:12 +00:00
- Python ([Flask](http://flask.pocoo.org))
2018-02-01 13:21:23 +00:00
- Golang
2018-08-21 15:54:11 +01:00
- PHP (Apache)
2018-02-01 13:21:23 +00:00
- MongoDB
- Redis
2018-02-13 12:35:08 +00:00
- MySQL ([Maxmind](http://www.maxmind.com) data)
2018-02-01 13:21:23 +00:00
- RabbitMQ
2018-02-19 10:01:12 +00:00
- Nginx
- AngularJS (1.x)
2018-02-01 13:21:23 +00:00
2018-03-20 10:57:22 +00:00
The various services in the sample application already include all required Instana components installed and configured. The Instana components provide automatic instrumentation for complete end to end [tracing](https://docs.instana.io/core_concepts/tracing/), as well as complete visibility into time series metrics for all the technologies.
2018-02-19 10:01:12 +00:00
2018-03-20 12:14:12 +00:00
To see the application performance results in the Instana dashboard, you will first need an Instana account. Don't worry a [trial account](https://instana.com/trial?utm_source=github&utm_medium=robot_shop) is free.
2018-02-01 13:21:23 +00:00
## Build from Source
2019-12-10 11:21:09 +00:00
To optionally build from source (you will need a newish version of Docker to do this) use Docker Compose. Optionally edit the `.env` file to specify an alternative image registry and version tag; see the official [documentation](https://docs.docker.com/compose/env-file/) for more information.
2018-02-01 13:21:23 +00:00
2021-06-25 11:30:16 +01:00
To download the tracing module for Nginx, it needs a valid Instana agent key. Set this in the environment before starting the build.
```shell
$ export INSTANA_AGENT_KEY="<your agent key>"
```
Now build all the images.
2019-07-10 12:21:52 +01:00
```shell
$ docker-compose build
```
2018-02-01 13:21:23 +00:00
2019-12-10 11:21:09 +00:00
If you modified the `.env` file and changed the image registry, you need to push the images to that registry
2018-02-01 13:21:23 +00:00
2019-07-10 12:21:52 +01:00
```shell
$ docker-compose push
```
2018-02-01 13:21:23 +00:00
## Run Locally
2018-08-21 15:54:11 +01:00
You can run it locally for testing.
If you did not build from source, don't worry all the images are on Docker Hub. Just pull down those images first using:
2018-02-01 13:21:23 +00:00
2019-07-10 12:21:52 +01:00
```shell
$ docker-compose pull
```
2018-08-21 15:54:11 +01:00
Fire up Stan's Robot Shop with:
2019-07-10 12:21:52 +01:00
```shell
$ docker-compose up
```
2018-02-01 13:21:23 +00:00
2019-10-25 15:38:01 +01:00
If you want to fire up some load as well:
```shell
$ docker-compose -f docker-compose.yaml -f docker-compose-load.yaml up
```
2018-02-01 13:21:23 +00:00
If you are running it locally on a Linux host you can also run the Instana [agent](https://docs.instana.io/quick_start/agent_setup/container/docker/) locally, unfortunately the agent is currently not supported on Mac.
2019-10-25 15:38:01 +01:00
There is also only limited support on ARM architectures at the moment.
2019-06-21 11:53:54 +01:00
2018-04-17 16:18:23 -05:00
## Marathon / DCOS
The manifests for robotshop are in the *DCOS/* directory. These manifests were built using a fresh install of DCOS 1.11.0. They should work on a vanilla HA or single instance install.
You may install Instana via the DCOS package manager, instructions are here: https://github.com/dcos/examples/tree/master/instana-agent/1.9
2018-02-01 13:21:23 +00:00
## Kubernetes
2019-05-22 15:54:05 +01:00
You can run Kubernetes locally using [minikube](https://github.com/kubernetes/minikube) or on one of the many cloud providers.
2018-02-07 09:25:40 -05:00
2019-12-10 11:21:09 +00:00
The Docker container images are all available on [Docker Hub](https://hub.docker.com/u/robotshop/).
2018-02-01 13:21:23 +00:00
2020-05-05 12:22:25 +01:00
Install Stan's Robot Shop to your Kubernetes cluster using the [Helm](K8s/helm/README.md) chart.
2019-10-23 15:40:40 +01:00
2021-04-16 16:18:40 +01:00
To deploy the Instana agent to Kubernetes, just use the [helm](https://github.com/instana/helm-charts) chart.
2019-04-26 16:43:13 +01:00
## Accessing the Store
2018-02-01 13:21:23 +00:00
If you are running the store locally via *docker-compose up* then, the store front is available on localhost port 8080 [http://localhost:8080](http://localhost:8080/)
2020-05-05 12:22:25 +01:00
If you are running the store on Kubernetes via minikube then, find the IP address of Minikube and the Node Port of the web service.
2018-02-01 13:21:23 +00:00
2019-07-10 12:21:52 +01:00
```shell
$ minikube ip
2020-05-05 12:22:25 +01:00
$ kubectl get svc web
2019-07-10 12:21:52 +01:00
```
2018-02-01 13:21:23 +00:00
2019-05-22 15:54:05 +01:00
If you are using a cloud Kubernetes / Openshift / Mesosphere then it will be available on the load balancer of that system.
2018-02-13 12:35:08 +00:00
## Load Generation
2019-12-10 11:21:09 +00:00
A separate load generation utility is provided in the `load-gen` directory. This is not automatically run when the application is started. The load generator is built with Python and [Locust](https://locust.io). The `build.sh` script builds the Docker image, optionally taking *push* as the first argument to also push the image to the registry. The registry and tag settings are loaded from the `.env` file in the parent directory. The script `load-gen.sh` runs the image, it takes a number of command line arguments. You could run the container inside an orchestration system (K8s) as well if you want to, an example descriptor is provided in K8s directory. For more details see the [README](load-gen/README.md) in the load-gen directory.
2018-02-13 12:35:08 +00:00
## Website Monitoring / End-User Monitoring
2019-12-10 11:21:09 +00:00
### Docker Compose
2018-03-08 12:16:15 +00:00
To enable Website Monioring / End-User Monitoring (EUM) see the official [documentation](https://docs.instana.io/website_monitoring/) for how to create a configuration. There is no need to inject the JavaScript fragment into the page, this will be handled automatically. Just make a note of the unique key and set the environment variable `INSTANA_EUM_KEY` and `INSTANA_EUM_REPORTING_URL` for the web image within `docker-compose.yaml`.
2019-07-16 13:06:37 +01:00
2019-12-10 11:21:09 +00:00
### Kubernetes
The Helm chart for installing Stan's Robot Shop supports setting the key and endpoint url required for website monitoring, see the [README](K8s/helm/README.md).
2019-12-10 11:21:09 +00:00
2019-07-16 13:06:37 +01:00
## Prometheus
The cart and payment services both have Prometheus metric endpoints. These are accessible on `/metrics`. The cart service provides:
* Counter of the number of items added to the cart
The payment services provides:
* Counter of the number of items perchased
* Histogram of the total number of items in each cart
* Histogram of the total value of each cart
To test the metrics use:
```shell
$ curl http://<host>:8080/api/cart/metrics
$ curl http://<host>:8080/api/payment/metrics
```