-
Notifications
You must be signed in to change notification settings - Fork 9
Add airbyte deployment tasks #216
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
645e98e
Make airbyte internal dataset configurable
asatwal 00b3a7d
Add rake task, jobs and service classes to apply BigQuery policy tags
asatwal fd7602b
Appease rubocop
asatwal 02e31ff
Add support for Airbyte deployment task and supporting classes/services
asatwal 88f47ce
Restructure jobs
asatwal 38a60f4
Add info log messages to AirbyteDeployJob
asatwal b56e9e9
Services::Airbyte::ApiServer - Improve error handling and refactor al…
asatwal 3aa0931
Add customer Http error class to ApiServer and handle specific error …
asatwal 5788ad0
WIP - Tidy up and update to correct response for job list
asatwal 3ad0e8e
Fix parameters to BigQueryApi method apply_policy_tags
asatwal a496950
Fix airbyte deploy job and stop apply policy tagging for final tables…
asatwal e7f0ca1
Fix incorrect spec name
asatwal fa0a680
Add documentation for airbyte deplyment tasks
asatwal dbccaad
Disable real sleep in WaitForSync spec
asatwal 588183a
Action review comments
asatwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'dfe/analytics/jobs/analytics_job' | ||
| require 'dfe/analytics/jobs/airbyte_deploy_job' | ||
| require 'dfe/analytics/jobs/big_query_apply_policy_tags_job' | ||
| require 'dfe/analytics/jobs/entity_table_check_job' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module DfE | ||
| module Analytics | ||
| module Jobs | ||
| # Orchestration job for airbyte deployment | ||
| class AirbyteDeployJob < AnalyticsJob | ||
| queue_as :default | ||
| # No retries – discard on any StandardError | ||
| discard_on StandardError | ||
|
|
||
| def perform | ||
| # Wait for any pending migrations to finish | ||
| DfE::Analytics::Services::WaitForMigrations.call | ||
|
|
||
| Rails.logger.info('Finished WaitForMigrations') | ||
|
|
||
| access_token = ::Services::Airbyte::AccessToken.call | ||
| connection_id, source_id = ::Services::Airbyte::ConnectionList.call(access_token:) | ||
|
|
||
| # Refresh schema | ||
| ::Services::Airbyte::ConnectionRefresh.call(access_token:, connection_id:, source_id:) | ||
|
|
||
| Rails.logger.info('Finished ConnectionRefresh') | ||
|
|
||
| # Check if a sync job is already running | ||
| last_job = ::Services::Airbyte::JobLast.call(access_token:, connection_id:) | ||
| status = last_job&.dig('job', 'status') | ||
| job_id = last_job&.dig('job', 'id') | ||
|
|
||
| Rails.logger.info("JobLast status: #{status} id: #{job_id}") | ||
|
|
||
| job_id = ::Services::Airbyte::StartSync.call(access_token:, connection_id:) if status != 'running' | ||
|
|
||
| # Wait for the job (existing or new) to finish | ||
| ::Services::Airbyte::WaitForSync.call(access_token:, connection_id:, job_id:) | ||
|
|
||
| Rails.logger.info('Finished WaitForSync') | ||
|
|
||
| # Trigger policy tagging for final tables | ||
| DfE::Analytics::Services::ApplyAirbyteFinalTablesPolicyTags.call | ||
|
|
||
| Rails.logger.info('Finished AirbyteDeployJob') | ||
| rescue StandardError => e | ||
| Rails.logger.error(e.message) | ||
| raise "AirbyteDeployJob failed: #{e.message}" | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| module DfE | ||
| module Analytics | ||
| module Jobs | ||
| # Base class for all DfE::Analytics jobs | ||
| class AnalyticsJob < ActiveJob::Base | ||
| queue_as { DfE::Analytics.config.queue } | ||
|
|
||
| wait_option = Rails::VERSION::STRING >= '7.1' ? :polynomially_longer : :exponentially_longer | ||
| retry_on StandardError, wait: wait_option, attempts: 5 | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module DfE | ||
| module Analytics | ||
| module Jobs | ||
| # Applies BigQuery hidden policy tags to PII fields in the airbyte tables | ||
| class BigQueryApplyPolicyTagsJob < AnalyticsJob | ||
| def self.do(dataset:, tables:, policy_tag:, delay_in_minutes: 0) | ||
| if delay_in_minutes.zero? | ||
| perform_later(dataset, tables, policy_tag) | ||
| else | ||
| time_to_run = Time.zone.now + delay_in_minutes.minutes | ||
|
|
||
| set(wait_until: time_to_run).perform_later(dataset, tables, policy_tag) | ||
| end | ||
| end | ||
|
|
||
| def perform(dataset, tables, policy_tag) | ||
| unless DfE::Analytics.airbyte_enabled? | ||
| Rails.logger.warn('DfE::Analytics::BigQueryApplyPolicyTags.perform called but airbyte is disabled. Please check DfE::Analytics.airbyte_enabled? before applying policy tags in BigQuery') | ||
| return | ||
| end | ||
|
|
||
| DfE::Analytics::BigQueryApi.apply_policy_tags(dataset, tables, policy_tag) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'active_support/values/time_zone' | ||
|
|
||
| module DfE | ||
| module Analytics | ||
| module Jobs | ||
| # To ensure BigQuery is in sync with the database | ||
| class EntityTableCheckJob < AnalyticsJob | ||
| def perform | ||
| return unless DfE::Analytics.enabled? && DfE::Analytics.entity_table_checks_enabled? | ||
|
|
||
| entity_tag = Time.now.strftime('%Y%m%d%H%M%S') | ||
| DfE::Analytics.entities_for_analytics.each do |entity_name| | ||
| DfE::Analytics::Services::EntityTableChecks.call(entity_name: entity_name, entity_type: 'entity_table_check', entity_tag: entity_tag) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'dfe/analytics/shared/service_pattern' | ||
|
|
||
| require 'dfe/analytics/services/apply_airbyte_final_tables_policy_tags' | ||
| require 'dfe/analytics/services/apply_airbyte_internal_tables_policy_tags' | ||
| require 'dfe/analytics/services/checksum_calculator' | ||
| require 'dfe/analytics/services/entity_table_checks' | ||
| require 'dfe/analytics/services/generic_checksum_calculator' | ||
| require 'dfe/analytics/services/postgres_checksum_calculator' | ||
| require 'dfe/analytics/services/wait_for_migrations' |
25 changes: 25 additions & 0 deletions
25
lib/dfe/analytics/services/apply_airbyte_final_tables_policy_tags.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module DfE | ||
| module Analytics | ||
| module Services | ||
| # Apply hidden policy tags to the final airbyte table columns in the hidden pii config | ||
| class ApplyAirbyteFinalTablesPolicyTags | ||
| include ServicePattern | ||
|
|
||
| def initialize(delay_in_minutes: 0) | ||
| @delay_in_minutes = delay_in_minutes | ||
| end | ||
|
|
||
| def call | ||
| DfE::Analytics::Jobs::BigQueryApplyPolicyTagsJob.do( | ||
| delay_in_minutes: @delay_in_minutes, | ||
| dataset: DfE::Analytics.config.bigquery_airbyte_dataset, | ||
| tables: DfE::Analytics.hidden_pii, | ||
| policy_tag: DfE::Analytics.config.bigquery_hidden_policy_tag | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.