Skip to content

Commit 96d585c

Browse files
tests: add more tests (#1002)
* test: move tests to dedicated directory * test: (wip) add apiserver tests * feat: add test group name * test: update apiserver availability tests to include new metrics and calculations * refactor(tests): update labels format in apiserver availability tests
1 parent e7b2ff7 commit 96d585c

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ clean:
9090

9191
.PHONY: test
9292
test: $(PROMTOOL_BIN) prometheus_alerts.yaml prometheus_rules.yaml
93-
@$(PROMTOOL_BIN) test rules tests.yaml
93+
@$(PROMTOOL_BIN) test rules tests/*.yaml
9494

9595
$(BIN_DIR):
9696
mkdir -p $(BIN_DIR)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
rule_files:
2+
- ../prometheus_alerts.yaml
3+
- ../prometheus_rules.yaml
4+
5+
evaluation_interval: 1m
6+
7+
tests:
8+
- name: calculate apiserver request total increase 1h rate
9+
interval: 1m
10+
input_series:
11+
# 100 requests in the overall interval, 99 successful and 1 error
12+
- series: 'apiserver_request_total{job="kube-apiserver",verb="GET",code="200"}'
13+
values: '0 10 20 50 90 99'
14+
- series: 'apiserver_request_total{job="kube-apiserver",verb="GET",code="500"}'
15+
values: '0x2 1x2'
16+
17+
promql_expr_test:
18+
- eval_time: 5m
19+
expr: code_verb:apiserver_request_total:increase1h{verb="GET"}
20+
exp_samples:
21+
- labels: 'code_verb:apiserver_request_total:increase1h{code="200", verb="GET"}'
22+
value: 99.0
23+
- labels: 'code_verb:apiserver_request_total:increase1h{code="500", verb="GET"}'
24+
value: 1.0
25+
26+
- name: calculate apiserver request total increase 30d rate
27+
interval: 1m
28+
input_series:
29+
- series: code_verb:apiserver_request_total:increase1h{verb="GET",code="200"}
30+
values: '10+10x9'
31+
- series: code_verb:apiserver_request_total:increase1h{verb="GET",code="500"}
32+
values: '0+1x9'
33+
34+
promql_expr_test:
35+
- eval_time: 10m
36+
expr: code_verb:apiserver_request_total:increase30d{verb="GET"}
37+
exp_samples:
38+
- labels: 'code_verb:apiserver_request_total:increase30d{code="200", verb="GET"}'
39+
value: 3.96e+4 # average of the input series values times 24 (hours) times 30 (days)
40+
- labels: 'code_verb:apiserver_request_total:increase30d{code="500", verb="GET"}'
41+
value: 3.24e+3

tests.yaml renamed to tests/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rule_files:
2-
- prometheus_alerts.yaml
3-
- prometheus_rules.yaml
2+
- ../prometheus_alerts.yaml
3+
- ../prometheus_rules.yaml
44

55
evaluation_interval: 1m
66

0 commit comments

Comments
 (0)