Skip to content

feat(sources): a manifest source loaded by the FHIR server through $bulk-submit - #45

Open
Gordex2014 wants to merge 8 commits into
HeliosSoftware:mainfrom
Gordex2014:feat/manifest-source
Open

Gordex2014 wants to merge 8 commits into
HeliosSoftware:mainfrom
Gordex2014:feat/manifest-source

Conversation

@Gordex2014

Copy link
Copy Markdown
Contributor

Closes #42.

A new source type, manifest: a user hands the engine a FHIR Bulk Data manifest, by URL or by uploading its JSON, and the engine passes it to the FHIR server with $bulk-submit. The FHIR server is the Data Consumer: it fetches the manifest and the NDJSON from the provider. The engine never downloads the NDJSON. It polls $bulk-submit-status and records each manifest the server accepts as one load, from the server's receipts.

What changes

The source (src/config.rs, src/manager.rs).

  • source: {type: manifest, poll_seconds?, oauth_metadata_url?}.
  • Refused: a transform, a format other than ndjson, any delivery but {method: bulk_submit}, expect_every, and a PUT that changes the type to or from manifest.
  • The definition is checked on what it holds, before defaults fill it in, and saved in one canonical form, which PUT accepts back as it is.
  • Born without a default silence rule.
  • POST /api/sources/test answers 400 not_supported.

Sending a manifest: POST /api/sources/{id}/manifests (src/api/manifests.rs, src/manifest.rs).

  • The body is {"manifest_url"} or {"manifest", "file_name"?}, plus an optional request_id. It is JSON only, at most 4 MiB, and needs hie/manage.
  • One submission per send. submissionId is hie-manifest- and a hash of the source, the load and a random token. The same URL or file sent twice loads twice.
  • The load is recorded unlisted before the kick-off, under the source's lock (and a PostgreSQL advisory lock). The kick-off is claimed right before it is sent, and every write after it is fenced.
  • Answers:
    • 2xx → 201 with the load.
    • A 4xx other than 401/403/408, or 501 → the FHIR server's status and body, byte for byte, with X-HIE-Refused-By: destination. No load is left.
    • 401/403, or a token the engine cannot get → 502 destination_auth. A warn log keeps the status and each issue's severity, code and text, with URLs cut to their origin, secrets redacted and text cut to 500 characters.
    • No connection → 502 destination_unreachable.
    • A lost answer (a timeout, 408, a 5xx other than 501, a 3xx) → 202 with an unconfirmed load.
  • An uploaded manifest is served at {public_url}/bulk/{token}/manifest.json while its load is open, then 404.
  • request_id makes a resend after a lost answer safe:
    • the same body returns the same load (200);
    • a different body answers 409 request_id_conflict;
    • a send still in flight answers 409 request_in_progress.

Recovery and polling (src/pipeline/manifest.rs, src/db/manifest.rs).

  • The source asks $bulk-submit-status about an unconfirmed load. A 404 counts only after a grace period.
  • A known submission whose final status lists no file is probed with a status-only kick-off (submissionStatus: in-progress, which changes nothing at HFS 0.2.8):
    • 409 means it completed: the status is read once more, and the load is settled from it;
    • 200 after the grace period means unreadable, with manifest.kickoff: "not_received".
  • A load still unlisted after twice the kick-off timeout is listed as unconfirmed.
  • Polls honour Retry-After and resume from the throttled page.
  • Each status page is one checkpoint: totals and failure groups, kept to the 100 largest at the end.
  • The engine's token goes only to the FHIR server's origin and its status URL's origin.
  • A 501 on the status endpoints, or a malformed status page, makes the load unreadable.
  • The lease is renewed and pause, stop and ownership are checked between requests.

The load (src/api.rs, src/api/loads.rs, src/db.rs).

  • Counts:
    • sent: the reference receipts.
    • rejected and failing: OperationOutcomes with an error or fatal issue.
  • failures are grouped by severity, code and reason.
  • A new manifest member on every load: null, or {by, request_id, submission_id, kickoff, sent_by_type, deleted}.
  • No per-line rows. Retry answers 409 not_retryable.
  • The stored and shown name has no query, fragment or user information. The URL itself is forwarded unchanged.
  • Unlisted loads are hidden from every list, count, check, rule and cursor.
  • Monitoring:
    • a manifest source's figures, and /stats, come from its receipts;
    • GET /api/monitoring/status last_24h gains by_source_type, whose members add up to the totals;
    • manifest requests count for the destination's reachability.
  • Stamping reads direct_bulk and counts manifest submissions.

Store. New columns on files (manifest, request_id, listed, listed_at, receipt counts and groups), submissions (load_id, manifest-only m_* statuses) and checks (cutoff_at), plus indexes. They are added in place on SQLite and PostgreSQL, and an existing store reopens.

Unchanged: the outbound delivery.method: bulk_submit path. src/bulk.rs is not touched. A 409 there is still a repeat of the same drop, and tests/bulk_submit.rs is untouched and passing.

Docs.

  • docs/sources.md has a Manifest section: the definition and its canonical form, the two calls, the answers, lost answers and what recovery can prove, receipts, and the limits.
  • docs/api.md adds the route's table, the manifest load member, by_source_type and the auth scope.
  • docs/development.md covers building a local image (docker build -t hie:local .).
  • README.md and ROADMAP.md updated.

In plain words

A user can load a Bulk Data export through the engine instead of straight into the FHIR server. Each manifest they send shows up as a load with what the server wrote and what it refused. A manifest the server refuses comes back with the server's own answer, and leaves nothing behind.

Side effects checked

  • API: additive. One new route. A new manifest member on every load (null for other loads), and by_source_type in monitoring. No existing member changes meaning.
  • Upgrade: new columns and indexes are added in place. Existing rows are listed (listed defaults to 1). Checks answered before this version keep unfiltered pages.
  • Several instances and versions: admission, dispatch, listing and settlement are fenced. An older binary sharing the store does not know manifest loads (documented).
  • Limits, documented in docs/sources.md:
    • no per-line rows and no Retry;
    • the FHIR server fetches whatever hosts the manifest names;
    • a protected provider depends on the FHIR server's SMART Backend Services configuration;
    • one accepted residual case: a kick-off cut after the server registered the manifest and before it completed the submission, for a manifest that leaves no receipt, ends not_received.
  • Review: two rounds, each with two independent reviewers.
  • Edits after the last review round (724baba, 743905f), checked by the gate, double runs, PostgreSQL and the end-to-end run below:
    • a check's count and pages use one strict cutoff under the source's lock;
    • monitoring totals come from the same read as by_source_type;
    • the kick-off deadline runs from when the load was recorded;
    • five attempts per receipt file;
    • a lost request_id replay race re-reads the row;
    • token invalidation stays within the deadline;
    • the destination observer sees kick-off timeouts;
    • a manifest source's figures are its receipts only;
    • doc corrections, including the residual case above.
  • Left unchanged after review, on purpose:
    • Renewing the lease during one long receipt download. Settlement and checkpoints are fenced by the claim epoch, so a takeover never writes wrong data. The cost is repeated work for a receipt that takes longer than the lease with a standby instance, as on the outbound path's receipt reads today.
    • A poll or receipt read already in flight when the source is paused or deleted. It may still finish and settle its load. It reports what the server did, and listing a load is not polling. This is documented, in line with the rule for a kick-off in flight.

How to verify

The CI commands, with CI=true and default parallelism, on this tree (Linux):

$ helios-ci-gate      # fmt, clippy (both feature sets), Python tests, cargo test, the no-backend tests
test: passed
  • tests/manifest_source.rs: 31 tests, run twice on SQLite and once against a throwaway PostgreSQL 16. All passed.
  • tests/bulk_submit.rs: 14 tests, run twice. All passed.
  • End to end against ghcr.io/heliossoftware/hfs:0.2.8, with a static provider serving a 2-Patient manifest (as in hfs docker/bulk-submit/provider) and the engine image built from this branch. Nine scenarios passed:
    • by URL;
    • by upload (served while open, 404 after);
    • the same URL twice (two loads, 2 sent each);
    • a broken file URL (a failed load with its reason);
    • an unfetchable manifest;
    • a refusal passed through, with HFS started with HFS_BULK_SUBMIT_ENABLED=false (501, same body and Content-Type, X-HIE-Refused-By, no load);
    • test/Retry/records refusals;
    • monitoring by_source_type sums;
    • a request_id replay and conflict.

To try it locally:

docker build -t hie:local .
# hie.yaml: fhir_base_url = the FHIR server as the engine reaches it; public_url = the engine as the FHIR server reaches it
curl -X POST localhost:8090/api/sources -H 'Content-Type: application/json' \
  -d '{"id":"provider-export","name":"Provider export","source":{"type":"manifest"}}'
curl -X POST localhost:8090/api/sources/provider-export/manifests -H 'Content-Type: application/json' \
  -d '{"manifest_url":"https://provider.example/manifest.json"}'

Links

…e FHIR server

A new source type, manifest: POST /api/sources/{id}/manifests takes a FHIR
Bulk Data manifest by URL (forwarded unchanged) or uploaded (stored and
served at /bulk/{token}/manifest.json while its load is open), and hands it
to the FHIR server with $bulk-submit, one submission per send. The load is
recorded, unlisted, before the kick-off; a refusal comes back with the
server's status and body and leaves no load; a lost answer is kept as
unconfirmed and confirmed with $bulk-submit-status (and a status-only
kick-off when the final status lists no file). The source's runner polls
the status pages and settles each load from the receipts: counts by type,
deletions, failing outcomes grouped by their first error issue.

The definition is checked on what it holds and written in one canonical
form; the source is born without a rule, refuses Retry and the connection
test, and keeps no per-line rows. The outbound bulk_submit path is
unchanged.
…ter review

- A definite refusal is marked before it is answered and never becomes a
  load; the runner removes what a failed removal left, and a replay of its
  request_id is sent again.
- The kick-off runs in phases under one deadline from the admission: the
  token in its own share (a failure is destination_auth), a dispatch claim
  right before sending, a 10 s connect timeout (destination_unreachable),
  and a refusal body that stalls is destination_answer_too_large.
- After a status-only kick-off answers 409 the status is read once more.
- Receipt read failures are counted per page, apart from failed polls; the
  lease is renewed and ownership, pause and stop are checked between
  requests, and no runner write lands while the source is paused.
- 501 from the status endpoints is terminal; status pages are capped and
  checked; receipt files are read with an idle timeout.
- Checks count and list the loads listed by their cutoff.
- Token-endpoint failures are logged as a fixed sentence; secrets are
  redacted from the 401/403 issue log before it is cut.
- Manifest traffic feeds the destination observer and the stamping read.
- delivery {} and null source members are refused; a manifest YAML is read
  strictly; uploaded output URLs have no length cap.
- The source view's records are all zeros and its last_received_at is its
  own; monitoring gains last_24h.by_source_type; a manifest never received
  is kickoff not_received.
- A check's count and pages use one strict cutoff on when a manifest load
  was listed, taken under the lock a listing takes.
- Monitoring's files, sent and failing come from the same read as
  by_source_type.
- The kick-off deadline runs from when the load was recorded.
- Receipt read failures are counted per receipt file.
- A request_id replay that loses the listing race answers from the row.
- Forgetting a refused token waits no longer than the kick-off deadline.
- Kick-offs are observed by the destination as outbound requests are.
- A manifest source's 24-hour and daily figures are its receipts only.
- A store read error around the dispatch claim does not answer 500.
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.

Sources: a manifest source (a FHIR Bulk Data manifest, by URL or uploaded, loaded by the FHIR server through $bulk-submit)

1 participant