Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add more tests #1002

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ clean:

.PHONY: test
test: $(PROMTOOL_BIN) prometheus_alerts.yaml prometheus_rules.yaml
@$(PROMTOOL_BIN) test rules tests.yaml
@$(PROMTOOL_BIN) test rules tests/*.yaml

$(BIN_DIR):
mkdir -p $(BIN_DIR)
Expand Down
23 changes: 23 additions & 0 deletions tests/apiserver-availability-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rule_files:
- ../prometheus_alerts.yaml
- ../prometheus_rules.yaml

evaluation_interval: 1m

tests:
- interval: 1m
input_series:
# 100 requests in the overall interval, 99 successful and 1 error
- series: 'apiserver_request_total{job="kube-apiserver",verb="GET",code="200"}'
values: '0 10 20 50 90 99'
- series: 'apiserver_request_total{job="kube-apiserver",verb="GET",code="500"}'
values: '0 0 0 1 1 1'

promql_expr_test:
- eval_time: 5m
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I just found out that you can name tests, this is really useful for identifying which test has failed and can indicate the intention of the test, in case you'd like to use the name property (see docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good finding! Will start using it

expr: code_verb:apiserver_request_total:increase1h{verb="GET"}
exp_samples:
- labels: '{__name__="code_verb:apiserver_request_total:increase1h", code="200", verb="GET"}'
value: 99.0
- labels: '{__name__="code_verb:apiserver_request_total:increase1h", code="500", verb="GET"}'
value: 1.0
4 changes: 2 additions & 2 deletions tests.yaml → tests/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rule_files:
- prometheus_alerts.yaml
- prometheus_rules.yaml
- ../prometheus_alerts.yaml
- ../prometheus_rules.yaml

evaluation_interval: 1m

Expand Down