Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/dfe/analytics/big_query_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ class BigQueryApi
RETRY_INTERVAL_MULTIPLIER = 2
BIGQUERY_MANDATORY_CONFIG =
%i[bigquery_project_id bigquery_table_name bigquery_dataset azure_client_id azure_token_path azure_scope gcp_scope google_cloud_credentials].freeze
BIGQUERY_AIRBYTE_MANDATORY_CONFIG = %i[bigquery_airbyte_dataset].freeze

def self.client
@client ||= begin
DfE::Analytics::Config.check_missing_config!(BIGQUERY_MANDATORY_CONFIG)
DfE::Analytics::Config.check_missing_config!(BIGQUERY_AIRBYTE_MANDATORY_CONFIG) if DfE::Analytics.airbyte_enabled?

Google::Apis::BigqueryV2::BigqueryService.new
end
Expand Down Expand Up @@ -79,7 +77,7 @@ def self.apply_policy_tags(dataset, tables, policy_tags)
table_name.to_s
)
rescue Google::Apis::ClientError => e
error_message = "DfE::Analytics Failed to retrieve table: #{table_name}: #{e.message}"
error_message = "DfE::Analytics Failed to retrieve table: #{dataset}.#{table_name}: #{e.message}"
Rails.logger.error(error_message)
raise PolicyTagError, error_message
end
Expand Down Expand Up @@ -111,7 +109,7 @@ def self.apply_policy_tags(dataset, tables, policy_tags)
fields: 'schema'
)
rescue Google::Apis::ClientError => e
error_message = "DfE::Analytics Failed to update table: #{table_name}: #{e.message}"
error_message = "DfE::Analytics Failed to update table: #{dataset}.#{table_name}: #{e.message}"
Rails.logger.error(error_message)
raise PolicyTagError, error_message
end
Expand Down
16 changes: 2 additions & 14 deletions spec/dfe/analytics/big_query_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,16 @@
end
end

it 'raises a configuration error if airbyte is enabled and airbyte config is missing' do
with_analytics_config(test_dummy_config.merge(bigquery_airbyte_dataset: nil)) do
allow(DfE::Analytics::Config).to receive(:airbyte_enabled?).and_return(true)

expect do
described_class.client
end.to raise_error(DfE::Analytics::Config::ConfigurationError)
end
end

it 'initializes and returns the BigQuery client with authorization' do
with_analytics_config(test_dummy_config.merge(bigquery_airbyte_dataset: 'airbyte_dataset')) do
allow(DfE::Analytics::Config).to receive(:airbyte_enabled?).and_return(true)

with_analytics_config(test_dummy_config) do
expect(described_class.client).to eq(client)
end
end
end

describe '.insert' do
subject(:insert) do
with_analytics_config(test_dummy_config.merge(bigquery_airbyte_dataset: 'airbyte_dataset')) do
with_analytics_config(test_dummy_config) do
described_class.insert([event.as_json])
end
end
Expand Down
Loading