Skip to content

feat(pull): warn about the aspects pull leaves out - #561

Open
merr1988 wants to merge 1 commit into
feat/init/default-aspectsfrom
feat/pull/warn-left-out-aspects
Open

merr1988 wants to merge 1 commit into
feat/init/default-aspectsfrom
feat/pull/warn-left-out-aspects

Conversation

@merr1988

Copy link
Copy Markdown
Collaborator

Part 2 of b/576454554. Built on #560; I'll rebase onto main once it merges.

Problem

Pull fetched each entry with only the aspect types catalog.yaml lists and its entry type requires, so it could not say what it left out. With a catalog.yaml from before #560, a knowledge base document pulls with an empty body and kcmd is silent.

Change

  • Pull fetches each entry with every aspect (lookupEntry(..., 'FULL')), keeps the aspects of the types it knows, and warns once per aspect type it left out:
    Warning: pull left out aspect type 'X' on N entries; list it under snapshot.aspects in catalog.yaml to pull it.
    What pull stores is unchanged.
  • CatalogSource.systemAspects: aspects the service writes beyond the required ones, left out without a warning. BigQuery dataset: bigquery-policy and usage. These are what a sample of 27 real BigQuery tables carry besides the required bigquery-table, schema and storage.
  • lookupEntry takes 'FULL' for every aspect; a string list still means those types, and nothing still means none.

Tests

  • New pull_left_out scenario: two entries with an unlisted aspect and one with overview, pulled with a catalog.yaml that lists none. The aspects are not stored, and pull warns once per type with the entry count.
  • pull_bq: a table with usage and bigquery-policy pulls without them and with no warning.
  • The scenario harness records console.warn and checks assert.warnings.
  • lookupEntry sends the BASIC, CUSTOM or FULL view as asked.
  • Mutation checks: dropping usage from the BigQuery list fails pull_bq; storing every fetched aspect fails pull_bq and pull_left_out; removing the warning fails pull_left_out.
  • tsc clean; scenarios 24, layouts 2, gcp 12, semantic 2068, tool 395, all pass.

Pull fetched each entry with only the aspect types catalog.yaml lists and
its entry type requires, so it could not tell an author what it left out.
A catalog.yaml written before init listed any aspects pulls a knowledge
base document with an empty body and says nothing.

Pull now fetches each entry with every aspect (the FULL view), keeps the
aspects of the types it knows, and warns once for each aspect type it
left out, naming the number of entries and how to pull it. What it stores
is unchanged.

Each scope names the aspects the service writes beyond the required ones
(CatalogSource.systemAspects), which pull leaves out without a warning.
For a BigQuery dataset these are bigquery-policy and usage, the aspects
BigQuery writes on a table besides the ones its type requires.

lookupEntry takes 'FULL' to return every aspect.

Bug: b/576454554
@merr1988
merr1988 requested a review from feixufeixu October 23, 2026 23:42

@feixufeixu feixufeixu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving with two required fixes. In production a FULL read returns data only for the aspects an entry's type requires. So this pull stops storing the overview that #560 lists, and the new warning never prints. My sync.ts comment gives the fix, and my mocks.ts comment covers why the tests still pass. The other two comments are optional.

Comment on lines 68 to +69
const res = await this._catalog.lookupEntry(nameParts[1], nameParts[3], entry.name,
aspectTypes);
'FULL');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Required. In production a FULL read gives data only to the aspects the entry type requires. Every other aspect comes back as {}, and _fixEntry drops it at dataplex.ts:451. So pull stores no listed aspect beyond the required ones. A knowledge base document pulls with an empty body again, and the warning below never prints.

I'd keep #560's read here, with [...aspectTypes.keys()] as the last argument, and store its result as before. For the warning, I'd add a CatalogClient method that reads the entry through _get with view: 'FULL'. It returns the distinct aspect types of the entry's keys as project.location.type. It drops the @path part of each key and resolves project numbers with crm.fixProject. A type is left out when it is in that list, the first read did not return it, aspectTypes does not have it, and it is not a system aspect. lookupEntry then goes back to its #560 version. This costs one more read per entry. The change also keeps a listed or required aspect when Resource Manager cannot resolve the project number of its type. Line 82 now drops such an aspect and warns about it. view=ALL would not work. Production returns at most 100 aspects for it, so an entry with more can lose a listed aspect.

Comment on lines +95 to +98
// As Dataplex does: every aspect for 'FULL', else only the aspects of the
// requested types, none when no type is requested.
const kept = Object.entries(entry.aspects ?? {})
.filter(([, a]) => aspects?.includes(a.aspectType ?? ''));
.filter(([, a]) => aspects === 'FULL' || aspects?.includes(a.aspectType ?? ''));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Required. This mock answers FULL with every aspect and its data. Production gives data only to the required aspects. That is why pull_left_out and init_kb_pull_overview pass here, while a real pull prints no warning and loses a listed overview. If you keep a FULL read through lookupEntry, please make this mock match production: it lists every aspect key on the entry, and only the required aspects carry data. With my sync.ts change instead, this filter goes back to its #560 version, and the mock of the new method returns every aspect type on the entry.

Comment on lines +17 to +21
// BigQuery writes these on a table besides the ones its type requires.
readonly systemAspects = [
'dataplex-types.global.bigquery-policy',
'dataplex-types.global.usage',
];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional. Dataplex data profile and data quality scans also write aspects on BigQuery tables when they publish results. For example, bigquery-public-data.stackoverflow.posts_questions carries data-profile. Without them in this list, the warning tells the author to pull aspects that push would then send back.

Suggested change
// BigQuery writes these on a table besides the ones its type requires.
readonly systemAspects = [
'dataplex-types.global.bigquery-policy',
'dataplex-types.global.usage',
];
// BigQuery and Dataplex data scans write these on a table besides the ones
// its type requires.
readonly systemAspects = [
'dataplex-types.global.bigquery-policy',
'dataplex-types.global.data-profile',
'dataplex-types.global.data-quality-scorecard',
'dataplex-types.global.usage',
];

// Dataplex keeps an aspect that aspectKeys names and the body leaves out
// unless deleteMissingAspects is set, so a caller that means to remove one has
// to send it.
describe('CatalogClient.lookupEntry', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional. The comment on lines 249-251 describes the updateEntry tests further down. I'd put this block, or whatever test replaces it after the sync.ts change, above line 249, so the comment sits right above those tests again.

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.

2 participants