Skip to content

Commit ac24e09

Browse files
committed
feat: add e2e tests for problem tracking
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
1 parent 75bd3eb commit ac24e09

File tree

4 files changed

+280
-6
lines changed

4 files changed

+280
-6
lines changed

e2e/e2e_test.sh

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function main()
1111
test_tenants_with_bridges
1212
test_filestorage_receiver_failure
1313
test_filestorage_collector_failure
14+
test_problem_tracking
1415

1516
echo "E2E (helm) test: PASSED"
1617
}
@@ -150,6 +151,46 @@ function test_filestorage_collector_failure()
150151
undeploy_test_assets "e2e/testdata/filestorage/"
151152
}
152153

154+
function test_problem_tracking()
155+
{
156+
helm_install_log_generator_to_ns "problem-test-ns"
157+
158+
deploy_test_assets "e2e/testdata/problem_tracking/problem"
159+
160+
# Verify initial problem states
161+
check_resource_status "output" "problem-test-ns" "output-without-tenant" "tenant" "problem-test-tenant"
162+
check_resource_status "subscription" "problem-test-ns" "valid-subscription" "state" "ready"
163+
164+
check_resource_status "subscription" "problem-test-ns" "subscription-missing-output" "state" "failed"
165+
check_resource_problems "subscription" "problem-test-ns" "subscription-missing-output" "non-existent-output" 1
166+
167+
check_resource_status "subscription" "problem-test-ns" "cross-tenant-subscription" "state" "failed"
168+
check_resource_problems "subscription" "problem-test-ns" "cross-tenant-subscription" "tenant" 1
169+
170+
check_resource_status "tenant" "" "problem-test-tenant" "state" "failed"
171+
# there should be atleast 1 problem
172+
check_resource_problems_min "tenant" "" "problem-test-tenant" "subscription-missing-output" 1
173+
174+
# Apply fixes
175+
deploy_test_assets "e2e/testdata/problem_tracking/fix"
176+
177+
# Verify fixed states
178+
check_resource_status "subscription" "problem-test-ns" "subscription-missing-output" "state" "ready"
179+
check_resource_problems "subscription" "problem-test-ns" "subscription-missing-output" "" 0
180+
181+
check_resource_status "subscription" "problem-test-ns" "cross-tenant-subscription" "state" "ready"
182+
check_resource_problems "subscription" "problem-test-ns" "cross-tenant-subscription" "" 0
183+
184+
check_resource_status "tenant" "" "problem-test-tenant" "state" "ready"
185+
check_resource_problems "tenant" "" "problem-test-tenant" "" 0
186+
187+
# Verify logs are flowing
188+
check_logs_in_workload_with_regex "telemetry-controller-system" "deployments" "receiver-collector" "valid-subscription"
189+
190+
helm_uninstall_log_generator_from_ns "problem-test-ns"
191+
undeploy_test_assets "e2e/testdata/problem_tracking/problem"
192+
}
193+
153194
function helm_install_log_generator_to_ns() {
154195
local namespace="$1"
155196
shift
@@ -178,18 +219,18 @@ function helm_uninstall_log_generator_from_ns()
178219

179220
function deploy_test_assets()
180221
{
181-
local manifests="$1"
182-
183-
kubectl apply -f "${manifests}"
222+
for manifest in "$@"; do
223+
kubectl apply -f "${manifest}"
224+
done
184225

185226
sleep 5
186227
}
187228

188229
function undeploy_test_assets()
189230
{
190-
local manifests="$1"
191-
192-
kubectl delete -f "${manifests}"
231+
for manifest in "$@"; do
232+
kubectl delete -f "${manifest}"
233+
done
193234

194235
sleep 5
195236
}
@@ -254,4 +295,83 @@ function check_logs_until_expected_number_is_reached() {
254295
done
255296
}
256297

298+
function check_resource_status()
299+
{
300+
local resource_type="$1"
301+
local namespace="$2"
302+
local resource_name="$3"
303+
local field="$4"
304+
local expected_value="$5"
305+
306+
local ns_flag=""
307+
if [ -n "$namespace" ]; then
308+
ns_flag="-n $namespace"
309+
fi
310+
311+
local actual_value=$(kubectl get "$resource_type" $ns_flag "$resource_name" -o jsonpath="{.status.$field}")
312+
313+
if [ "$actual_value" != "$expected_value" ]; then
314+
echo "ERROR: $resource_type $resource_name should have $field '$expected_value', but has '$actual_value'"
315+
kubectl get "$resource_type" $ns_flag "$resource_name" -o yaml
316+
return 1
317+
fi
318+
}
319+
320+
function check_resource_problems()
321+
{
322+
local resource_type="$1"
323+
local namespace="$2"
324+
local resource_name="$3"
325+
local expected_problem_text="$4"
326+
local expected_count="$5"
327+
328+
local ns_flag=""
329+
if [ -n "$namespace" ]; then
330+
ns_flag="-n $namespace"
331+
fi
332+
333+
local problems=$(kubectl get "$resource_type" $ns_flag "$resource_name" -o jsonpath='{.status.problems}')
334+
local problems_count=$(kubectl get "$resource_type" $ns_flag "$resource_name" -o jsonpath='{.status.problemsCount}')
335+
336+
# Check if problems should be empty
337+
if [ -z "$expected_problem_text" ]; then
338+
if ([ -n "$problems" ] && [ "$problems" != "[]" ]) || [ "$problems_count" -ne "$expected_count" ]; then
339+
echo "ERROR: $resource_type $resource_name should have no problems"
340+
echo "Problems: $problems"
341+
return 1
342+
fi
343+
else
344+
# Check if problems contain expected text
345+
if [[ ! "$problems" == *"$expected_problem_text"* ]] || [ "$problems_count" -ne "$expected_count" ]; then
346+
echo "ERROR: $resource_type $resource_name should have problem mentioning '$expected_problem_text' and count $expected_count"
347+
echo "Problems: $problems (count: $problems_count)"
348+
return 1
349+
fi
350+
fi
351+
}
352+
353+
function check_resource_problems_min()
354+
{
355+
local resource_type="$1"
356+
local namespace="$2"
357+
local resource_name="$3"
358+
local expected_problem_text="$4"
359+
local min_count="$5"
360+
361+
local ns_flag=""
362+
if [ -n "$namespace" ]; then
363+
ns_flag="-n $namespace"
364+
fi
365+
366+
local problems=$(kubectl get "$resource_type" $ns_flag "$resource_name" -o jsonpath='{.status.problems}')
367+
local problems_count=$(kubectl get "$resource_type" $ns_flag "$resource_name" -o jsonpath='{.status.problemsCount}')
368+
369+
# Check if problems contain expected text and count is at least min_count
370+
if [[ ! "$problems" == *"$expected_problem_text"* ]] || [ "$problems_count" -lt "$min_count" ]; then
371+
echo "ERROR: $resource_type $resource_name should have problem mentioning '$expected_problem_text' and count >= $min_count"
372+
echo "Problems: $problems (count: $problems_count)"
373+
return 1
374+
fi
375+
}
376+
257377
main "$@"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: telemetry.kube-logging.dev/v1alpha1
2+
kind: Output
3+
metadata:
4+
name: non-existent-output
5+
namespace: problem-test-ns
6+
spec:
7+
otlp:
8+
endpoint: receiver-collector.telemetry-controller-system.svc.cluster.local:4317
9+
tls:
10+
insecure: true
11+
---
12+
apiVersion: telemetry.kube-logging.dev/v1alpha1
13+
kind: Subscription
14+
metadata:
15+
name: cross-tenant-subscription
16+
namespace: problem-test-ns
17+
spec:
18+
condition: "true"
19+
outputs:
20+
- name: output-without-tenant
21+
namespace: problem-test-ns
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: collector
5+
---
6+
apiVersion: v1
7+
kind: Namespace
8+
metadata:
9+
labels:
10+
nsSelector: problem-test
11+
name: problem-test-ns
12+
---
13+
apiVersion: telemetry.kube-logging.dev/v1alpha1
14+
kind: Collector
15+
metadata:
16+
name: problem-test-collector
17+
spec:
18+
controlNamespace: collector
19+
tenantSelector:
20+
matchLabels:
21+
collectorLabel: problem-test
22+
---
23+
apiVersion: telemetry.kube-logging.dev/v1alpha1
24+
kind: Tenant
25+
metadata:
26+
labels:
27+
collectorLabel: problem-test
28+
name: problem-test-tenant
29+
spec:
30+
subscriptionNamespaceSelectors:
31+
- matchLabels:
32+
nsSelector: problem-test
33+
logSourceNamespaceSelectors:
34+
- matchLabels:
35+
nsSelector: problem-test
36+
---
37+
apiVersion: telemetry.kube-logging.dev/v1alpha1
38+
kind: Output
39+
metadata:
40+
name: output-without-tenant
41+
namespace: problem-test-ns
42+
spec:
43+
otlp:
44+
endpoint: receiver-collector.telemetry-controller-system.svc.cluster.local:4317
45+
tls:
46+
insecure: true
47+
---
48+
apiVersion: telemetry.kube-logging.dev/v1alpha1
49+
kind: Subscription
50+
metadata:
51+
name: valid-subscription
52+
namespace: problem-test-ns
53+
spec:
54+
condition: "true"
55+
outputs:
56+
- name: output-without-tenant
57+
namespace: problem-test-ns
58+
---
59+
apiVersion: telemetry.kube-logging.dev/v1alpha1
60+
kind: Subscription
61+
metadata:
62+
name: subscription-missing-output
63+
namespace: problem-test-ns
64+
spec:
65+
condition: "true"
66+
outputs:
67+
- name: non-existent-output
68+
namespace: problem-test-ns
69+
---
70+
apiVersion: v1
71+
kind: Namespace
72+
metadata:
73+
labels:
74+
nsSelector: other-tenant
75+
name: other-tenant-ns
76+
---
77+
apiVersion: telemetry.kube-logging.dev/v1alpha1
78+
kind: Tenant
79+
metadata:
80+
labels:
81+
collectorLabel: problem-test
82+
name: other-tenant
83+
spec:
84+
subscriptionNamespaceSelectors:
85+
- matchLabels:
86+
nsSelector: other-tenant
87+
logSourceNamespaceSelectors:
88+
- matchLabels:
89+
nsSelector: other-tenant
90+
---
91+
apiVersion: telemetry.kube-logging.dev/v1alpha1
92+
kind: Output
93+
metadata:
94+
name: other-tenant-output
95+
namespace: other-tenant-ns
96+
spec:
97+
otlp:
98+
endpoint: receiver-collector.telemetry-controller-system.svc.cluster.local:4317
99+
tls:
100+
insecure: true
101+
---
102+
apiVersion: telemetry.kube-logging.dev/v1alpha1
103+
kind: Subscription
104+
metadata:
105+
name: cross-tenant-subscription
106+
namespace: problem-test-ns
107+
spec:
108+
condition: "true"
109+
outputs:
110+
- name: other-tenant-output
111+
namespace: other-tenant-ns
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: opentelemetry.io/v1beta1
2+
kind: OpenTelemetryCollector
3+
metadata:
4+
name: receiver
5+
namespace: telemetry-controller-system
6+
spec:
7+
managementState: managed
8+
image: otel/opentelemetry-collector-contrib:0.112.0
9+
config:
10+
receivers:
11+
otlp:
12+
protocols:
13+
grpc:
14+
endpoint: 0.0.0.0:4317
15+
exporters:
16+
debug:
17+
verbosity: detailed
18+
service:
19+
pipelines:
20+
logs:
21+
receivers: [otlp]
22+
exporters: [debug]

0 commit comments

Comments
 (0)