Skip to content

Commit 6f66ffd

Browse files
committed
promtorture 0.3: kinda useful
1 parent 50355c5 commit 6f66ffd

File tree

8 files changed

+102
-12
lines changed

8 files changed

+102
-12
lines changed

testcases/promtorture/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
promtorture
22
promtool
33
.cache
4+
notes.md

testcases/promtorture/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# promtorture
2+
3+
Make prometheus feel really bad. For science.
4+
5+
## quickstart
6+
7+
```
8+
./scripts/kind-create.sh
9+
./scripts/kind-deploy.sh
10+
11+
sleep 10
12+
13+
./scripts/resources
14+
./scripts/promapi -m tsdb | yq .data.headStats
15+
./scripts/promapi -m tsdb -l 100
16+
17+
```
18+
19+
## promtorture
20+
21+
for args:
22+
23+
```
24+
go build
25+
./promtorture --help
26+
```
27+
28+
## scripts
29+
30+
- [`kind-create.sh`](./scripts/kind-create.sh): Create a kind cluster and deply kube-prometheus
31+
- [`kind-deploy.sh`](./scripts/kind-deploy.sh): Deploy promtorture, takes CLI options for target and label counts
32+
- [`promapi`](./scripts/promapi): A simple prometheus API client, see
33+
`./scripts/promapi -h`. Can get TSDB info, make snapshots, etc.
34+
- [`promcmd`](./scripts/promcmd): wrapper for running shell commands on the prometheus pod. Useful for running
35+
`promtool` etc. The script source contains some notes on handy commands.
36+
- [`promlogs`](./scripts/promlogs): tail logs from the prometheus pod
37+
- [`promnuke`](./scripts/promnuke): delete all prometheus data
38+
- [`promtorture-args`](./scripts/promtorture-args): report the container args for the running promtorture instance
39+
- [`resources`](./scripts/resources): dump the resources for the prometheus pod
40+
- [`socks5`](./scripts/socks5): start a socks5 proxy to the prometheus pod. You can use this with
41+
the `http_proxy=socks5://localhost:1081` env-var to proxy requests to the kube cluster, so you can
42+
use in-cluster URIs like `http://prometheus-k8s.monitoring.svc.cluster.local:9090` from commands
43+
like `curl` and `promtool`. See also the `curl` option `--socks5-hostname`.
44+
- [`get-promtool`](./scripts/get-promtool): download the `promtool` binary from a prometheus release,
45+
for if you want to run `promtool` over SOCKS5 or port-forward rather than in the prom container, e.g
46+
for `promtool debug` dump generation.

testcases/promtorture/scripts/get-promtool

100644100755
File mode changed.

testcases/promtorture/scripts/kind-create.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ yq '.|select(.kind == "CustomResourceDefinition")' .cache/kube-prometheus.yaml |
1919

2020
"${kubectl[@]}" wait --for=condition=established --timeout=60s crd --all
2121

22-
# this'll re-apply the CRDs but that's harmless
23-
#
24-
# ServiceMonitors are omitted deliberately because for this test we only want to see
25-
# metrics for explicitly named targets.
26-
#
2722
yq '
2823
.
2924
|select(
3025
(.kind != "CustomResourceDefinition")
31-
and (.kind != "ServiceMonitor")
3226
and (.kind != "AlertManager")
33-
and (.kind != "PodMonitor")
34-
)' | "${kubectl[@]}" apply --server-side -f -
27+
)' | "${kubectl[@]}" apply --server-side -f -
3528
"${kubectl[@]}" apply --server-side -f .cache/kube-prometheus.yaml
3629

3730
# Scale down to 1 replica and don't deploy alertmanager

testcases/promtorture/scripts/promapi

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ set -e -u -o pipefail
88

99
function usage() {
1010
echo "Usage: meta -k target|targetmeta|tsdb|walreplay|config|flags|runtime|snapshot"
11+
echo
12+
echo "For tsdb:"
13+
echo " -l nnnn : number of entries in the top-n lists to return"
1114
exit 1
1215
}
1316

1417
# what to fetch
1518
meta=
16-
while getopts "m:h" opt; do
19+
limit=
20+
while getopts "hm:l:" opt; do
1721
case ${opt} in
1822
m)
1923
meta=$OPTARG
2024
;;
25+
l)
26+
limit=$OPTARG
27+
;;
2128
\?|h|: )
2229
usage
2330
;;
@@ -43,7 +50,11 @@ case "${meta}" in
4350
apiQuery "/api/v1/targets/metadata" -G --data 'match_target={job="monitoring/promtorture"}'
4451
;;
4552
tsdb)
46-
apiQuery "/api/v1/status/tsdb" -G
53+
if [ -n "${limit}" ]; then
54+
apiQuery "/api/v1/status/tsdb" -G --data "limit=${limit}"
55+
else
56+
apiQuery "/api/v1/status/tsdb" -G
57+
fi
4758
;;
4859
walreplay)
4960
apiQuery "/api/v1/status/walreplay" -G

testcases/promtorture/scripts/promcmd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ prom_pod="$("${kubectl[@]}" get pod -n monitoring -l app.kubernetes.io/instance=
1212
#
1313
# handy commands include
1414
#
15+
# promtool query instant http://localhost:9090 'up{job="monitoring/promtorture"}'
16+
#
1517
# promtool check service-discovery /etc/prometheus/config_out/prometheus.env.yaml podMonitor/monitoring/promtorture/0 --timeout=5s
18+
#
1619
# promtool query labels http://localhost:9090 'container'
20+
#
1721
# promtool push metrics ...
18-
# promtool debug --server http://localhost:9090 'tsdb' 'head' 'select * from container_cpu_usage_seconds_total limit 1'
1922
#
2023
# Alternately you can run it locally, using scripts/get-promtool, run scripts/socks5 for proxy then
2124
# run with http_proxy env-var and kube uri for prometheus e.g.:
@@ -34,6 +37,12 @@ prom_pod="$("${kubectl[@]}" get pod -n monitoring -l app.kubernetes.io/instance=
3437
# # that'll print the snaphot name, so
3538
# ./scripts/promcmd du -ms /prometheus/snapshots/${snap_name}
3639
#
40+
# and the snapshot can be dumped with
41+
#
42+
# ./scripts/promcmd /prometheus/replay mkdir /prometheus/snapshots/${snap_name}/wal
43+
# ./scripts/promcmd promtool tsdb dump --sandbox-dir-root=/prometheus/replay /prometheus/snapshots/${snap_name}
44+
45+
#
3746

3847

3948
exec "${kubectl[@]}" exec -it -n monitoring "${prom_pod}" -- "$@"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
#
3+
# Print the args promtorture is running with
4+
#
5+
6+
set -e -u -o pipefail
7+
source scripts/config
8+
9+
"${kubectl[@]}" get -n default deployment/promtorture -o yaml | yq '.spec.template.spec.containers[]|select(.name=="promtorture").args'
10+
11+
# vim: et ts=2 sw=2 sts=2 ft=bash ai

testcases/promtorture/scripts/resources

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,23 @@
55
set -e -u -o pipefail
66
source scripts/config
77

8-
"${kubectl_bin}" resource-capacity "${kubectl_context[@]}" -n monitoring --pods --pod-labels app.kubernetes.io/instance=k8s,app.kubernetes.io/name=prometheus
8+
"${kubectl[@]}" top -n monitoring pod prometheus-k8s-0
9+
echo
10+
11+
if type -p kubectl-resource_capacity &>/dev/null; then
12+
"${kubectl_bin}" resource-capacity "${kubectl_context[@]}" -n monitoring \
13+
--pods --pods --containers --util \
14+
--pod-labels app.kubernetes.io/instance=k8s,app.kubernetes.io/name=prometheus \
15+
| awk 'NR==1 { print } $3=="prometheus" { print }'
16+
echo
17+
else
18+
echo 1>&2 "no kubectl resource-capacity; use kubectl krew install resource-capacity"
19+
echo 1>&2 "skipping"
20+
echo 1>&2
21+
fi
22+
23+
./scripts/promcmd top -b -n 1 -d 0
24+
25+
./scripts/promcmd cat /proc/1/status | awk '/^Name|^Vm|^Rss/ {print}'
26+
27+
# vim: et ts=2 sw=2 sts=2 ft=bash ai

0 commit comments

Comments
 (0)