Skip to content

Commit 64630db

Browse files
zeitlingerjaydelucatrask
authored
fix prom example and add test (open-telemetry#909)
Co-authored-by: Jay DeLuca <jaydeluca4@gmail.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 0fc127c commit 64630db

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

.github/scripts/prometheus-test.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
cd prometheus
6+
../gradlew shadowJar
7+
docker compose up -d
8+
9+
function ready() {
10+
# check that 200 is returned from the metrics endpoint
11+
curl -f localhost:19090/metrics > /dev/null 2>&1 || (echo "Metrics endpoint did not return 200" && exit 1)
12+
# check that 200 is returned from the Prometheus server
13+
curl -f http://localhost:9090 > /dev/null 2>&1 || (echo "Prometheus did not return 200" && exit 1)
14+
}
15+
16+
# wait up to 2 minutes for the endpoints to be ready
17+
timeout=120
18+
interval=5
19+
elapsed=0
20+
while ! ready; do
21+
if [ $elapsed -ge $timeout ]; then
22+
echo "Timeout waiting for Prometheus endpoints to be ready"
23+
docker compose logs
24+
docker compose down
25+
exit 1
26+
fi
27+
echo "Waiting for Prometheus endpoints to be ready..."
28+
sleep $interval
29+
elapsed=$((elapsed + interval))
30+
done
31+
32+
echo "Prometheus example build and endpoints are working correctly"
33+
34+
docker compose down
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Prometheus Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- .github/workflows/prometheus-test.yml
9+
- .github/scripts/prometheus-test.sh
10+
- 'prometheus/**'
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
acceptance-tests:
18+
runs-on: ubuntu-24.04
19+
steps:
20+
- name: Check out
21+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
22+
23+
- name: Set up JDK for running Gradle
24+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
25+
with:
26+
distribution: temurin
27+
java-version: 17
28+
29+
- name: Set up gradle
30+
uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0
31+
with:
32+
cache-read-only: ${{ github.event_name == 'pull_request' }}
33+
34+
- name: Run Prometheus test
35+
run: .github/scripts/prometheus-test.sh

prometheus/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM eclipse-temurin:11.0.29_7-jre@sha256:5a9b558567e6a2f7fbaa5000891caf515c31db
22

33
ADD build/libs/opentelemetry-examples-prometheus-*-SNAPSHOT-all.jar /app.jar
44

5-
ENTRYPOINT java -cp app.jar io.opentelemetry.example.prometheus.PrometheusExample 19090
5+
ENTRYPOINT exec java -cp app.jar io.opentelemetry.example.prometheus.PrometheusExample 19090

prometheus/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ docker compose up
3232

3333
## 3 - View Metrics
3434

35-
To view metrics in Prometheus, navigate to:
35+
To view metrics in Prometheus (e.g. 90th percentile), navigate to:
3636

37-
http://localhost:9090/graph?g0.range_input=15m&g0.expr=incoming_messages&g0.tab=0
37+
http://localhost:9090/query?g0.expr=histogram_quantile%28.90%2C+sum+by%28le%29+%28rate%28super_timer_milliseconds_bucket%5B5m%5D%29%29%29&g0.show_tree=0&g0.tab=graph&g0.range_input=15m&g0.res_type=auto&g0.res_density=medium&g0.display_mode=lines&g0.show_exemplars=0
3838

3939
To fetch application metrics in prometheus format, run:
40-
40+
41+
```shell
4142
curl localhost:19090/metrics
43+
```
4244

4345
To fetch application metrics in OpenMetrics format, which includes exemplars, run:
4446

47+
```shell
4548
curl -H 'Accept: application/openmetrics-text; version=1.0.0; charset=utf-8' localhost:19090/metrics
49+
```

prometheus/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3'
21
services:
32
app:
43
build: ./

prometheus/prometheus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ alerting:
88
- targets: []
99
scheme: http
1010
timeout: 10s
11-
api_version: v1
11+
api_version: v2
1212
scrape_configs:
1313
- job_name: prometheus
1414
honor_timestamps: true

0 commit comments

Comments
 (0)