|
| 1 | +# gRPC-Observability Example |
| 2 | + |
| 3 | +## Features |
| 4 | + |
| 5 | +* End to end examples to generate the gRPC metrics with Prometheus, including: |
| 6 | + * A frontend microservice ( |
| 7 | + in [gRPC-Spring](https://github.com/grpc-ecosystem/grpc-spring)), which |
| 8 | + keeps calling the backend microservices. |
| 9 | + * A backend microservice ( |
| 10 | + in [gRPC-Spring](https://github.com/grpc-ecosystem/grpc-spring)), which |
| 11 | + serves unary/client streaming/server streaming and bidi streaming example |
| 12 | + services. |
| 13 | + * Instructions to containerize them and deploy them in kubernetes |
| 14 | +* Monitoring dashboards to support |
| 15 | + the [gRPC A66](https://github.com/grpc/proposal/blob/master/A66-otel-stats.md) |
| 16 | + spec. |
| 17 | +* Deploy the Grafana and import |
| 18 | + the [gRPC A66](https://github.com/grpc/proposal/blob/master/A66-otel-stats.md) |
| 19 | + dashboard |
| 20 | + |
| 21 | +## Build the end to end example |
| 22 | + |
| 23 | +Under the root directory of your grpc-spring repo |
| 24 | + |
| 25 | +``` |
| 26 | +./gradlew build |
| 27 | +``` |
| 28 | + |
| 29 | +## Run the end to end example |
| 30 | + |
| 31 | +Run the backend microservice locally |
| 32 | + |
| 33 | +``` |
| 34 | +./gradlew examples:grpc-observability:backend:bootRun |
| 35 | +``` |
| 36 | + |
| 37 | +Run the frontend microservice locally. Please note that the backend needs to be |
| 38 | +started first to be ready to serve the client calls. |
| 39 | + |
| 40 | +``` |
| 41 | +./gradlew examples:grpc-observability:frontend:bootRun |
| 42 | +``` |
| 43 | + |
| 44 | +The backend microservice will |
| 45 | + |
| 46 | +- listen on the TCP port 9091 for the gRPC calls from the frontend microservice. |
| 47 | +- listen on the TCP port 8081 for the Prometheus scrape requests. |
| 48 | + The frontend microservice will |
| 49 | +- send the unary/client streaming/server streaming/bidi streaming calls to the |
| 50 | + backend microservices via TCP port 9091. |
| 51 | +- listen on the TCP port 8080 for the Prometheus scrape requests. |
| 52 | + |
| 53 | +## Containerize the frontend/backend microservices |
| 54 | + |
| 55 | +Build the docker image for the backend microservice |
| 56 | + |
| 57 | +``` |
| 58 | +docker build -t grpc-observability/grpc-spring-example-backend examples/grpc-observability/backend |
| 59 | +``` |
| 60 | + |
| 61 | +Run the backend microservice with docker |
| 62 | + |
| 63 | +``` |
| 64 | +docker run --network host grpc-observability/grpc-spring-example-backend |
| 65 | +``` |
| 66 | + |
| 67 | +Build the docker image for the frontend microservice |
| 68 | + |
| 69 | +``` |
| 70 | +docker build -t grpc-observability/grpc-spring-example-frontend examples/grpc-observability/frontend |
| 71 | +``` |
| 72 | + |
| 73 | +Run the frontend microservice with docker |
| 74 | + |
| 75 | +``` |
| 76 | +docker run --network host grpc-observability/grpc-spring-example-frontend |
| 77 | +``` |
| 78 | + |
| 79 | +## Deploy the end to end example to kubernetes |
| 80 | + |
| 81 | +To deploy the example to kubernetes, please upload the docker images to a |
| 82 | +registry by yourself and modify the frontend.yaml/backend.yaml with your docker |
| 83 | +image location, and then run following commands. |
| 84 | + |
| 85 | +Deploy the backend microservice in kubernetes |
| 86 | + |
| 87 | +``` |
| 88 | +kubectl apply -f ./examples/grpc-observability/backend/backend.yaml |
| 89 | +``` |
| 90 | + |
| 91 | +Deploy the frontend microservice in kubernetes |
| 92 | + |
| 93 | +``` |
| 94 | +kubectl apply -f ./examples/grpc-observability/frontend/frontend.yaml |
| 95 | +``` |
| 96 | + |
| 97 | +## Set up the Prometheus to collect the gRPC metrics |
| 98 | + |
| 99 | +Once the frontend/backend microservices are deployed (either locally or on |
| 100 | +cloud), you may set up the Prometheus to start scrape the metrics from them. |
| 101 | +Depends on where you run the frontend/backend microservices, you may need to |
| 102 | +deploy the Prometheus to a proper location to be able to access them, such as, |
| 103 | +the same cloud, etc. |
| 104 | + |
| 105 | +If you |
| 106 | +use [Google Managed Prometheus](https://cloud.google.com/stackdriver/docs/managed-prometheus), |
| 107 | +you may need to configure the PodMonitoring resource to tell where are endpoints |
| 108 | +to scrape the Prometheus metrics. |
| 109 | +``` |
| 110 | +kubectl apply -f ./examples/grpc-observability/pod_monitoring.yaml |
| 111 | +``` |
| 112 | + |
| 113 | +## Set up the Grafana dashboard |
| 114 | + |
| 115 | +Once we have the gRPC metrics scraped by the Prometheus, we may set up a Grafana |
| 116 | +server to visualize them. |
| 117 | + |
| 118 | +- Set up a Grafana server, deploy it to a place where can connect the Prometheus |
| 119 | + server as its data source. |
| 120 | +- Create a Grafana dashboard by importing the |
| 121 | + grpc-observability/grafana/prometheus/microservices-grpc-dashboard.json file. |
| 122 | + |
| 123 | +If you |
| 124 | +use [Google Managed Prometheus](https://cloud.google.com/stackdriver/docs/managed-prometheus), |
| 125 | +you need to follow |
| 126 | +the [Grafana Query User Guide](https://cloud.google.com/stackdriver/docs/managed-prometheus/query) |
| 127 | +to set up the Grafana server |
| 128 | +and [data source syncer](https://github.com/GoogleCloudPlatform/prometheus-engine/tree/main/cmd/datasource-syncer). |
| 129 | + |
0 commit comments