Skip to content

Commit 8d2075b

Browse files
committed
promtorture: embed old version
1 parent fbed217 commit 8d2075b

File tree

9 files changed

+260
-0
lines changed

9 files changed

+260
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
promkill
2+
config/k8s
3+
README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
promkill
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Usage:
4+
# docker buildx build -t promkill:latest .
5+
# docker run --rm --publish 127.0.0.1:8080:8080 --name promkill promkill:latest
6+
# curl localhost:8080/metrics
7+
#
8+
# or
9+
# kind load docker-image promkill:latest
10+
# kubectl apply --context kind-kind -f config/k8s/deployment.yaml
11+
12+
13+
FROM golang:1.21-alpine AS build
14+
WORKDIR /app
15+
COPY go.mod go.sum ./
16+
RUN go mod download
17+
COPY *.go ./
18+
RUN CGO_ENABLED=0 GOOS=linux go build -o /usr/local/bin/promkill
19+
20+
FROM scratch
21+
COPY --from=build /usr/local/bin/promkill /usr/local/bin/promkill
22+
EXPOSE 8080
23+
CMD ["/usr/local/bin/promkill"]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Prometheus cardinality torture-testing
2+
3+
(This is an earlier version of promtorture, retained here for reference)
4+
5+
6+
Should use https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/getting-started.md instead for
7+
setup
8+
9+
```bash
10+
kind create cluster
11+
12+
# should be releasever instead
13+
kustomize build https://github.com/prometheus-operator/kube-prometheus > prom.yaml
14+
kfilt --kind=CustomResourceDefinition < prom.yaml | kubectl create --context kind-kind -f -
15+
kfilt --exclude-kind=CustomResourceDefinition < prom.yaml | kubectl create --context kind-kind -f -
16+
rm prom.yaml
17+
18+
# should be a kustomization
19+
cat > resources-patch.json <<'__END__'
20+
[
21+
{
22+
"op": "add",
23+
"path": "/spec/resources",
24+
"value": {
25+
"requests": {
26+
"memory": "1Gi",
27+
"cpu": "4"
28+
},
29+
"limits": {
30+
"memory": "1Gi",
31+
"cpu": "15"
32+
}
33+
}
34+
},
35+
{
36+
"op": "replace",
37+
"path": "/spec/scrapeInterval",
38+
"value": "1s"
39+
},
40+
{
41+
"op": "replace",
42+
"path": "/spec/replicas",
43+
"value": 1
44+
}
45+
]
46+
__END__
47+
48+
kubectl patch -n monitoring prometheus/k8s --type json --patch-file resources-patch.json
49+
50+
docker buildx build -t promkill:latest .
51+
kind load docker-image promkill:latest
52+
kubectl apply --context kind-kind -f config/k8s/deployment.yaml
53+
kubectl apply --context kind-kind -f config/k8s/podmonitor.yaml
54+
```
55+
56+
check exported metrics
57+
58+
```bash
59+
kubectl port-forward $(kubectl get pod -n default -l app=promkill -o name | head -1) 8080:8080
60+
curl -sSLf localhost:8080/metrics
61+
curl -sSLf http://localhost:8080/metrics | wc -l
62+
```
63+
64+
check prom
65+
66+
```bash
67+
kubectl -n monitoring get pods -l app.kubernetes.io/name=prometheus
68+
```
69+
70+
forward prom api
71+
72+
```bash
73+
kubectl -n monitoring port-forward services/prometheus-k8s 8081:8080 9091:9090
74+
```
75+
76+
then visit http://localhost:9091/ for webui or API, e.g. enumerate labels
77+
78+
Make sure it's being scraped
79+
80+
```bash
81+
curl -X GET -sSLf http://localhost:9091/api/v1/targets
82+
```
83+
84+
check metrics dims
85+
86+
```bash
87+
curl -X GET -sSLf http://localhost:9091/api/v1/labels
88+
```
89+
90+
watch mem
91+
92+
```
93+
kube-capacity --pod-labels app.kubernetes.io/name=prometheus -u -c
94+
```
95+
96+
97+
### hacking prom
98+
99+
```
100+
kubectl get -n monitoring prometheus/k8s -oyaml
101+
```
102+
103+
also useful: `GET /api/v1/metadata`, `GET /api/v1/status/runtimeinfo`, `GET /api/v1/status/tsdb`
104+
105+
* `curl -X GET -sSLf http://localhost:9091/api/v1/status/tsdb | jq '.'`
106+
* `curl -X GET -sSLf http://localhost:9091/api/v1/status/runtimeinfo | jq '.'`
107+
* `curl -X GET -sSLf http://localhost:9091/api/v1/status/config | jq -r '.data.yaml'`
108+
* `curl -X GET -sSLf http://localhost:9091/api/v1/status/flags`
109+
* `curl -X GET -sSLf http://localhost:9091/api/v1/metadata| jq '.'`
110+
* `curl -X GET -sSLf http://localhost:9091/flags | jq -r '.data.yaml'`
111+
112+
Watch prom's own metrics
113+
114+
## Poke at prom
115+
116+
```bash
117+
kubectl get -n monitoring prometheus/k8s -oyaml > promcfg.yaml
118+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: promkill
5+
namespace: default
6+
labels:
7+
app: promkill
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app: promkill
13+
template:
14+
metadata:
15+
labels:
16+
app: promkill
17+
spec:
18+
containers:
19+
- name: promkill
20+
image: promkill:latest
21+
ports:
22+
- name: metrics
23+
containerPort: 8080
24+
imagePullPolicy: Never
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: PodMonitor
3+
metadata:
4+
name: promkill
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: promkill
9+
podMetricsEndpoints:
10+
- port: metrics

testcases/promtorture/promkill/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module promkill
2+
3+
go 1.20
4+
5+
require (
6+
github.com/VictoriaMetrics/metrics v1.24.0
7+
github.com/google/uuid v1.3.1
8+
)
9+
10+
require (
11+
github.com/valyala/fastrand v1.1.0 // indirect
12+
github.com/valyala/histogram v1.2.0 // indirect
13+
golang.org/x/sys v0.7.0 // indirect
14+
)

testcases/promtorture/promkill/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/VictoriaMetrics/metrics v1.24.0 h1:ILavebReOjYctAGY5QU2F9X0MYvkcrG3aEn2RKa1Zkw=
2+
github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys=
3+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
4+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5+
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
6+
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
7+
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
8+
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
9+
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
10+
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* hacked up version of the victoria metrics prom exporter demo, for generating
3+
* massive cardinality and throwing it at prom.
4+
*/
5+
package main
6+
7+
import (
8+
"fmt"
9+
"strings"
10+
"time"
11+
"net/http"
12+
"log"
13+
"math/rand"
14+
"github.com/google/uuid"
15+
"github.com/VictoriaMetrics/metrics"
16+
)
17+
18+
func addMetric(basename string, ndims int) {
19+
var labels []string = []string{
20+
"fixed1=\"constant\"",
21+
"fixed2=\"very very very very very very very very very long long long long long long value value value value\"",
22+
}
23+
for i := 0; i < ndims; i++ {
24+
dim := fmt.Sprintf("dim%d=\"%s\"", i, uuid.New().String())
25+
labels = append(labels, dim)
26+
}
27+
metric_name := fmt.Sprintf("%s{%s}", basename, strings.Join(labels,","))
28+
// Discard the metric, we're just making noise here. The metric value will be 0.
29+
// TODO: remember them a while then age them out?
30+
metric_func := func() float64 { return rand.Float64() }
31+
_ = metrics.NewGauge(metric_name, metric_func)
32+
}
33+
34+
func metricsGenerator() {
35+
for {
36+
addMetric("basic", 1)
37+
addMetric("wide", 10)
38+
addMetric("extreme", 40)
39+
40+
time.Sleep(1 * time.Second)
41+
}
42+
}
43+
44+
func main() {
45+
// front-load a massive pile of metrics
46+
for i := 0; i < 400000; i++ {
47+
metric_name := fmt.Sprintf("fixed%d", i)
48+
metric_func := func() float64 { return rand.Float64() }
49+
_ = metrics.NewGauge(metric_name, metric_func)
50+
}
51+
// and add more with wide dims regularly
52+
go metricsGenerator();
53+
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
54+
metrics.WritePrometheus(w, false)
55+
})
56+
log.Fatal(http.ListenAndServe(":8080", nil))
57+
}

0 commit comments

Comments
 (0)