Skip to content

Commit dd29c37

Browse files
authored
YQ kqprun added scripts for starting prometheus and connector (#14816)
1 parent ad0b833 commit dd29c37

10 files changed

+255
-33
lines changed

ydb/tests/tools/fqrun/flame_graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ fi
99

1010
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1111

12-
$SCRIPT_DIR/../kqprun/flame_graph.sh ${1:-'30'} ${2:-''} fqrun
12+
$SCRIPT_DIR/../kqprun/scripts/flame_graph.sh ${1:-'30'} ${2:-''} fqrun

ydb/tests/tools/kqprun/README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,34 @@ For profiling memory allocations build kqprun with ya make flag `-D PROFILE_MEMO
88

99
* `flame_graph.sh` - script for collecting flame graphs in svg format, usage:
1010
```(bash)
11-
./flame_graph.sh [graph collection time in seconds] [use sudo]
11+
./scripts/flame_graph.sh [graph collection time in seconds] [use sudo]
12+
```
13+
14+
* `start_prometheus.sh` - start prometheus web UI, can be used for counters visualisation (kqprun should be runned with flag `-M <monitoring port>`), usage:
15+
```(bash)
16+
./scripts/start_prometheus.sh <kqprun monitoring port> <web UI port> [config path]
17+
```
18+
Prometheus UI available on `http://localhost:<web UI port>/targets`
19+
20+
* `start_grafana.sh` - start grafana other existing prometheus, usage:
21+
```(bash)
22+
./scripts/start_grafana.sh <prometheus port> <web UI port> [additional dashboards dirs]
23+
```
24+
25+
Command for starting prometheus and grafana:
26+
```(bash)
27+
./scripts/start_prometheus.sh 32000 32001 && ./scripts/start_grafana.sh 32001 32002
28+
```
29+
Where 32000 - kqprun monitoring port, graphana UI available on http://localhost:32002 (login: `admin`, password: `admin`)
30+
31+
* `start_connector.sh` - start local FQ connector, usage:
32+
```(bash)
33+
./scripts/start_connector.sh <connector port>
34+
```
35+
36+
* `cleanup_docker.sh` - stop created docker containers, usege:
37+
```(bash)
38+
./scripts/cleanup_docker.sh [name filter]
1239
```
1340
1441
## Examples

ydb/tests/tools/kqprun/configuration/app_config.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ FeatureFlags {
5555
EnableExternalSourceSchemaInference: true
5656
EnableTempTables: true
5757
EnableReplaceIfExistsForExternalEntities: true
58+
EnableResourcePoolsCounters: true
5859
}
5960

6061
KQPConfig {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
global:
2+
scrape_interval: 5s
3+
evaluation_interval: 5s
4+
5+
scrape_configs:
6+
- job_name: "ydb_dynamic"
7+
metrics_path: "/counters/counters=ydb/name_label=name/prometheus"
8+
static_configs:
9+
- targets: ["localhost:${TARGET_PORT}"]
10+
labels:
11+
container: ydb-dynamic
12+
metric_relabel_configs:
13+
- source_labels: ["__name__"]
14+
target_label: "__name__"
15+
replacement: "ydb_$1"
16+
- job_name: "utils_dynamic"
17+
metrics_path: "/counters/counters=utils/prometheus"
18+
static_configs:
19+
- targets: ["localhost:${TARGET_PORT}"]
20+
labels:
21+
container: ydb-dynamic
22+
metric_relabel_configs:
23+
- source_labels: ["__name__"]
24+
target_label: "__name__"
25+
replacement: "utils_$1"
26+
- job_name: "kqp_dynamic"
27+
metrics_path: "/counters/counters=kqp/prometheus"
28+
static_configs:
29+
- targets: ["localhost:${TARGET_PORT}"]
30+
labels:
31+
container: ydb-dynamic
32+
metric_relabel_configs:
33+
- source_labels: ["__name__"]
34+
target_label: "__name__"
35+
replacement: "kqp_$1"
36+
- job_name: "tablets_dynamic"
37+
metrics_path: "/counters/counters=tablets/prometheus"
38+
static_configs:
39+
- targets: ["localhost:${TARGET_PORT}"]
40+
labels:
41+
container: ydb-dynamic
42+
metric_relabel_configs:
43+
- source_labels: ["__name__"]
44+
target_label: "__name__"
45+
replacement: "tablets_$1"
46+
- job_name: "proxy_dynamic"
47+
metrics_path: "/counters/counters=proxy/prometheus"
48+
static_configs:
49+
- targets: ["localhost:${TARGET_PORT}"]
50+
labels:
51+
container: ydb-dynamic
52+
metric_relabel_configs:
53+
- source_labels: ["__name__"]
54+
target_label: "__name__"
55+
replacement: "proxy_$1"
56+
- job_name: "dsproxynode_dynamic"
57+
metrics_path: "/counters/counters=dsproxynode/prometheus"
58+
static_configs:
59+
- targets: ["localhost:${TARGET_PORT}"]
60+
labels:
61+
container: ydb-dynamic
62+
metric_relabel_configs:
63+
- source_labels: ["__name__"]
64+
target_label: "__name__"
65+
replacement: "dsproxynode_$1"
66+
- job_name: "ic_dynamic"
67+
metrics_path: "/counters/counters=interconnect/prometheus"
68+
static_configs:
69+
- targets: ["localhost:${TARGET_PORT}"]
70+
labels:
71+
container: ydb-dynamic
72+
metric_relabel_configs:
73+
- source_labels: ["__name__"]
74+
target_label: "__name__"
75+
replacement: "interconnect_$1"

ydb/tests/tools/kqprun/flame_graph.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
if [ $# -gt 1 ]; then
6+
echo "Too many arguments"
7+
exit -1
8+
fi
9+
10+
KQPRUN_CONTAINERS=$(docker container ls -q --filter name=${1:-$USER-kqprun-*})
11+
12+
if [ "$KQPRUN_CONTAINERS" ]; then
13+
docker container stop $KQPRUN_CONTAINERS
14+
else
15+
echo "Nothing to cleanup"
16+
fi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
if [ $# -gt 3 ]; then
6+
echo "Too many arguments"
7+
exit -1
8+
fi
9+
10+
SUDO=""
11+
12+
if [ ${2:-''} ]; then
13+
SUDO="sudo"
14+
fi
15+
16+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
17+
18+
function cleanup {
19+
$SUDO rm $SCRIPT_DIR/profdata
20+
rm $SCRIPT_DIR/profdata.txt
21+
}
22+
trap cleanup EXIT
23+
24+
TARGER_PID=$(pgrep -u $USER ${3:-'kqprun'})
25+
26+
$SUDO perf record -F 50 --call-graph dwarf -g --proc-map-timeout=10000 --pid $TARGER_PID -v -o $SCRIPT_DIR/profdata -- sleep ${1:-'30'}
27+
$SUDO perf script -i $SCRIPT_DIR/profdata > $SCRIPT_DIR/profdata.txt
28+
29+
flame_graph_tool="$SCRIPT_DIR/../../../../../contrib/tools/flame-graph/"
30+
31+
${flame_graph_tool}/stackcollapse-perf.pl $SCRIPT_DIR/profdata.txt | ${flame_graph_tool}/flamegraph.pl > ./profdata.svg
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
if [ $# -le 0 ]; then
6+
echo "Please provide connector port (value of Generic::Connector::Endpoint::Port in config)"
7+
exit -1
8+
fi
9+
10+
if [ $# -gt 2 ]; then
11+
echo "Too many arguments"
12+
exit -1
13+
fi
14+
15+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
16+
CONTAINER_NAME=$USER-kqprun-fq-connector-go-$1
17+
18+
$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
19+
docker pull ghcr.io/ydb-platform/fq-connector-go:latest
20+
docker run -d --rm --name=$CONTAINER_NAME --network host ghcr.io/ydb-platform/fq-connector-go:latest --connector-port=$1 --metrics-port=$(($1 + 1)) --pprof-port=$(($1 + 2))
21+
docker container ls --filter name=$CONTAINER_NAME
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
if [ $# -le 0 ]; then
6+
echo "Please provide prometheus port"
7+
exit -1
8+
fi
9+
10+
if [ $# -le 1 ]; then
11+
echo "Please provide grafana web ui port"
12+
exit -1
13+
fi
14+
15+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
16+
DASHBOARDS_DIRS="$SCRIPT_DIR/../../../../deploy/helm/ydb-prometheus/dashboards/"
17+
if [ $# -gt 2 ]; then
18+
DASHBOARDS_DIRS="$DASHBOARDS_DIRS $3"
19+
fi
20+
21+
if [ $# -gt 3 ]; then
22+
echo "Too many arguments"
23+
exit -1
24+
fi
25+
26+
CONTAINER_NAME=$USER-kqprun-grafana-$1-$2
27+
28+
$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
29+
docker run -d --rm --name=$CONTAINER_NAME --network host -e "GF_SERVER_HTTP_PORT=$2" grafana/grafana-oss
30+
docker container ls --filter name=$CONTAINER_NAME
31+
32+
echo "Wait grafana is up"
33+
34+
(set -eux; while ! nc -v -z -w 1 localhost $2; do sleep 2; done)
35+
36+
echo "Initialization of datasource and dashboards"
37+
38+
GRAFANA_API="http://admin:admin@localhost:$2/api"
39+
40+
curl -X POST -H "Content-Type: application/json" ${GRAFANA_API}/datasources --data-ascii "{ \"name\": \"prometheus_datasource_$1\", \"type\": \"prometheus\", \"url\": \"http://localhost:$1\", \"access\": \"proxy\" }"
41+
curl -X POST -H "Content-Type: application/json" ${GRAFANA_API}/folders --data-ascii '{ "uid": "ydb", "title": "YDB" }'
42+
43+
for DASHBOARDS_DIR in $DASHBOARDS_DIRS; do
44+
for DASH in "$DASHBOARDS_DIR"/*; do
45+
jq '{ folderUid: "ydb", dashboard: . }' < "$DASH" | curl -X POST -H "Content-Type: application/json" ${GRAFANA_API}/dashboards/db -d @-
46+
done
47+
done
48+
49+
echo "Initialization finished successfully"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
if [ $# -le 0 ]; then
6+
echo "Please provide monitoring port to listen (value of -M argument)"
7+
exit -1
8+
fi
9+
10+
if [ $# -le 1 ]; then
11+
echo "Please provide prometheus web ui port"
12+
exit -1
13+
fi
14+
15+
if [ $# -gt 3 ]; then
16+
echo "Too many arguments"
17+
exit -1
18+
fi
19+
20+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
21+
22+
function cleanup {
23+
rm $SCRIPT_DIR/prometheus_config.yaml
24+
}
25+
trap cleanup EXIT
26+
27+
sed "s/\${TARGET_PORT}/$1/g" "${3:-$SCRIPT_DIR/../configuration/prometheus_config.yaml}" > $SCRIPT_DIR/prometheus_config.yaml
28+
29+
CONTAINER_NAME=$USER-kqprun-prometheus-$1-$2
30+
31+
$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
32+
docker run -d --rm --name=$CONTAINER_NAME --network host -v $SCRIPT_DIR/prometheus_config.yaml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:$2
33+
docker container ls --filter name=$CONTAINER_NAME

0 commit comments

Comments
 (0)