@@ -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+
153194function helm_install_log_generator_to_ns() {
154195 local namespace=" $1 "
155196 shift
@@ -178,18 +219,18 @@ function helm_uninstall_log_generator_from_ns()
178219
179220function 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
188229function 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+
257377main " $@ "
0 commit comments