Skip to content

Commit 1447946

Browse files
committed
docs (README): improve text and add four golden signals section
1 parent 64fcec9 commit 1447946

File tree

1 file changed

+77
-32
lines changed

1 file changed

+77
-32
lines changed

README.md

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ connection between this .NET project and the Prometheus server, we're using the
77

88
+ Related project :: [64J0/dotnet-builtin-metrics](https://github.com/64J0/dotnet-builtin-metrics).
99

10-
## Project components
10+
### Project components
1111

1212
In this project we're going to use the following tools and components:
1313

@@ -17,7 +17,33 @@ In this project we're going to use the following tools and components:
1717
* Prometheus
1818
* Grafana
1919

20-
## How to run the containerized project?
20+
## What should we monitor?
21+
22+
For this project, I'm considering the four golden signals, as defined at
23+
Google's SRE book: [link](https://sre.google/sre-book/monitoring-distributed-systems/#xref_monitoring_golden-signals).
24+
25+
> The four golden signals of monitoring are latency, traffic, errors, and
26+
> saturation. If you can only measure four metrics of your user-facing system,
27+
> focus on these four. [...] If you measure all four golden signals and page a
28+
> human when one signal is problematic (or, in the case of saturation, nearly
29+
> problematic), your service will be at least decently covered by monitoring.
30+
31+
The following table presents how we can get each signal information with this
32+
current code configuration:
33+
34+
| Signal | Description | How to get |
35+
|------------|-----------------------------------------|--------------------------|
36+
| Latency | The time it takes to service a request. | `requestDuration` |
37+
| Traffic | HTTP requests per second. | `requestCounter` |
38+
| Errors | The rate of requests that fail. | Combination of both |
39+
| Saturation | How "full" your service is. | Other Prometheus metrics |
40+
41+
1. Notice that `requestDuration` and `requestCounter` are the custom middlewares
42+
defined at the API.
43+
44+
## How to run?
45+
46+
### How to run the containerized project?
2147

2248
Make sure you have the following tools installed:
2349

@@ -27,78 +53,97 @@ Make sure you have the following tools installed:
2753
Then, you can use the following commands:
2854

2955
```bash
30-
# recommended process using `docker compose'
56+
# Option 1:
57+
#
3158
docker compose up -d
3259

33-
# if you don't want to use the `docker compose' command, you can, first
60+
#
61+
# ===============================================================
62+
#
63+
64+
# Option 2:
65+
#
66+
# If you don't want to use the `docker compose' command, you can, first
3467
# build the docker image for the API
3568
docker build -t fsharp-api:v1 .
3669

37-
# you can run the API in a standalone process, although this is not
38-
# my recommended process. Use the `docker-compose' command instead.
39-
docker run -d -e HOST="0.0.0.0" -p 8085:8085 -p 9085:9085 fsharp-api:v1
70+
# Then, you can run the API in a standalone container
71+
docker run -d -p 8085:8085 -p 9085:9085 fsharp-api:v1
4072
```
4173

42-
When this project is running you can visit `http://localhost:9090` and start
43-
grabbing the metrics for our project from the Prometheus interface. The
44-
docker-compose configuration for the Prometheus service was mainly inspired by
74+
While this project is running, you can visit `http://localhost:9090` and start
75+
checking the metrics for the API from the Prometheus interface. The
76+
docker compose configuration for the Prometheus service was mainly inspired by
4577
[this reference](https://github.com/vegasbrianc/prometheus/blob/master/docker-compose.yml).
4678

47-
## How to run the API locally?
79+
### How to run the API locally?
4880

4981
For further improvements in the API code, I recommend running the project with a
50-
local .NET SDK service. In the context of the most recent development, I'm using
51-
the following version:
82+
local .NET SDK, since it's faster to iterate through the changes.
5283

53-
* `.NET SDK version 9.0.xxx`
84+
* .NET SDK version: 9.0.xxx
5485

5586
```bash
56-
# use this command to check your installed .NET SDK versions
87+
# Use this command to list .NET SDKs installed
5788
dotnet --list-sdks
5889
```
5990

6091
Next step is to install the required dependencies, using the following commands:
6192

6293
```bash
63-
# get inside the API directory
94+
# 1. Get inside the API directory
6495
cd fsharp-api/
6596

66-
# restore nuget packages
97+
# 2. Restore nuget packages
6798
dotnet restore
6899

69-
# make sure you can build the project
100+
# 3. Build the project
70101
dotnet build
71102

72-
# start the server
103+
# 4. Start the server
73104
dotnet run
74105
# watch mode for development
75106
# dotnet watch run
76107
```
77108

78-
## How to test it?
109+
## How to test it manually?
110+
111+
This API consists in basically 3 endpoints:
112+
113+
- GET `/health`
114+
- GET `/ping/%s`
115+
- POST `/api/prediction`
116+
117+
And you can test them manually with the following commands:
79118

80119
```bash
81-
# health endpoint
120+
# 1. Health endpoint
82121
curl localhost:8085/health
83-
# result:
84-
# API instance is healthy!
122+
# Response:
123+
# {"message":"API instance is healthy!"}
124+
125+
# =================================
126+
127+
# 2. Ping endpoint
128+
curl localhost:8085/ping/abc
129+
# Response:
130+
# {"message":"Pong from foo!"}
131+
132+
# =================================
85133

86-
# trying the POST endpoint
134+
# 3. Prediction endpoint
87135
curl -X POST \
88136
-H "Accept: application/json" \
89137
-d '{"id":1, "crimesPerCapta":0.01}' \
90138
localhost:8085/api/prediction
91-
# result:
92-
# Request OK
93-
# Id: 1
94-
# CrimesPerCapta: 0.010000
95-
# Price Prediction: 27.148332
139+
# Response:
140+
# {"message":"OK","id":1,"crimesPerCapta":0.01,"pricePrediction":27.148331825982115}
96141
```
97142

98-
You can later see the metrics by visiting `http://localhost:8085/metrics` in
143+
You can later see the metrics by visiting `http://localhost:9085/metrics` in
99144
your browser.
100145

101-
# Resource allocation
146+
## Resource allocation
102147

103148
Since this project uses a bunch of other services, I decided to limit the
104149
resources allocated for them. If you notice that some piece is not working
@@ -108,7 +153,7 @@ If you want to check how much resources your containers are currently consuming,
108153
you can use the following command in the terminal:
109154

110155
```bash
111-
# check the resources usage for the containers
156+
# Check the resources usage for the containers in real time
112157
docker stats
113158
```
114159

0 commit comments

Comments
 (0)