Skip to content

Commit c10ddb0

Browse files
committed
Merge branch 'issues/210' into link-rule
2 parents 5859aac + 561f8ae commit c10ddb0

File tree

16 files changed

+209
-90
lines changed

16 files changed

+209
-90
lines changed

docs/DEV.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,54 @@ Kelemetrix is a separate component that consumes audit logs into metric points.
313313
Tag providers provide string tags to use in kelemetrix.toml,
314314
and quantifiers provide scalar quantities.
315315

316-
## Testing
316+
## End-to-end Testing
317317

318318
Kelemetry runs end-to-end tests on GitHub CI.
319319
Each test suite is a directory under the [`e2e`](../e2e) directory
320320
with the following structure:
321321

322-
- `client.sh`: Executes a series of operations on a running cluster at `$KUBECONFIG`
323-
to trigger generation of a test trace.
324-
It can be assumed that the default `make quickstart` configuration is running for the cluster.
325-
- `config.sh`: Defines the following `local` Bash variables.
322+
- `config.sh`: Sourced by the e2e test script,
323+
executes a series of operations on a running cluster at `$KUBECONFIG`
324+
to trigger a background `make quickstart` to generate the test trace.
325+
Also defines the following `local` Bash variables.
326326
It is directly `source`d by the e2e test script.
327-
- `TRACE_DISPLAY_NAME`, the display name of the trace shown on the [demo index](https://kubewharf.io/kelemetry/)
327+
- `TRACE_DISPLAY_NAME`, the display name of the trace shown on the [demo index](https://kubewharf.io/kelemetry/).
328328
- `TRACE_SEARCH_TAGS`, an associative array for the search tags to uniquely identify the test trace generated by `client.sh`.
329+
- `TEST_DISPLAY_MODE`, the display mode of the trace to test with.
330+
- `EXTRA_DISPLAY_MODES` (optional), an indexed array for additional display modes to show on GitHub Pages without getting tested in the e2e test.
329331
- `validate.jq`: A `jq` script that takes the test trace JSON as input
330332
and [fails](https://jqlang.github.io/jq/manual/#error) if errors are encountered.
331333
The script may use library functions defined under [`e2e/lib`](../e2e/lib).
332334
The current framework uses [gojq](https://github.com/itchyny/gojq/) as the `jq` implementation.
335+
336+
End-to-end tests can be executed locally with the commands:
337+
338+
```console
339+
$ make kind
340+
$ make e2e
341+
```
342+
343+
`make e2e` automatically runs `make quickstart`
344+
using a custom image built from the local `make output/kelemetry` output.
345+
If you prefer to run the kelemetry process directly (e.g. with a debugger),
346+
use the following steps instead:
347+
348+
1. Clean up all previous data by removing the stack volumes completely:
349+
350+
```bash
351+
make stack COMPOSE_COMMAND='down --remove-orphans --volumes'
352+
```
353+
354+
2. Recreate the stack:
355+
356+
```bash
357+
make stack COMPOSE_COMMAND='up --build -d --remove-orphans'
358+
```
359+
360+
3. Run Kelemetry with your preferred method equivalent to `make`.
361+
362+
4. Execute the e2e test script:
363+
364+
```bash
365+
bash e2e/run-all.sh
366+
```

e2e/ancestors/config.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# script
2+
kubectl create deployment ancestors --image=alpine:3.16 --replicas=2 -- sleep infinity
3+
local first_rs_name=$(kubectl get replicasets --selector app=ancestors -o json | jq -r '.items[0].metadata.name')
4+
sleep 5
5+
kubectl set image deployments ancestors alpine=alpine:3.17
6+
sleep 30
7+
kubectl delete deployments ancestors
8+
9+
# config
10+
local TEST_DISPLAY_MODE="22000000" # tracing, ancestors only
11+
local TRACE_DISPLAY_NAME="Deployment"
12+
13+
TRACE_SEARCH_TAGS[cluster]=tracetest
14+
TRACE_SEARCH_TAGS[group]=apps
15+
TRACE_SEARCH_TAGS[resource]=replicasets
16+
TRACE_SEARCH_TAGS[namespace]=default
17+
TRACE_SEARCH_TAGS[name]=$first_rs_name

e2e/ancestors/validate.jq

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include "assert";
2+
include "graph";
3+
4+
.data[0]
5+
| ._ = (
6+
# check root
7+
.spans
8+
| root
9+
| .tags | from_entries
10+
| assertEq("root span is deployment"; .resource; "deployments")
11+
| assertEq("root span has the correct name"; .name; "ancestors")
12+
) | ._ = (
13+
# root only has one child
14+
.spans
15+
| children(root.spanID)
16+
| assertEq("there is only one child replicaset"; length; 1)
17+
)
18+
| null

e2e/deployment/client.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

e2e/deployment/config.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
# script
2+
kubectl create deployment demo --image=alpine:3.16 --replicas=2 -- sleep infinity
3+
sleep 5
4+
kubectl scale deployment demo --replicas=4
5+
sleep 5
6+
kubectl set image deployments demo alpine=alpine:3.17
7+
sleep 5
8+
kubectl scale deployment demo --replicas=2
9+
sleep 5
10+
kubectl delete deployment demo
11+
sleep 30
12+
13+
# config
14+
local TEST_DISPLAY_MODE="21000000" # tracing, full tree
115
local TRACE_DISPLAY_NAME="Deployment"
216

3-
declare -A TRACE_SEARCH_TAGS
417
TRACE_SEARCH_TAGS[cluster]=tracetest
518
TRACE_SEARCH_TAGS[group]=apps
619
TRACE_SEARCH_TAGS[resource]=deployments

e2e/run-all.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ cd $(dirname $0)
66

77
export REPO_PATH=$(realpath ..)
88

9-
export TEST_DISPLAY_MODE="21000000"
10-
11-
export DISPLAY_MODES="${TEST_DISPLAY_MODE} ${DISPLAY_MODES:-}"
12-
139
run_test() {
1410
local test_name=$1
1511

1612
local tmpdir=$(mktemp -d)
1713

18-
if [[ ! -v IS_RERUN ]]; then
19-
bash -x ${test_name}/client.sh
20-
fi
21-
14+
declare -A TRACE_SEARCH_TAGS
15+
declare -a EXTRA_DISPLAY_MODES
16+
set -x
2217
source ${test_name}/config.sh
18+
set +x
2319

2420
local curl_param_string=""
2521
for curl_param_key in "${!TRACE_SEARCH_TAGS[@]}"; do
@@ -32,6 +28,12 @@ run_test() {
3228
-o ${tmpdir}/curl-output.http \
3329
localhost:8080/redirect
3430

31+
if ! (head -n1 ${tmpdir}/curl-output.http | grep '302 Found'); then
32+
echo "Trace not found for the parameters"
33+
cat curl-output.http
34+
exit 1
35+
fi
36+
3537
local full_trace_id=$(grep -P "^Location: /trace/" ${tmpdir}/curl-output.http | cut -d/ -f3 | tr -d '\r')
3638
if [[ -z $full_trace_id ]]; then
3739
echo "Trace not found for the parameters"
@@ -46,6 +48,8 @@ run_test() {
4648
echo "${TRACE_DISPLAY_NAME}" >${OUTPUT_TRACE}/trace-${test_name}/trace_display_name
4749
echo ${fixed_id} >${OUTPUT_TRACE}/trace-${test_name}/trace_id
4850

51+
DISPLAY_MODES=($TEST_DISPLAY_MODE ${EXTRA_DISPLAY_MODES[@]})
52+
4953
for mode in ${DISPLAY_MODES}; do
5054
local mode_trace_id=ff${mode}${fixed_id}
5155
curl -o ${OUTPUT_TRACE}/api/traces/${mode_trace_id} localhost:16686/api/traces/${mode_trace_id}
@@ -59,10 +63,12 @@ run_test() {
5963

6064
declare -A pids
6165

62-
for client in */client.sh; do
63-
test_name=$(basename $(dirname $client))
64-
run_test ${test_name} &
65-
pids[$test_name]=$!
66+
for sh in */validate.jq; do
67+
test_name=$(basename $(dirname $sh))
68+
if [[ ! -v FILTER_TESTS ]] || [[ $FILTER_TESTS == *$test_name* ]]; then
69+
run_test ${test_name} &
70+
pids[$test_name]=$!
71+
fi
6672
done
6773

6874
failed_tests=()

e2e/secret-link/client.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

e2e/secret-link/config.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
1+
kubectl create -f ${REPO_PATH}/crds/samples/pod-secret.yaml
2+
3+
kubectl create secret generic content
4+
5+
kubectl create -f - << EOF
6+
apiVersion: apps/v1
7+
kind: Deployment
8+
metadata:
9+
name: reader
10+
labels:
11+
app: reader
12+
spec:
13+
selector:
14+
matchLabels:
15+
app: reader
16+
replicas: 2
17+
template:
18+
metadata:
19+
labels:
20+
app: reader
21+
spec:
22+
containers:
23+
- name: reader
24+
command: ["sleep", "infinity"]
25+
image: alpine:3.16
26+
volumeMounts:
27+
- name: content
28+
mountPath: /mnt/content
29+
volumes:
30+
- name: content
31+
secret:
32+
secretName: content
33+
EOF
34+
sleep 10
35+
36+
kubectl delete deployment/reader secret/content
37+
sleep 20
38+
39+
# config
40+
local TEST_DISPLAY_MODE="24100000" # tracing, owned objects, volumes
141
local TRACE_DISPLAY_NAME="Volume links"
2-
local TEST_DISPLAY_MODE="24100000"
342

4-
declare -A TRACE_SEARCH_TAGS
543
TRACE_SEARCH_TAGS[cluster]=tracetest
644
TRACE_SEARCH_TAGS[group]=apps
745
TRACE_SEARCH_TAGS[resource]=deployments

hack/kind-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nodes:
1414
apiServer:
1515
extraArgs:
1616
audit-webhook-config-file: /mnt/audit/audit-kubeconfig.local.yaml
17+
audit-webhook-batch-max-wait: 5s # speed up event consumption during test
1718
tracing-config-file: /mnt/audit/tracing-config.local.yaml
1819
audit-policy-file: /mnt/audit/audit-policy.yaml
1920
extraVolumes:

hack/tfconfig.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ modifiers:
6363
modifierName: link-selector
6464
args:
6565
modifierClass: owner-ref
66-
includeSiblings: true
66+
includeSiblings: false
67+
ifAll:
68+
- linkClass: children
69+
fromParent: false
6770
upwardDistance: 3
6871
"04000000":
6972
# the entire subtree under this object
@@ -77,7 +80,7 @@ modifiers:
7780
downwardDistance: 3
7881
"00100000":
7982
# include secrets under pods
80-
displayName: volume secrets
83+
displayName: volumes
8184
modifierName: link-selector
8285
args:
8386
ifAll:

0 commit comments

Comments
 (0)