Skip to content

Commit

Permalink
wip: example dashboard for grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
dhontecillas committed Feb 9, 2024
1 parent d4e3955 commit ac63bfb
Show file tree
Hide file tree
Showing 25 changed files with 1,206 additions and 318 deletions.
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ Example:

### Layers

We can differentiate the processing of a request in KrakenD in 3 main stages:
We can differentiate the processing of a request in KrakenD in 3 main stages (each one
including or wrapping the inner stage):

- `router`: the part that comes before the `Lura`'s framework starts working with
- `global`: this part that comes before the `Lura`'s framework starts working with
the request. In the case of [KrakenD CE](https://github.com/krakend/krakend-ce),
this stage is implemented usin [gin](https://github.com/gin-gonic/gin)

Expand All @@ -104,7 +105,7 @@ We can differentiate the processing of a request in KrakenD in 3 main stages:
For each of those layers it can be selected the deatail of metrics and traces
that we want to report.

#### router
#### global

At the router level we have 3 main options:

Expand All @@ -114,7 +115,7 @@ At the router level we have 3 main options:
traces (so spans from a previous layer are linked to the KrakenD trace).

```json
"router": {
"global": {
"disable_metrics": false,
"disable_traces": false,
"disable_propagation": false
Expand All @@ -123,12 +124,12 @@ At the router level we have 3 main options:

##### Metrics

- `router-response-latency`: histogram of the time it takes to produce the response.
- `http.server.duration`: histogram of the time it takes to produce the response.
Attributes:
- `http.response.status_code`: status code of the produced response
- `url.path`: the matched endpoint path
- `krakend.stage`: always with value `router`
- `router-response-size`: histogram of the size of the body produced for the response.
- `http.server.response.size`: histogram of the size of the body produced for the response.
Attributes:
- `http.response.status_code`: status code of the produced response
- `url.path`: the matched endpoint path
Expand All @@ -151,12 +152,11 @@ At the pipe level we only have 2 options:

##### Metrics

- `stage-duration`: histogram of the time it takes to produce the response.
- `krakend.pipe.duration`: histogram of the time it takes to produce the response.
Attributes:
- `url.path`: the matched endpoint path that **krakend is serving** (is different
than in `backend`, krakend stage, when this property is the path
for the backend we are targetting).
- `krakend.stage`: always with value `pipe`

##### Traces

Expand Down Expand Up @@ -222,13 +222,11 @@ For both, the `metrics` and `traces` part, we can select the same options:

##### Metrics

- `stage-duration`: histogram of the time it takes to produce the response. Controlled
- `krakend.backend.duration`: histogram of the time it takes to produce the response. Controlled
by the `disable_stage` flag (if set to `true` this metric will not appear).
Attributes:
- `url.path`: the matched endpoint path that **krakend is serving** (is different
than in `backend`, krakend stage, when this property is the path
for the backend we are targetting).
- `krakend.stage`: always with value `backend`
- `krakend.endpoint`: this attribute is set to the krakend exposed endpoint that
is the "parent" of the backend request.
- `server.address`: the target host (in case more than one are provided, those
Expand All @@ -245,17 +243,18 @@ The following metrics are enabled if `round_trip` is set to true, and share the
metric, or if we should change that attribute there).
- `krakend.stage`: always with value `backend-request`

- `http.client.duration`: histogram with the time taken since starting a request, until
until having the first byte of the body ready to read.

- `requests-started-count`: number of requests started.
- `requests-failed-count`: number of requests failed.
- `requests-canceled-count`: number of canceled request.
- `requests-timedout-count`: number of timed out requests.
- `requests-content-length`: counter wit the sum of `Content-Length` header for the
- `http.client.request.started.count`: number of requests started.
- `http.client.request.failed.count`: number of requests [failed](failed).
- `http.client.request.canceled.count`: number of canceled request.
- `http.client.request.timedout.count`: number of timed out requests.
- `http.client.request.content-length`: counter wit the sum of `Content-Length` header for the
sent payload for the request.

- `response-latency`: histogram with the time taken until receiving the first byte of the response
- `response-content-length`: histogram with the size of response bodies as reported in the
`Content-Lenght` header.
- `http.client.response.content-length`: histogram with the size of response bodies as reported in the
`Content-Length` header.


###### Read Payload metrics
Expand Down Expand Up @@ -372,7 +371,7 @@ Putting it all together, here we have an example of a configuration:
}
],
"layers": {
"router": {
"global": {
"disable_metrics": false,
"disable_traces": false,
"disable_propagation": false
Expand Down
6 changes: 6 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ image:
conf:
cat ./docker_compose/conf.local/prometheus/prometheus.env_tmpl.yml | envsubst > ./docker_compose/conf.local/prometheus/prometheus.yml

docker_up:
cd ./docker_compose && docker-compose -p krakend_otel_local -f compose.local.yaml up -d

docker_down:
cd ./docker_compose && docker-compose -p krakend_otel_local -f compose.local.yaml down --remove-orphans -v

run: srv
cd ./docker_compose && docker-compose -p krakend_otel_local -f compose.local.yaml up -d
./srv -c ./docker_compose/conf.local/krakend_front/configuration.json > log_frontend.log &
Expand Down
24 changes: 24 additions & 0 deletions example/client/k6client/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: '15m',
};

// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function() {
let address = 'http://192.168.1.12:54444';
http.get(address + '/fake/fsf');
http.get(address + '/combination/1');
http.get(address + '/direct/slow');
http.get(address + '/direct/delayed');
http.get(address + '/direct/drop');
sleep(1);
}
29 changes: 29 additions & 0 deletions example/client/make_requests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# to generate a new base script:
#
# docker run --rm -i -v ${PWD}:/app \
# --user $(id -u):$(id -g) \
# -w /app grafana/k6 \
# new client.js

docker run --rm -i -v ${PWD}:/app \
--user $(id -u):$(id -g) \
-w /app grafana/k6 \
run k6client/client.js

## for i in {1..1}
## # for i in {1..1000}
## do
## # curl localhost:54444/fake/fsf
## # curl localhost:54444/combination/2
## curl localhost:54444/combination/1
## # curl localhost:54444/direct/slow
## sleep 0.1
## # curl localhost:54444/direct/delayed
## # curl localhost:54444/direct/drop
## done
##
## # curl localhost:44444/fake/fsf | jq
## # echo -e "\n"
## # curl localhost:44444/combination/23 | jq
28 changes: 16 additions & 12 deletions example/docker_compose/compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
healthcheck:
test: [CMD, wget, --spicer, -S, http://localhost:3100/ready]
ports:
- "3100:3100"
- "53100:3100"
tempo:
image: grafana/tempo:latest
domainname: tempo
Expand All @@ -17,24 +17,24 @@ services:
- "./conf.local/tempo/tempo.yaml:/etc/tempo.yaml"
- "vol_local_tempo:/tmp/tempo"
ports:
- "14268:14268" # jaeger ingest
- "3200:3200" # tempo
- "9095:9095" # tempo grpc
- "54317:4317" # otlp grpc
- "54318:4318" # otlp http
- "9411:9411" # zipkin
- "53200:3200" # tempo
- "59095:9095" # tempo grpc
- "53317:4317" # otlp grpc
- "53318:4318" # otlp http
# - "14268:14268" # jaeger ingest
# - "9411:9411" # zipkin
prometheus:
image: prom/prometheus:latest
domainname: prometheus
ports:
- "59090:9090"
- "59590:9090"
volumes:
- "./conf.local/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
grafana:
image: grafana/grafana:latest
domainname: grafana
ports:
- "3000:3000"
- "53000:3000"
environment:
GF_SECURITY_ADMIN_USER: krakend
GF_SECURITY_ADMIN_PASSWORD: krakend
Expand All @@ -46,15 +46,19 @@ services:
- loki
- tempo
jaeger:
image: jaegertracing/all-in-one:1.52
image: jaegertracing/all-in-one:1.54
domainname: jaeger
environment:
COLLECTOR_ZIPKIN_HOST_PORT: ":9411"
ports:
- "5778:5778" # serve configs
- "16686:16686" # serve frontend UI
- "55778:5778" # serve configs
- "56686:16686" # serve frontend UI
- "55317:4317" # otlp grpc: we remap this to be able to run other envs
- "55318:4318" # otlp http: we reamp this to be able to run other envs
deploy:
resources:
limits:
memory: 1024M
fakeapi:
image: dhontecillas/reqstatsrv:latest
domainname: fakeapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
"name": "delayer",
"config": {
"delay_millis_distribution": [
{"key": 0, "val": 0.05},
{"key": 10, "val": 0.2},
{"key": 0, "val": 0.0},
{"key": 10, "val": 0.0},
{"key": 50, "val": 0.0},
{"key": 100, "val": 0.5},
{"key": 200, "val": 0.0},
{"key": 700, "val": 0.25}
{"key": 100, "val": 0.25},
{"key": 200, "val": 0.25},
{"key": 700, "val": 0.5}
],
"seed": 1
}
Expand Down
Loading

0 comments on commit ac63bfb

Please sign in to comment.