Skip to content

YQ kqprun added scripts for starting prometheus and connector #14816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ydb/tests/tools/fqrun/flame_graph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fi

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

$SCRIPT_DIR/../kqprun/flame_graph.sh ${1:-'30'} ${2:-''} fqrun
$SCRIPT_DIR/../kqprun/scripts/flame_graph.sh ${1:-'30'} ${2:-''} fqrun
29 changes: 28 additions & 1 deletion ydb/tests/tools/kqprun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,34 @@ For profiling memory allocations build kqprun with ya make flag `-D PROFILE_MEMO

* `flame_graph.sh` - script for collecting flame graphs in svg format, usage:
```(bash)
./flame_graph.sh [graph collection time in seconds] [use sudo]
./scripts/flame_graph.sh [graph collection time in seconds] [use sudo]
```

* `start_prometheus.sh` - start prometheus web UI, can be used for counters visualisation (kqprun should be runned with flag `-M <monitoring port>`), usage:
```(bash)
./scripts/start_prometheus.sh <kqprun monitoring port> <web UI port> [config path]
```
Prometheus UI available on `http://localhost:<web UI port>/targets`

* `start_grafana.sh` - start grafana other existing prometheus, usage:
```(bash)
./scripts/start_grafana.sh <prometheus port> <web UI port> [additional dashboards dirs]
```

Command for starting prometheus and grafana:
```(bash)
./scripts/start_prometheus.sh 32000 32001 && ./scripts/start_grafana.sh 32001 32002
```
Where 32000 - kqprun monitoring port, graphana UI available on http://localhost:32002 (login: `admin`, password: `admin`)

* `start_connector.sh` - start local FQ connector, usage:
```(bash)
./scripts/start_connector.sh <connector port>
```

* `cleanup_docker.sh` - stop created docker containers, usege:
```(bash)
./scripts/cleanup_docker.sh [name filter]
```

## Examples
Expand Down
1 change: 1 addition & 0 deletions ydb/tests/tools/kqprun/configuration/app_config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ FeatureFlags {
EnableExternalSourceSchemaInference: true
EnableTempTables: true
EnableReplaceIfExistsForExternalEntities: true
EnableResourcePoolsCounters: true
}

KQPConfig {
Expand Down
75 changes: 75 additions & 0 deletions ydb/tests/tools/kqprun/configuration/prometheus_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
global:
scrape_interval: 5s
evaluation_interval: 5s

scrape_configs:
- job_name: "ydb_dynamic"
metrics_path: "/counters/counters=ydb/name_label=name/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "ydb_$1"
- job_name: "utils_dynamic"
metrics_path: "/counters/counters=utils/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "utils_$1"
- job_name: "kqp_dynamic"
metrics_path: "/counters/counters=kqp/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "kqp_$1"
- job_name: "tablets_dynamic"
metrics_path: "/counters/counters=tablets/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "tablets_$1"
- job_name: "proxy_dynamic"
metrics_path: "/counters/counters=proxy/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "proxy_$1"
- job_name: "dsproxynode_dynamic"
metrics_path: "/counters/counters=dsproxynode/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "dsproxynode_$1"
- job_name: "ic_dynamic"
metrics_path: "/counters/counters=interconnect/prometheus"
static_configs:
- targets: ["localhost:${TARGET_PORT}"]
labels:
container: ydb-dynamic
metric_relabel_configs:
- source_labels: ["__name__"]
target_label: "__name__"
replacement: "interconnect_$1"
31 changes: 0 additions & 31 deletions ydb/tests/tools/kqprun/flame_graph.sh

This file was deleted.

16 changes: 16 additions & 0 deletions ydb/tests/tools/kqprun/scripts/cleanup_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -eux

if [ $# -gt 1 ]; then
echo "Too many arguments"
exit -1
fi

KQPRUN_CONTAINERS=$(docker container ls -q --filter name=${1:-$USER-kqprun-*})

if [ "$KQPRUN_CONTAINERS" ]; then
docker container stop $KQPRUN_CONTAINERS
else
echo "Nothing to cleanup"
fi
31 changes: 31 additions & 0 deletions ydb/tests/tools/kqprun/scripts/flame_graph.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -eux

if [ $# -gt 3 ]; then
echo "Too many arguments"
exit -1
fi

SUDO=""

if [ ${2:-''} ]; then
SUDO="sudo"
fi

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

function cleanup {
$SUDO rm $SCRIPT_DIR/profdata
rm $SCRIPT_DIR/profdata.txt
}
trap cleanup EXIT

TARGER_PID=$(pgrep -u $USER ${3:-'kqprun'})

$SUDO perf record -F 50 --call-graph dwarf -g --proc-map-timeout=10000 --pid $TARGER_PID -v -o $SCRIPT_DIR/profdata -- sleep ${1:-'30'}
$SUDO perf script -i $SCRIPT_DIR/profdata > $SCRIPT_DIR/profdata.txt

flame_graph_tool="$SCRIPT_DIR/../../../../../contrib/tools/flame-graph/"

${flame_graph_tool}/stackcollapse-perf.pl $SCRIPT_DIR/profdata.txt | ${flame_graph_tool}/flamegraph.pl > ./profdata.svg
21 changes: 21 additions & 0 deletions ydb/tests/tools/kqprun/scripts/start_connector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eux

if [ $# -le 0 ]; then
echo "Please provide connector port (value of Generic::Connector::Endpoint::Port in config)"
exit -1
fi

if [ $# -gt 2 ]; then
echo "Too many arguments"
exit -1
fi

SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
CONTAINER_NAME=$USER-kqprun-fq-connector-go-$1

$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
docker pull ghcr.io/ydb-platform/fq-connector-go:latest
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))
docker container ls --filter name=$CONTAINER_NAME
49 changes: 49 additions & 0 deletions ydb/tests/tools/kqprun/scripts/start_grafana.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -eux

if [ $# -le 0 ]; then
echo "Please provide prometheus port"
exit -1
fi

if [ $# -le 1 ]; then
echo "Please provide grafana web ui port"
exit -1
fi

SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
DASHBOARDS_DIRS="$SCRIPT_DIR/../../../../deploy/helm/ydb-prometheus/dashboards/"
if [ $# -gt 2 ]; then
DASHBOARDS_DIRS="$DASHBOARDS_DIRS $3"
fi

if [ $# -gt 3 ]; then
echo "Too many arguments"
exit -1
fi

CONTAINER_NAME=$USER-kqprun-grafana-$1-$2

$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
docker run -d --rm --name=$CONTAINER_NAME --network host -e "GF_SERVER_HTTP_PORT=$2" grafana/grafana-oss
docker container ls --filter name=$CONTAINER_NAME

echo "Wait grafana is up"

(set -eux; while ! nc -v -z -w 1 localhost $2; do sleep 2; done)

echo "Initialization of datasource and dashboards"

GRAFANA_API="http://admin:admin@localhost:$2/api"

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\" }"
curl -X POST -H "Content-Type: application/json" ${GRAFANA_API}/folders --data-ascii '{ "uid": "ydb", "title": "YDB" }'

for DASHBOARDS_DIR in $DASHBOARDS_DIRS; do
for DASH in "$DASHBOARDS_DIR"/*; do
jq '{ folderUid: "ydb", dashboard: . }' < "$DASH" | curl -X POST -H "Content-Type: application/json" ${GRAFANA_API}/dashboards/db -d @-
done
done

echo "Initialization finished successfully"
33 changes: 33 additions & 0 deletions ydb/tests/tools/kqprun/scripts/start_prometheus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -eux

if [ $# -le 0 ]; then
echo "Please provide monitoring port to listen (value of -M argument)"
exit -1
fi

if [ $# -le 1 ]; then
echo "Please provide prometheus web ui port"
exit -1
fi

if [ $# -gt 3 ]; then
echo "Too many arguments"
exit -1
fi

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

function cleanup {
rm $SCRIPT_DIR/prometheus_config.yaml
}
trap cleanup EXIT

sed "s/\${TARGET_PORT}/$1/g" "${3:-$SCRIPT_DIR/../configuration/prometheus_config.yaml}" > $SCRIPT_DIR/prometheus_config.yaml

CONTAINER_NAME=$USER-kqprun-prometheus-$1-$2

$SCRIPT_DIR/cleanup_docker.sh $CONTAINER_NAME
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
docker container ls --filter name=$CONTAINER_NAME