Skip to content
Open
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
4 changes: 0 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ en:
description: |
Perform airbyte checks on startup and allow airbyte config generation
default: false
airbyte_stream_config_path:
description: |
Path of airbyte stream config file relative to the App root (Rails.root)
default: /terraform/aks/workspace-variables/airbyte_stream_config.json
airbyte_internal_dataset:
description: |
Airbyte internal dataset for service
Expand Down
6 changes: 0 additions & 6 deletions lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ def self.event_debug_filters
{}
end

def self.airbyte_stream_config
JSON.parse(File.read(DfE::Analytics.config.airbyte_stream_config_path)).deep_symbolize_keys
rescue RuntimeError
{}
end

def self.environment
config.environment
end
Expand Down
5 changes: 3 additions & 2 deletions lib/dfe/analytics/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def self.configure(config)
config.airbyte_server_url ||= ENV.fetch('AIRBYTE_SERVER_URL', nil)
config.airbyte_configuration ||=
JSON.parse(ENV.fetch('AIRBYTE_CONFIGURATION', '{}')).transform_keys(&:underscore).symbolize_keys
config.airbyte_stream_config_path ||= nil
Comment thread
mysteryGarlicPress marked this conversation as resolved.

config.async = true if config.async.nil?
Rails.logger.warn("DEPRECATION WARNING: DfE::Analytics airbyte_stream_config_path config option is no longer used; the airbyte stream config is now generated dynamically. You're running v#{DfE::Analytics::VERSION}. To silence this warning, remove airbyte_stream_config_path from your DfE::Analytics initializer.") if config.airbyte_stream_config_path.present?

config.airbyte_stream_config_path = File.join(Rails.root, config.airbyte_stream_config_path) if config.airbyte_stream_config_path.present?
config.async = true if config.async.nil?

return unless config.azure_federated_auth

Expand Down
21 changes: 0 additions & 21 deletions lib/dfe/analytics/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ def self.check!
HEREDOC
end

if DfE::Analytics.airbyte_enabled? && airbyte_conflicting_fields.any?
Comment thread
mysteryGarlicPress marked this conversation as resolved.
errors << <<~HEREDOC
Differences detected between analytics.yml and #{File.basename(DfE::Analytics.config.airbyte_stream_config_path)}!

The following field differences exist. To upgrade the airbyte stream config, run:

SUPPRESS_DFE_ANALYTICS_INIT=1 bundle exec rails dfe:analytics:regenerate_airbyte_stream_config

Field Differences:

#{airbyte_conflicting_fields.to_yaml}
HEREDOC
end

configuration_errors = errors.join("\n\n----------------\n\n")

raise(ConfigurationError, configuration_errors) if errors.any?
Expand Down Expand Up @@ -102,13 +88,6 @@ def self.conflicting_fields
diff_between(allowlist, diff_between(allowlist, blocklist))
end

def self.airbyte_conflicting_fields
diff_between(
allowlist.merge(DfE::Analytics::AirbyteStreamConfig::AIRBYTE_HEARTBEAT_ENTITY_ATTRIBUTES).transform_values(&:uniq),
DfE::Analytics::AirbyteStreamConfig.entity_attributes
)
end

# extract and concatenate the fields associated with an entity in 1 or
# more entity->field lists
def self.extract_entity_attributes_from_lists(entity, *lists)
Expand Down
6 changes: 3 additions & 3 deletions lib/dfe/analytics/tasks/fields.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace :dfe do
)
end

desc 'Generate a new airbyte stream config listing all fields to be send to Bigquery from analytics.yml'
task regenerate_airbyte_stream_config: :environment do
desc 'Generate a debug airbyte stream config listing all fields to be send to Bigquery from analytics.yml. Generates debug_airbyte_config.json.'
task airbyte_stream_config_for_debug: :environment do
File.write(
DfE::Analytics.config.airbyte_stream_config_path,
'debug_airbyte_config.json',
DfE::Analytics::AirbyteStreamConfig.generate_pretty_json_for(DfE::Analytics.allowlist)
Comment thread
mysteryGarlicPress marked this conversation as resolved.
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dfe/analytics/testing/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def with_analytics_config(options)
end

def test_dummy_config
config = DfE::Analytics.config.members.each_with_object({}) { |key, mem| mem[key] = 'dummy_value' }
config = DfE::Analytics.config.members.to_h { |key| [key, 'dummy_value'] }
config[:google_cloud_credentials] = '{ "dummy_value": 1 }'
config[:bigquery_api_json_key] = '{ "dummy_value": 1 }'
config
Expand Down
4 changes: 0 additions & 4 deletions lib/generators/dfe/analytics/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def install
create_file 'config/analytics.yml', { 'shared' => {} }.to_yaml
create_file 'config/analytics_hidden_pii.yml', { 'shared' => {} }.to_yaml
create_file 'config/analytics_blocklist.yml', { 'shared' => {} }.to_yaml
create_file(
DfE::Analytics.config.airbyte_stream_config_path,
DfE::Analytics::AirbyteStreamConfig.generate_pretty_json_for(table1: %w[id field1 field2])
)
end

private
Expand Down
9 changes: 0 additions & 9 deletions spec/dfe/analytics/airbyte_stream_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@
end
end

describe '.generate_pretty_json_for' do
let(:entity_attributes) { { users: %w[id name] } }

it 'returns a pretty JSON version of generate_for' do
expect(described_class.generate_pretty_json_for(entity_attributes))
.to eq(JSON.pretty_generate(described_class.generate_for(entity_attributes)))
end
end

describe '.entity_attributes' do
context 'when config is empty' do
before { allow(DfE::Analytics).to receive(:airbyte_stream_config).and_return({}) }
Expand Down
20 changes: 18 additions & 2 deletions spec/dfe/analytics/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,28 @@

context 'when airbyte_stream_config_path is set' do
before do
allow(Rails.logger).to receive(:warn)
config.airbyte_stream_config_path = 'config/airbyte.json'
described_class.configure(config)
end

it 'resolves the full path from Rails.root' do
expect(config.airbyte_stream_config_path).to eq(Rails.root.join('config/airbyte.json').to_s)
it 'still stores the value' do
expect(config.airbyte_stream_config_path).to eq('config/airbyte.json')
end

it 'logs a deprecation warning' do
expect(Rails.logger).to have_received(:warn).with(/DEPRECATION WARNING/)
end
end

context 'when airbyte_stream_config_path is not set' do
before do
allow(Rails.logger).to receive(:warn)
described_class.configure(config)
end

it 'does not log a deprecation warning' do
expect(Rails.logger).not_to have_received(:warn).with(/DEPRECATION WARNING/)
end
end
end
Expand Down
28 changes: 0 additions & 28 deletions spec/dfe/analytics/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,6 @@
end
end

describe '.airbyte_conflicting_fields' do
context 'when fields conflict' do
let(:existing_allowlist) { { Candidate.table_name.to_sym => %w[email_address id first_name dob] } }
let(:existing_airbytelist) { { Candidate.table_name.to_sym => %w[email_address first_name] } }

it 'returns the conflicting fields' do
conflicts = described_class.airbyte_conflicting_fields
expect(conflicts[Candidate.table_name.to_sym]).to eq(%w[id dob])
end

describe '.check!' do
it 'raises an error' do
expect { DfE::Analytics::Fields.check! }.to raise_error(DfE::Analytics::ConfigurationError, /Conflict detected/)
end
end
end

context 'when there are no conflicts' do
let(:existing_allowlist) { { Candidate.table_name.to_sym => %w[id email_address] } }
let(:existing_airbytelist) { { Candidate.table_name.to_sym => %w[email_address id] } }

it 'returns nothing' do
conflicts = described_class.airbyte_conflicting_fields
expect(conflicts).to be_empty
end
end
end

describe '.generate_blocklist' do
it 'returns all the fields in the model that aren’t in the allowlist' do
fields = described_class.generate_blocklist[Candidate.table_name.to_sym]
Expand Down
8 changes: 0 additions & 8 deletions spec/dfe/analytics/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@
{ 'shared' => {} }.to_yaml
)
end
it 'creates the airbyte stream config file' do
generator.install

expect(generator).to have_received(:create_file).with(
airbyte_stream_config_path,
generated_stream_config
)
end

it 'uses the generated config options in the initializer' do
generator.install
Expand Down
66 changes: 0 additions & 66 deletions spec/dfe/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,70 +427,4 @@
end
end
end

describe '.airbyte_stream_config' do
let(:mock_path) { '/fake/path/airbyte_stream_config.json' }

let(:config_double) do
instance_double(
'DfE::Analytics.config',
airbyte_stream_config_path: mock_path
)
end

before do
allow(DfE::Analytics).to receive(:config).and_return(config_double)
end

context 'when the JSON file is valid' do
let(:json_data) do
{
configurations: {
streams: [
{
name: 'teachers',
syncMode: 'incremental_append',
selectedFields: [{ fieldPath: ['id'] }]
}
]
}
}.to_json
end

before do
allow(File).to receive(:read).with(mock_path).and_return(json_data)
end

it 'returns the parsed JSON with symbolized keys' do
result = described_class.airbyte_stream_config

expect(result).to eq(
configurations: {
streams: [
{
name: 'teachers',
syncMode: 'incremental_append',
selectedFields: [{ fieldPath: ['id'] }]
}
]
}
)

# verify keys are deep symbolized
expect(result.keys).to all(be_a(Symbol))
expect(result[:configurations][:streams].first[:name]).to eq('teachers')
expect(result[:configurations][:streams].first[:selectedFields].first[:fieldPath]).to eq(['id'])
end
end

context 'when File.read raises a RuntimeError' do
before do
allow(File).to receive(:read).with(mock_path).and_raise(RuntimeError)
end

it 'returns an empty hash' do
expect(described_class.airbyte_stream_config).to eq({})
end
end
end
end