+54
-5
lines changedFilter options
+54
-5
lines changed Original file line number Diff line number Diff line change
@@ -16,8 +16,10 @@ services:
16
16
image: prom/prometheus
17
17
ports:
18
18
- "9090:9090"
19
-
command:
20
-
- --config.file=/etc/prometheus/prometheus.yml
19
+
entrypoint: /etc/prometheus/entrypoint.sh
20
+
volumes:
21
+
- ./testdata/prometheus-seed.yml:/etc/prometheus/prometheus-seed.yml
22
+
- ./testdata/prometheus-entrypoint.sh:/etc/prometheus/entrypoint.sh
21
23
22
24
loki:
23
25
image: grafana/loki:2.6.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
1
+
#!/bin/sh
2
+
# Prometheus entrypoint script to backfill recording rules and start Prometheus
3
+
4
+
set -e
5
+
6
+
echo "Starting Prometheus entrypoint script..."
7
+
8
+
9
+
backfill() {
10
+
# Calculate time range for backfilling (5 hours ago from now)
11
+
# Get current time in seconds since epoch
12
+
CURRENT_TIME=$(date -u +%s)
13
+
# Subtract 5 hours (5 * 60 * 60 = 18000 seconds)
14
+
START_TIME=$((CURRENT_TIME - 18000))
15
+
16
+
# wait until Prometheus is up and running
17
+
until wget http://localhost:9090/-/healthy -q -O /dev/null; do
18
+
sleep 1
19
+
done
20
+
21
+
promtool tsdb create-blocks-from \
22
+
rules \
23
+
--url=http://localhost:9090 \
24
+
--start="${START_TIME}" \
25
+
--end="${CURRENT_TIME}" \
26
+
--eval-interval=30s \
27
+
/etc/prometheus/prometheus-seed.yml
28
+
}
29
+
30
+
# Start Prometheus with the regular configuration, this is needed for backfilling
31
+
/bin/prometheus \
32
+
--config.file=/etc/prometheus/prometheus.yml &
33
+
34
+
backfill
35
+
36
+
# Restarting Prometheus after backfilling will allow to load the new blocks directly
37
+
# without having to wait for the next compaction cycle
38
+
kill %1
39
+
echo "Starting Prometheus server..."
40
+
# Start Prometheus with the regular configuration
41
+
/bin/prometheus \
42
+
--config.file=/etc/prometheus/prometheus.yml
43
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1
+
groups:
2
+
- name: seed
3
+
rules:
4
+
- record: test
5
+
expr: vector(1)
Original file line number Diff line number Diff line change
@@ -233,15 +233,14 @@ func TestSelectorMatches(t *testing.T) {
233
233
234
234
func TestPrometheusQueries(t *testing.T) {
235
235
t.Run("query prometheus range", func(t *testing.T) {
236
-
t.Skip("Skipping because we don't have a Prometheus instance with enough data")
237
236
end := time.Now()
238
237
start := end.Add(-10 * time.Minute)
239
238
for _, step := range []int{15, 60, 300} {
240
239
t.Run(fmt.Sprintf("step=%d", step), func(t *testing.T) {
241
240
ctx := newTestContext()
242
241
result, err := queryPrometheus(ctx, QueryPrometheusParams{
243
242
DatasourceUID: "prometheus",
244
-
Expr: "up",
243
+
Expr: "test",
245
244
StartRFC3339: start.Format(time.RFC3339),
246
245
EndRFC3339: end.Format(time.RFC3339),
247
246
StepSeconds: step,
@@ -253,7 +252,7 @@ func TestPrometheusQueries(t *testing.T) {
253
252
expectedLen := int(end.Sub(start).Seconds()/float64(step)) + 1
254
253
assert.Len(t, matrix[0].Values, expectedLen)
255
254
assert.Less(t, matrix[0].Values[0].Timestamp.Sub(model.TimeFromUnix(start.Unix())), time.Duration(step)*time.Second)
256
-
assert.Equal(t, matrix[0].Metric["__name__"], model.LabelValue("up"))
255
+
assert.Equal(t, matrix[0].Metric["__name__"], model.LabelValue("test"))
257
256
})
258
257
}
259
258
})
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4