Skip to content

Commit 6ceb663

Browse files
committed
feat: add support for building the "release" Prometheus from source
Signed-off-by: bwplotka <bwplotka@gmail.com>
1 parent 23302d6 commit 6ceb663

5 files changed

Lines changed: 115 additions & 17 deletions

File tree

prombench/manifests/cluster-infra/7a_commentmonitor_configmap_noparse.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ data:
1818
* See the details [here](https://github.com/prometheus/test-infra/tree/master/prombench/manifests/prombench#benchmarking-from-the-different-directory), defaults to `manifests/prombench`.
1919
* `--bench.version=<branch | @commit>`
2020
* See the details [here](https://github.com/prometheus/test-infra/tree/master/prombench/manifests/prombench#benchmarking-from-the-custom-test-infra-commitbranch), defaults to `master`.
21+
* `--bench.use-registry=<true | anything else>`
22+
* If `true`, benchmark will use the Prometheus from the quay.io/prometheus/prometheus for the "release" version. Any other value will cause benchmark to rebuild the prometheus from the provided (start or restart argument) reference, same as the PR Prometheus. By default it builds from source.
2123
2224
**Examples:**
2325
* `/prombench v3.0.0`
26+
* `/prombench v3.0.0 --bench.use-registry=true`
2427
* `/prombench v3.0.0 --bench.version=@aca1803ccf5d795eee4b0848707eab26d05965cc --bench.directory=manifests/prombench`
2528
2629
verify_user: true
@@ -32,11 +35,12 @@ data:
3235
3336
- name: restart
3437
event_type: prombench_restart
35-
arg_regex: (master|main|v[0-9]+\.[0-9]+\.[0-9]+\S*)
38+
arg_regex: (\S+)
3639
arg_name: RELEASE
3740
flag_args:
3841
bench.directory: BENCHMARK_DIRECTORY
3942
bench.version: BENCHMARK_VERSION
43+
bench.use-registry: BENCHMARK_USE_REGISTRY
4044
comment_template: |
4145
⏱️ Welcome (again) to Prometheus Benchmarking Tool. ⏱️
4246
@@ -65,11 +69,12 @@ data:
6569
6670
- name: "" # start is a default (empty command).
6771
event_type: prombench_start
68-
arg_regex: (master|main|v[0-9]+\.[0-9]+\.[0-9]+\S*)
72+
arg_regex: (\S+)
6973
arg_name: RELEASE
7074
flag_args:
7175
bench.directory: BENCHMARK_DIRECTORY
7276
bench.version: BENCHMARK_VERSION
77+
bench.use-registry: BENCHMARK_USE_REGISTRY
7378
label: prombench
7479
comment_template: |
7580
⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️

prombench/manifests/prombench/benchmark/3_prometheus-test-pr_deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ spec:
766766
image: docker.io/prominfra/prometheus-builder:master
767767
imagePullPolicy: Always
768768
env:
769-
- name: PR_NUMBER
769+
- name: REFERENCE
770770
value: "{{ .PR_NUMBER }}"
771771
- name: VOLUME_DIR
772772
value: "/prometheus-builder" # same as mountPath

prombench/manifests/prombench/benchmark/3_prometheus-test-release_deployment.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,39 @@ spec:
761761
- prometheus
762762
securityContext:
763763
runAsUser: 0
764+
initContainers:
765+
- name: prometheus-builder
766+
image: docker.io/prominfra/prometheus-builder:master
767+
imagePullPolicy: Always
768+
env:
769+
- name: REFERENCE
770+
value: "{{ .RELEASE }}"
771+
- name: USE_REGISTRY
772+
value: "{{ .BENCHMARK_USE_REGISTRY }}"
773+
- name: VOLUME_DIR
774+
value: "/prometheus-builder" # same as mountPath
775+
- name: GITHUB_ORG
776+
value: "{{ .GITHUB_ORG }}"
777+
- name: GITHUB_REPO
778+
value: "{{ .GITHUB_REPO }}"
779+
volumeMounts:
780+
- name: prometheus-executable
781+
mountPath: /prometheus-builder
764782
containers:
765783
- name: prometheus
766-
image: quay.io/prometheus/prometheus:{{ .RELEASE }}
784+
image: quay.io/prometheus/busybox:latest
767785
imagePullPolicy: Always
768-
command: [ "/bin/prometheus" ]
786+
# The prometheus-builder takes a while to build
787+
# so make sure to start it before the release deployment.
788+
# Mark it ready only when prometheus is started.
789+
# This way we have the least time difference in the scraped metrics.
790+
readinessProbe:
791+
tcpSocket:
792+
port: 9090
793+
initialDelaySeconds: 30
794+
periodSeconds: 2
795+
failureThreshold: 30
796+
command: ["/usr/bin/prometheus"]
769797
args: [
770798
"--web.external-url=http://{{ .DOMAIN_NAME }}/{{ .PR_NUMBER }}/prometheus-release",
771799
"--storage.tsdb.path=/prometheus",
@@ -781,6 +809,8 @@ spec:
781809
mountPath: /etc/prometheus
782810
- name: instance-ssd
783811
mountPath: /prometheus
812+
- name: prometheus-executable
813+
mountPath: /usr/bin
784814
ports:
785815
- name: prom-web
786816
containerPort: 9090
@@ -792,6 +822,8 @@ spec:
792822
hostPath:
793823
# /mnt is where GKE keeps it's SSD.
794824
path: /mnt/disks/ssd0
825+
- name: prometheus-executable
826+
emptyDir: {}
795827
terminationGracePeriodSeconds: 300
796828
nodeSelector:
797829
node-name: prometheus-{{ .PR_NUMBER }}

tools/comment-monitor/internal/command_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ func TestParseCommand_ProdCommentMonitorConfig(t *testing.T) {
265265
// Not matching cases.
266266
{comment: ""},
267267
{comment: "How to start prombench? I think it was something like:\n\n /prombench main\n\nYolo"},
268+
// Extended reference building from source cases
269+
{
270+
comment: "/prombench d40aff95265ae8af512d58dd7b76c77abfb9611f\nSome text after",
271+
expect: testCommand(eventTypeStart, map[string]string{"RELEASE": "d40aff95265ae8af512d58dd7b76c77abfb9611f"}),
272+
},
273+
{
274+
comment: "/prombench some-branch/yolo --bench.use-registry=true\nSome text after",
275+
expect: testCommand(eventTypeStart, map[string]string{"RELEASE": "some-branch/yolo", "BENCHMARK_USE_REGISTRY": "true"}),
276+
},
277+
{
278+
comment: "/prombench restart some-branch/yolo --bench.directory=manifests/prombench --bench.use-registry=true\nSome text after",
279+
expect: testCommand(eventTypeRestart, map[string]string{"RELEASE": "some-branch/yolo", "BENCHMARK_DIRECTORY": "manifests/prombench", "BENCHMARK_USE_REGISTRY": "true"}),
280+
},
268281
})
269282
}
270283

tools/prometheus-builder/build.sh

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,82 @@
11
#!/bin/bash
22

3+
# This script created a Prometheus binary to use in benchmarks and place it in $VOLUME/prometheus.
4+
# It uses $REFERENCE variable to build or fetch the binary.
5+
# If $USE_REGISTRY is set to "true" it uses the binary from the quay.io/prometheus/prometheus:${REFERENCE},
6+
# otherwise it builds it from source, from the given reference (PR number, branch or git SHA).
7+
8+
# Default values
39
DIR="/go/src/github.com/prometheus/prometheus"
410

5-
if [[ -z $PR_NUMBER || -z $VOLUME_DIR || -z $GITHUB_ORG || -z $GITHUB_REPO ]]; then
6-
echo "ERROR:: environment variables not set correctly"
11+
REFERENCE=${REFERENCE}
12+
13+
# We want builder to work with the old scenarios, so support PR_NUMBER var for compatibility.
14+
if [[ -z ${REFERENCE} ]]; then
15+
REFERENCE=${PR_NUMBER}
16+
fi
17+
18+
if [[ -z ${REFERENCE} || -z ${VOLUME_DIR} || -z ${GITHUB_ORG} || -z ${GITHUB_REPO} ]]; then
19+
echo "ERROR:: environment variables not set correctly, requires REFERENCE (or PR_NUMBER), VOLUME_DIR, GITHUB_ORG, GITHUB_REPO"
720
exit 1;
821
fi
922

23+
# Fetch from quay if requested.
24+
if [[ "${USE_REGISTRY}" == "true" ]]; then
25+
echo ">> USE_PRE_BUILD is enabled."
26+
echo ">> Attempting to download binary from quay.io/prometheus/prometheus:${REFERENCE}"
27+
28+
IMAGE="quay.io/prometheus/prometheus:${REFERENCE}"
29+
30+
if ! CONTAINER_ID=$(docker create "${IMAGE}"); then
31+
echo "ERROR:: Could not pull or create container from ${IMAGE}"
32+
exit 1
33+
fi
34+
35+
echo ">> Extracting prometheus binary from ${CONTAINER_ID} container..."
36+
if ! docker cp "${CONTAINER_ID}:/bin/prometheus" "${VOLUME_DIR}/prometheus"; then
37+
echo "ERROR:: Failed to copy binary from container"
38+
docker rm -v "${CONTAINER_ID}" >/dev/null
39+
exit 1
40+
fi
41+
docker rm -v "${CONTAINER_ID}" >/dev/null
42+
echo ">> Binary successfully downloaded and copied."
43+
exit 0
44+
fi
45+
1046
# Clone the repository with a shallow clone
1147
echo ">> Cloning repository $GITHUB_ORG/$GITHUB_REPO (shallow clone)"
12-
if ! git clone --depth 1 https://github.com/$GITHUB_ORG/$GITHUB_REPO.git $DIR; then
48+
if ! git clone --depth 1 "https://github.com/$GITHUB_ORG/$GITHUB_REPO.git" "$DIR"; then
1349
echo "ERROR:: Cloning of repo $GITHUB_ORG/$GITHUB_REPO failed"
1450
exit 1;
1551
fi
1652

17-
cd $DIR || exit 1
53+
cd "$DIR" || exit 1
1854

19-
echo ">> Fetching Pull Request $GITHUB_ORG/$GITHUB_REPO/pull/$PR_NUMBER"
20-
if ! git fetch origin pull/$PR_NUMBER/head:pr-branch; then
21-
echo "ERROR:: Fetching of PR $PR_NUMBER failed"
22-
exit 1;
23-
fi
55+
echo ">> Resolving git state for building from source from ${REFERENCE}..."
56+
57+
# Attempt 1: Try pulling PR first which will only work if REFERENCE is a PR number.
58+
if git fetch origin "pull/${REFERENCE}/head:pr-branch" 2>/dev/null; then
59+
echo ">> Successfully fetched PR reference: pull/${REFERENCE}/head"
60+
git checkout pr-branch
61+
else
62+
# Attempt 2: If PR fetch fails, try assuming it's a branch or Git SHA
63+
echo ">> Reference 'pull/${REFERENCE}/head' not found; assuming reference is not a PR number. Trying to fetch '${REFERENCE}' as a remote branch or SHA..."
2464

25-
git checkout pr-branch
65+
# We fetch specifically the ref to FETCH_HEAD to avoid naming conflicts
66+
if git fetch origin "${REFERENCE}"; then
67+
echo ">> Successfully fetched reference: ${REFERENCE}"
68+
git checkout FETCH_HEAD
69+
else
70+
echo "ERROR:: Could not resolve '${REFERENCE}' as a Pull Request, remote branch, or Git SHA."
71+
exit 1
72+
fi
73+
fi
2674

27-
echo ">> Creating prometheus binaries"
75+
echo ">> Creating prometheus binary using promu"
2876
if ! make build PROMU_BINARIES="prometheus"; then
2977
echo "ERROR:: Building of binaries failed"
3078
exit 1;
3179
fi
3280

3381
echo ">> Copy files to volume"
34-
cp prometheus $VOLUME_DIR/prometheus
82+
cp prometheus "$VOLUME_DIR/prometheus"

0 commit comments

Comments
 (0)