feat(ingest/github-documents): map OKF frontmatter to an okfProperties aspect and native metadata
Merged
SH
1mo ago+5285+5285+0123456789012345678901234567890123456789-41-41-01234567890123456789
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:
- A format-specific aspect (
okfProperties, namespacecom.linkedin.okf), intended to be shared by other entity types later (data products, datasets). - 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
rawmeans not a concept. Whenrawis present,bundle,conceptIdandtypeare always set. enable_okfdefaults totrue, 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
okfPropertiesaspect ondocument. It stores only what is OKF-specific:bundle:location(the bundle's URI, any git host or archive),rootPath(.at the location's root) andokfVersion. Location and root path are searchable, so references resolve within a bundle.conceptId, the bundle-relative path (OKF's concept id, §2), anddeclaredId, a producer's ownidkey, unique only within its bundle. On Search V3 both feed the sharedidlabel (likeDocumentSource.externalId), so a search forguide:maufinds the page; on V2 they are filterable but not in default search.typeandstatus(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 servesfrontmatteras JSON parsed fromrawwhen 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.mddeclaresokf_version(§8, §12), or a root listed inokf_bundle_roots. Markdown with atype:key elsewhere (Hugo and similar) is imported exactly as before.index.mdandlog.mdare reserved (§3.1) and imported verbatim. Index files with frontmatter but nookf_versionare 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 neutralokfProperties, emptiessubTypesif 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-restsink) the source reads the server's entity registry once per run; ifokfPropertiesis 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_hashhashes exactly the text stored indocumentInfo(the body for a concept), the contract Cloud sync-back relies on. A newsource_content_hashcovers 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. ExamplesReportno longer crashes on an emptysubTypesaspect (one-line fix iningestion/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 andfrontmatterparsed fromraw.- 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; turningenable_okfoff cleared the aspect (GraphQL returns null,okfTypefilter 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