Repository navigation
feat(ingester): export a counter for submission files that fail preparation - #2225
Conversation
| except Exception as e: | ||
| origin_info = _extract_origins_info(data) | ||
| logger.error("Error preparing data from %s%s: %s", file["name"], origin_info, e) | ||
| logger.error(traceback.format_exc()) | ||
| FILE_FAILURES_COUNTER.labels( | ||
| ingester=INGESTER_GRAFANA_LABEL, reason=_failure_reason(e) | ||
| ).inc() | ||
| return None, { | ||
| "error": str(e), | ||
| } |
There was a problem hiding this comment.
When the JSON parses but has the wrong shape, prepare_file_data raises inside the except block:
[1]:standardize_tree_namesraisesAttributeError, then_extract_origins_info(data)raises again inside the handler.{"checkouts": ["a"]}: same result.
The exception leaves prepare_file_data. process_batch has no try around it, so the worker exits. The file stays in the spool and kcidb_ingestion_failures is not incremented.
It seems this bug predates this PR. But would be good to fix it, we can do it separately though
There was a problem hiding this comment.
Agreed. This may come from #1790, which added _extract_origins_info to this except.
We could also benefit from moving the increment to after the file is moved to failed/. A file that stays in the spool is counted again on the next pass, so counting after the move counts each file once.
There was a problem hiding this comment.
Fixed, Now will handle malformed submissions without crashing the worker, and increment the failure counter only after successfully moving the file to failed/.
63a95cd to
00c78a9
Compare
…ration Count preparation failures by reason after files move to failed, so a failed move does not count the same file again on each retry. Exclude deferred submissions from the counter. Handle malformed submission structures when extracting origins for error logs, so invalid data reaches the failure handler without killing a worker. Closes kernelci#1505 Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com> Assisted-by: Codex (GPT-6)
00c78a9 to
ef8def2
Compare
Files that fail JSON decoding or schema validation were only logged and moved to the failed directory, so Grafana could not show them. Add the
kcidb_ingestion_failurescounter, labelled withreason=json_decode,schema_validationorother.Increment the counter only after a successful move to
failed/. Failed moves leave the file in the spool without counting it again on each retry. Deferred files with log excerpt upload errors remain excluded.Make origin extraction tolerate malformed submission structures so inputs such as
[1]and{"checkouts":["a"]}reach failure handling instead of crashing the worker while logging the error.Validation: all 61 tests in the ingester test file pass, along with Ruff lint and formatting checks. Regression tests exercise malformed data, successful moves, repeated failed moves, and deferred files.
To reproduce from
backend/:poetry run pytest kernelCI_app/tests/unitTests/commands/monitorSubmissions/kcidbng_ingester_test.py -o addopts='' -p no:rerunfailures -q poetry run ruff check kernelCI_app/management/commands/helpers/kcidbng_ingester.py kernelCI_app/tests/unitTests/commands/monitorSubmissions/kcidbng_ingester_test.py poetry run ruff format --check kernelCI_app/management/commands/helpers/kcidbng_ingester.py kernelCI_app/tests/unitTests/commands/monitorSubmissions/kcidbng_ingester_test.pyThe test command runs serially with automatic reruns disabled and does not require a running database.
Closes #1505