Skip to content

Commit 8b50728

Browse files
Integration tests (#56)
* Integration tests Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Test Remote read too Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Workflow does not contain permissions' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * test loadgen Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Delete alertmanager config Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * More rules group Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Test rules lint Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Document integration tests Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> * Removing duplicated tests Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> --------- Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent e9f20a9 commit 8b50728

5 files changed

Lines changed: 592 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Integration Tests
2+
on:
3+
pull_request:
4+
paths-ignore:
5+
- "docs/**"
6+
- "*.md"
7+
permissions:
8+
contents: read
9+
jobs:
10+
integration:
11+
name: Integration Tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: 1.22
18+
- name: Start Cortex
19+
run: |
20+
docker run -d --name cortex \
21+
-p 9009:9009 \
22+
-v ${{ github.workspace }}/integration/cortex-config.yaml:/etc/cortex/config.yaml \
23+
cortexproject/cortex:v1.18.1 \
24+
-config.file=/etc/cortex/config.yaml \
25+
-target=all,alertmanager
26+
- name: Wait for Cortex
27+
run: |
28+
for i in $(seq 1 30); do
29+
if wget -qO- http://localhost:9009/ready > /dev/null 2>&1; then
30+
echo "Cortex is ready"
31+
exit 0
32+
fi
33+
echo "Waiting for Cortex... ($i)"
34+
sleep 2
35+
done
36+
echo "Cortex failed to start"
37+
docker logs cortex
38+
exit 1
39+
- name: Run Integration Tests
40+
env:
41+
CORTEX_ADDRESS: http://localhost:9009
42+
run: go test -mod=vendor -tags=integration -v -count=1 ./integration/...
43+
- name: Cortex Logs
44+
if: failure()
45+
run: docker logs cortex
46+
- name: Cleanup
47+
if: always()
48+
run: docker stop cortex && docker rm cortex

integration/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Integration Tests
2+
3+
## Running
4+
5+
```bash
6+
# Start Cortex
7+
docker run -d --name cortex-test -p 9009:9009 \
8+
-v $(pwd)/integration/cortex-config.yaml:/etc/cortex/config.yaml \
9+
cortexproject/cortex:v1.18.1 \
10+
-config.file=/etc/cortex/config.yaml \
11+
-target=all,alertmanager
12+
13+
# Wait for ready
14+
until curl -s http://localhost:9009/ready > /dev/null 2>&1; do sleep 2; done && echo "Ready"
15+
16+
# Run tests
17+
go test -mod=vendor -tags=integration -v -count=1 ./integration/...
18+
19+
# Cleanup
20+
docker stop cortex-test && docker rm cortex-test
21+
```
22+
23+
## Coverage
24+
25+
These integration tests require a running Cortex instance. Offline commands (lint, check, prepare, parse) are covered by unit tests in `pkg/rules/`.
26+
27+
| Command | Tested? |
28+
|---------|:---:|
29+
| **rules load/list/print/get** | Yes |
30+
| **rules delete (group)** | Yes |
31+
| **rules delete-namespace** | Yes |
32+
| **alertmanager load** | Yes |
33+
| **alertmanager load (with templates)** | Yes |
34+
| **alertmanager get** | Yes |
35+
| **alertmanager delete** | Yes |
36+
| **remote-read dump/stats** | Yes |
37+
| **remote-read export** | Yes |
38+
| **loadgen (write workload)** | Yes |
39+
| **analyse** (grafana/ruler/dashboard/rule-file) | No |
40+
| **bucket-validation** | No |
41+
| **config** (use-context) | No |
42+
| **alert verify** | No |
43+
| **push-gateway** | No |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
route:
2+
receiver: default
3+
receivers:
4+
- name: default

integration/cortex-config.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 9009
5+
grpc_server_max_recv_msg_size: 104857600
6+
grpc_server_max_send_msg_size: 104857600
7+
grpc_server_max_concurrent_streams: 1000
8+
9+
distributor:
10+
shard_by_all_labels: true
11+
pool:
12+
health_check_ingesters: true
13+
14+
ingester_client:
15+
grpc_client_config:
16+
max_recv_msg_size: 104857600
17+
max_send_msg_size: 104857600
18+
grpc_compression: gzip
19+
20+
ingester:
21+
lifecycler:
22+
min_ready_duration: 0s
23+
final_sleep: 0s
24+
num_tokens: 512
25+
ring:
26+
kvstore:
27+
store: inmemory
28+
replication_factor: 1
29+
30+
blocks_storage:
31+
tsdb:
32+
dir: /tmp/cortex/tsdb
33+
bucket_store:
34+
sync_dir: /tmp/cortex/tsdb-sync
35+
backend: filesystem
36+
filesystem:
37+
dir: /tmp/cortex/data/tsdb
38+
39+
compactor:
40+
data_dir: /tmp/cortex/compactor
41+
sharding_ring:
42+
kvstore:
43+
store: inmemory
44+
45+
frontend_worker:
46+
match_max_concurrent: true
47+
48+
ruler:
49+
enable_api: true
50+
51+
ruler_storage:
52+
backend: filesystem
53+
filesystem:
54+
dir: /tmp/cortex/rules
55+
56+
alertmanager:
57+
enable_api: true
58+
external_url: http://localhost:9009/alertmanager
59+
sharding_ring:
60+
kvstore:
61+
store: inmemory
62+
replication_factor: 1
63+
64+
alertmanager_storage:
65+
backend: filesystem
66+
filesystem:
67+
dir: /tmp/cortex/alerts

0 commit comments

Comments
 (0)