Area: Deployment
Sub-Area: Multi-Environment Setup
Applies to: OSS + Cloud
Issue
You run more than one DataHub environment, such as development, staging and production. You want shared metadata, such as the business glossary, to stay the same in every environment, while each environment keeps its own datasets.
You Might Be Asking
- How do I keep a glossary in sync across environments?
- Why does
from datahub.emitter.mce_builder import make_glossary_term_urnfail? - Can I keep one DataHub instance and separate environments another way?
- Can I use
datahub getanddatahub put --serverto copy metadata between instances? - How do I give different groups access to different environments?
Cause
A recipe has exactly one source and at most one sink. To write the same metadata to several instances, you run one recipe per target. Each recipe uses a datahub-rest sink with that instance's GMS URL and token.
Hand-written glossary scripts often fail for two reasons:
-
datahub.emitter.mce_builderhas nomake_glossary_term_urn, so the import raises anImportError. The glossary term helper in that module ismake_term_urn. A function namedmake_glossary_term_urnexists only in thedatahub.ingestion.source.metadata.business_glossarymodule. -
datahub puthas no--serveroption and ignores unknown options. See the last section.
Solution
Glossary: use the built-in glossary source
The datahub-business-glossary ingestion source loads a glossary YAML file into any DataHub instance with datahub ingest. Keep the YAML file in Git. Apply the same file to each environment, one recipe per target. Run it against dev first, then staging, then production.
source:
type: datahub-business-glossary
config:
file: /path/to/business_glossary.yml
enable_auto_id: true
sink:
type: datahub-rest
config:
server: <GMS URL of this environment>
token: <token for this environment>
Run it with datahub ingest -c <recipe file>. Set enable_auto_id: true, as the source docs recommend. Do not write your own emitter script for glossary terms. See the business glossary source and Managing Glossary with Git.
Domains
A transformer can assign a domain only if the domain already exists on the target instance. Create the domains in each environment first. In the UI, start from the Domains tab. See Domains.
If you assign domains with the pattern domain transformer, use the domain_pattern key with rules. Rule keys match from the start of the string. The older pattern_add_dataset_domain transformer is deprecated in favor of pattern_add_domain. See dataset transformers.
Separate environments inside one instance: platform instances
You can use one DataHub instance and separate environments with platform_instance. The instance name prefixes the dataset name in the URN, as in urn:li:dataset:(urn:li:dataPlatform:<platform>,<instance>.<name>,ENV). Keep the instance name stable. See Platform Instances.
source:
type: snowflake
config:
account_id: xy12345.us-east-2.aws
platform_instance: dev
The Snowflake key is account_id, not account.
Access by environment
You manage policies as entities in DataHub. You do not load them from files in a repository. In the UI, go to Settings > Permissions > Policies. You need the Manage Policies privilege to see that tab. You can also use the createPolicy, updatePolicy and deletePolicy GraphQL mutations. See Managing policies.
For createPolicy:
-
actorsneeds the booleansresourceOwners,allUsersandallGroups. You can also passusersandgroupslists, withcorpGroupURNs for groups. -
resources.filter.criteriais a list of{field, condition, values}. Each criterion needs acondition, such asEQUALS. -
VIEW_ENTITY_PAGEandEDIT_ENTITYare valid privileges.
Policies only grant access. To stop users from seeing an environment, remove the grant and use view-based access control:
- On OSS, set
VIEW_AUTHORIZATION_ENABLED=trueon GMS (defaultfalse). This gates entity pages. It does not filter search results at query time. - On DataHub Cloud, use Search Access Controls, which filter at query time. Your DataHub Cloud administrator enables it.
- Remove the default policies that grant View Entity to all users.
- Users with the Admin, Editor or Reader role see all entities regardless of view policies.
See Policies and Search Access Controls.
Do not use datahub get and datahub put to promote metadata
datahub put --server <url> does not send anything to that URL.
-
datahub getfetches one exact URN and prints JSON to stdout. It takes--urn,-a(repeatable) and--details. -
datahub putwrites one aspect to one entity.--urn,-aand-dare all required:datahub put --urn <urn> -a <aspectName> -d <file>.-dis a plain file path, or-for stdin. It has no@fileform and no-foption. -
puthas no--serveroption. It ignores unknown options without an error, so a--serverflag is dropped. The write goes to the server inDATAHUB_GMS_URLor~/.datahubenv. SetDATAHUB_GMS_URLandDATAHUB_GMS_TOKENfor the target before you run it. -
putsends the whole aspect as an upsert, which replaces the aspect. It cannot export anything and does not take wildcard URNs. To change one field, use a patch. See Patch.
For glossaries, use the glossary source above.
To copy a whole self-hosted instance, use the datahub ingestion source. It needs direct access to the source instance's database, Kafka broker and schema registry. It writes to the sink you configure, such as datahub-rest with the destination server and token, or a file. The urn_pattern allow and deny regexes control which URNs it reads.
On DataHub Cloud you have no database, Kafka or schema registry access. To copy a whole instance, contact DataHub Support.