Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Retry Tracking and Permissions for Tables in Hasura #663

Merged
merged 19 commits into from
Apr 18, 2024

Conversation

darunrs
Copy link
Collaborator

@darunrs darunrs commented Apr 15, 2024

Logs Table and Metadata Table are necessary for important functions of QueryApi. Hasura often invisibly fails to track tables and add permissions. These operations need to be successful, so I added a check which verifies tracking and permissions are correct, and reattempts them if not. When successful, the result is cached. In a successful case, the expensive hasura calls (getTableNames and getTrackedTablesWithPermissions) are done at most twice.

I also combined the conditional provisioning functions since they are verified to work already.

@darunrs
Copy link
Collaborator Author

darunrs commented Apr 15, 2024

Manual testing performed:

  1. Logs and metadata created and tracked, but metadata lacking permissions.
  2. Neither created
  3. metadata created but not tracked
  4. logs created but not tracked
  5. everything provisioned, tracked, and with permissions

I ran all with multiple blocks to confirm caching behavior works correctly. None ran more than twice.

return;
}
const metadataTable = '__metadata';
async getTrackedTablesWithPermissions (indexerConfig: IndexerConfig): Promise<TrackedTablePermissions> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Transforms the returned list into a map to make some checks a bit easier.

@darunrs darunrs force-pushed the track-logs-metadata-tables branch 2 times, most recently from 41f7af9 to 0620567 Compare April 16, 2024 00:51
@darunrs darunrs marked this pull request as ready for review April 16, 2024 00:53
@darunrs darunrs requested a review from a team as a code owner April 16, 2024 00:53
@darunrs darunrs linked an issue Apr 16, 2024 that may be closed by this pull request
runner/src/hasura-client/hasura-client.ts Outdated Show resolved Hide resolved
runner/src/hasura-client/hasura-client.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Show resolved Hide resolved
await this.trackTables(indexerConfig.schemaName(), needsTrackingTables, indexerConfig.databaseName());
}
if (needsPermissionsTables.length > 0) {
await this.addPermissionsToTables(indexerConfig, needsPermissionsTables, permissionsToAdd);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this fail if a table has some of the permissions, i.e. just select/insert, and not the others? This will attempt to set them again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not cover partial failures of adding permissions. The current code just expects it to be a all or none. I did configure the code to accept different lists of permissions (even though we currently set all of them). I felt like that was something we can potentially cover in the future rather than now.

runner/src/provisioner/provisioner.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.ts Show resolved Hide resolved
@darunrs darunrs force-pushed the track-logs-metadata-tables branch from d0f7fb2 to 2cb8da0 Compare April 17, 2024 23:11
@darunrs darunrs force-pushed the track-logs-metadata-tables branch from 15d4b4a to 3907fef Compare April 18, 2024 00:38
@darunrs darunrs requested a review from morgsmccauley April 18, 2024 01:02
runner/src/provisioner/provisioner.ts Outdated Show resolved Hide resolved
runner/src/provisioner/provisioner.test.ts Show resolved Hide resolved
await this.deps.provisioner.provisionLogsIfNeeded(this.indexerConfig);
await this.deps.provisioner.provisionMetadataIfNeeded(this.indexerConfig);
await this.deps.provisioner.provisionLogsAndMetadataIfNeeded(this.indexerConfig);
await this.deps.provisioner.ensureConsistentHasuraState(this.indexerConfig);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eventually I think we should put this within provisionUserApi() and have it retry, but is probably fine living here for now

@darunrs darunrs merged commit bccb8b9 into main Apr 18, 2024
3 checks passed
@darunrs darunrs deleted the track-logs-metadata-tables branch April 18, 2024 19:22
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.

Retry Tracking and Permissions for New Logs/Metadata tables
2 participants