Skip to content

Bug 1882730: fix cluster:cpu_core_hyperthreading rule for s390x #953

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

Merged
merged 2 commits into from
Oct 27, 2020
Merged
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
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,17 @@ jsonnet-fmt: $(JSONNETFMT_BIN)
shellcheck:
hack/shellcheck.sh

tmp/rules.yaml: $(GOJSONTOYAML_BIN) assets/prometheus-k8s/rules.yaml
cat assets/prometheus-k8s/rules.yaml | $(GOJSONTOYAML_BIN) -yamltojson | jq .spec > "$@"

.PHONY: check-rules
check-rules: $(PROMTOOL_BIN) $(GOJSONTOYAML_BIN) assets/prometheus-k8s/rules.yaml
@$(PROMTOOL_BIN) check rules <(cat assets/prometheus-k8s/rules.yaml | $(GOJSONTOYAML_BIN) -yamltojson | jq .spec) | tee tmp/rules.out
check-rules: $(PROMTOOL_BIN) tmp/rules.yaml
rm -f tmp/"$@".out
@$(PROMTOOL_BIN) check rules tmp/rules.yaml | tee "tmp/[email protected]"

.PHONY: test-rules
test-rules: check-rules
hack/test-rules.sh | tee "tmp/[email protected]"

###########
# Testing #
Expand All @@ -146,8 +154,9 @@ check-rules: $(PROMTOOL_BIN) $(GOJSONTOYAML_BIN) assets/prometheus-k8s/rules.yam
.PHONY: test
test: test-unit test-e2e

# TODO(simonpasquier): we should have a CI job specifically checking Prometheus rules.
.PHONY: test-unit
test-unit:
test-unit: test-rules
go test -race -short $(PKGS) -count=1

.PHONY: test-e2e
Expand Down
30 changes: 25 additions & 5 deletions assets/prometheus-k8s/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,31 @@ spec:
record: cluster:capacity_cpu_cores:sum
- expr: |
clamp_max(
(
label_replace( ( ( sum (node_cpu_info) by (instance, package, core) ) > 1 ), "label_node_hyperthread_enabled", "true", "instance", "(.*)" )
or on (instance, package)
label_replace( ( ( sum (node_cpu_info) by (instance, package, core) ) <= 1 ), "label_node_hyperthread_enabled", "false", "instance", "(.*)" )
), 1
label_replace(
sum by(instance, package, core) (
node_cpu_info{core!="",package!=""}
or
# Assume core = cpu and package = 0 for platforms that don't expose core/package labels.
label_replace(label_join(node_cpu_info{core="",package=""}, "core", "", "cpu"), "package", "0", "package", "")
) > 1,
"label_node_hyperthread_enabled",
"true",
"instance",
"(.*)"
) or on (instance, package)
label_replace(
sum by(instance, package, core) (
label_replace(node_cpu_info{core!="",package!=""}
or
# Assume core = cpu and package = 0 for platforms that don't expose core/package labels.
label_join(node_cpu_info{core="",package=""}, "core", "", "cpu"), "package", "0", "package", "")
) <= 1,
"label_node_hyperthread_enabled",
"false",
"instance",
"(.*)"
),
1
)
record: cluster:cpu_core_hyperthreading
- expr: |
Expand Down
1 change: 1 addition & 0 deletions hack/build-jsonnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -x
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

# Ensure that we use the binaries from the versions defined in hack/tools/go.mod.
PATH="$(pwd)/tmp/bin:${PATH}"

prefix="assets"
Expand Down
17 changes: 17 additions & 0 deletions hack/test-rules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e
set -x
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

# Ensure that we use the binaries from the versions defined in hack/tools/go.mod.
PATH="$(pwd)/tmp/bin:${PATH}"

TMP_RULE_FILE=$(mktemp tmp/tmp.XXXXXXXXXX.yaml)
trap 'rm -f "$TMP_RULE_FILE"' EXIT

for rule in ./test/rules/*.yaml; do
echo ">> testing $rule <<";
gojsontoyaml -yamltojson - < "$rule" | jq '.rule_files=["rules.yaml"]' | gojsontoyaml - > "$TMP_RULE_FILE"
promtool test rules "$TMP_RULE_FILE"
done
30 changes: 25 additions & 5 deletions jsonnet/rules.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,31 @@ local droppedKsmLabels = 'endpoint, instance, job, pod, service';
{
expr: |||
clamp_max(
(
label_replace( ( ( sum (node_cpu_info) by (instance, package, core) ) > 1 ), "label_node_hyperthread_enabled", "true", "instance", "(.*)" )
or on (instance, package)
label_replace( ( ( sum (node_cpu_info) by (instance, package, core) ) <= 1 ), "label_node_hyperthread_enabled", "false", "instance", "(.*)" )
), 1
label_replace(
sum by(instance, package, core) (
node_cpu_info{core!="",package!=""}
or
# Assume core = cpu and package = 0 for platforms that don't expose core/package labels.
label_replace(label_join(node_cpu_info{core="",package=""}, "core", "", "cpu"), "package", "0", "package", "")
) > 1,
"label_node_hyperthread_enabled",
"true",
"instance",
"(.*)"
) or on (instance, package)
label_replace(
sum by(instance, package, core) (
label_replace(node_cpu_info{core!="",package!=""}
or
# Assume core = cpu and package = 0 for platforms that don't expose core/package labels.
label_join(node_cpu_info{core="",package=""}, "core", "", "cpu"), "package", "0", "package", "")
) <= 1,
"label_node_hyperthread_enabled",
"false",
"instance",
"(.*)"
),
1
)
|||,
record: 'cluster:cpu_core_hyperthreading',
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifests/bindata.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This directory contains [unit
tests](https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/)
for recording and alerting rules shipped by the Cluster Monitoring Operator.

To execute the tests, run `make test-rules` from the root directory.
Loading