feat(ingest/github-documents): map OKF frontmatter to an okfProperties aspect and native metadata

Merged
SH
1mo ago
+5285-41

Context repos keep curated context in git as Open Knowledge Format (OKF) 0.2 bundles: markdown concepts with a YAML frontmatter block (type, title, tags, ...). Today the GitHub documents source imports such a file's raw text, so the YAML shows up in the document body and none of it reaches DataHub's own fields.

Review guide

Start with the model (metadata-models/.../com/linkedin/okf/*.pdl): it is the part that is hard to change after release. Decisions for maintainers:

  1. A format-specific aspect (okfProperties, namespace com.linkedin.okf), intended to be shared by other entity types later (data products, datasets).
  2. All top-level fields are optional. Ingestion cannot delete a non-key aspect, so "this document is no longer an OKF concept" is written as a neutral aspect: no raw means not a concept. When raw is present, bundle, conceptId and type are always set.
  3. enable_okf defaults to true, but only files inside an OKF bundle are affected, and the source turns OKF off for a run when the target server does not support the aspect.

Then okf_*.py and github_documents_source.py, then tests. About two thirds of the added lines are tests, fixtures and the golden file.

What changes

  • New okfProperties aspect on document. It stores only what is OKF-specific:
    • bundle: location (the bundle's URI, any git host or archive), rootPath (. at the location's root) and okfVersion. Location and root path are searchable, so references resolve within a bundle.
    • conceptId, the bundle-relative path (OKF's concept id, §2), and declaredId, a producer's own id key, unique only within its bundle. On Search V3 both feed the shared id label (like DocumentSource.externalId), so a search for guide:mau finds the page; on V2 they are filterable but not in default search.
    • type and status (filters), description, staleAfter, generated, verified (§5.2, §5.4, §5.5).
    • raw: the original YAML block verbatim, the only stored copy of the frontmatter and the base for write-back. GraphQL also serves frontmatter as JSON parsed from raw when read.
    • revision (branch, commit, blob SHA): the merge base for write-back. The file path is derived from the bundle and concept id.
  • Only files inside an OKF bundle are concepts. A bundle root is a directory whose index.md declares okf_version (§8, §12), or a root listed in okf_bundle_roots. Markdown with a type: key elsewhere (Hugo and similar) is imported exactly as before. index.md and log.md are reserved (§3.1) and imported verbatim. Index files with frontmatter but no okf_version are reported.
  • Mapping (one versioned module): title → title, type → subtype, owners → ownership (users or groups), tags → tags, glossary_terms → glossary terms. The body is imported without the block.
  • Re-import patches, it does not overwrite. Owners, tags and terms are written as patches with MetadataAttribution (origin: okf, bundle, concept, commit, key, mapping version). A re-import adds what the file lists and removes only values the file added before; values added in DataHub are kept. When the file lists a value DataHub also holds without attribution (for example after a sync-back write merges), the file takes it over (owners only in the same role), so a later removal in git removes it from DataHub too. Values attributed to other sources are left alone. Without a graph connection it only adds.
  • Clearing. When a file stops being a concept (malformed frontmatter, no type, outside a bundle, enable_okf: false), the source writes the neutral okfProperties, empties subTypes if it was the OKF type, and removes the values the file added. The source never emits a DELETE.
  • Server capability. With a graph (a datahub-rest sink) the source reads the server's entity registry once per run; if okfProperties is unsupported, OKF handling is off for the run with a warning. Without a graph it emits as configured. If the registry can't be read, it emits and warns.
  • Content hashes. content_hash hashes exactly the text stored in documentInfo (the body for a concept), the contract Cloud sync-back relies on. A new source_content_hash covers the whole file, bundle metadata and the mapping version (bundle files only) and drives skip-if-unchanged. A concept is not skipped on a match with the last sync-back write (last_exported_content_hash), so a merged write is re-imported and re-attributed; plain documents keep that skip. Every file re-imports once after upgrade.
  • Safety. Frontmatter with YAML anchors or aliases, or over 64 KiB, is rejected and imported as plain text. Each run reads the tree and file contents at one commit SHA.
  • GraphQL: read-only Document.okfProperties.
  • ExamplesReport no longer crashes on an empty subTypes aspect (one-line fix in ingestion/api/report.py).
  • Docs: connector page section and a note under Unreleased in breaking-changes.md.

Testing

  • Unit tests (224) for bundle discovery, reserved files, parsing and its guards, lifecycle and trust fields, mapping, attribution, patch reconciliation, clearing, both hashes, the capability gate, and a guard that the source never emits a DELETE.
  • Golden-file integration test over a mocked bundle.
  • Smoke test (smoke-test/tests/e2e/knowledge/test_okf_reimport.py): re-import keeps an owner and tag added in DataHub, creates no duplicates, and removes only the owner the file dropped. Passes locally.
  • DocumentMapperTest (37), including the neutral aspect and frontmatter parsed from raw.
  • Manual, against a clean local build with a real context repo (112 files, 96 concepts): 0 parse errors; search for a declared id ranks the page first; bundle-scoped filters return exactly that page; hash(stored text) == content_hash, so sync-back sees imported pages as unchanged; turning enable_okf off cleared the aspect (GraphQL returns null, okfType filter 0 documents), the subtype and the file's tags while keeping a DataHub-added tag; a second run changed nothing; turning it back on restored everything.

Not in this PR

Writing DataHub edits back to the file (DataHub Cloud), UI for okfProperties, resource (§4.1) mapping, and other entity types.

  • Tests added
  • Docs updated
  • Entry in breaking-changes.md

🤖 Generated with Claude Code

https://claude.ai/code/session_01TtKYqnecg5Y6bvqLBgJjgr