Skip to content

feat(ingester): export a counter for submission files that fail preparation - #2225

Merged
nuclearcat merged 1 commit into
kernelci:mainfrom
nuclearcat:feat/1505/ingester-failure-metric
Nov 11, 2026
Merged

nuclearcat merged 1 commit into
kernelci:mainfrom
nuclearcat:feat/1505/ingester-failure-metric

Conversation

@nuclearcat

@nuclearcat nuclearcat commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

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_failures counter, labelled with reason=json_decode, schema_validation or other.

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.py

The test command runs serially with automatic reruns disabled and does not require a running database.

Closes #1505

Comment on lines 208 to 217
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),
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the JSON parses but has the wrong shape, prepare_file_data raises inside the except block:

  • [1]: standardize_tree_names raises AttributeError, 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, Now will handle malformed submissions without crashing the worker, and increment the failure counter only after successfully moving the file to failed/.

@nuclearcat
nuclearcat force-pushed the feat/1505/ingester-failure-metric branch 3 times, most recently from 63a95cd to 00c78a9 Compare November 10, 2026 18:18
…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)
@nuclearcat
nuclearcat force-pushed the feat/1505/ingester-failure-metric branch from 00c78a9 to ef8def2 Compare November 11, 2026 07:16
@nuclearcat
nuclearcat added this pull request to the merge queue Nov 11, 2026
Merged via the queue into kernelci:main with commit 716c83f Nov 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finalize dashboard ingester

3 participants