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

HOTT-4931 Drop CDS Env Var #1716

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

HWallenberg
Copy link
Contributor

Jira link

https://transformuk.atlassian.net/browse/HOTT-4931

What?

I have removed:

  • CDS Env Var from Taric Importer and Rollback, Apply, Download Workers as they will use uk? var instead

  • CDS Env Var from Terraform and other config files as it is now redundant

I have updated:

  • taric_importer as it wasn't recognising filenames in the correct format (YYYY-MM-DD) and file checks were just defaulting due to the erroneous env var use_cds. It will create_update_entry even if there isn't a filename in the correct format using today's date. This is up for discussion as the logic is different for CDS_Importer.

  • cds_synchronizer>Rollback as removal of use_cds env var meant that rollback tests failed when running as a uk worker.
    Specifically test 'it performs a rollback' in spec/controllers/api/admin/rollbacks_controller_uk_spec.rb. It looks like there was never any proper unit tests for this controller as a uk worker. It failed because the number of measures stayed at one instead of zero. So cds_Synchronizer will rollback based on date rather than updates relating to a filename similar to the Taric_synchronizer rollback. Again this is up for discussion and was altered due to uk worker tests failing.

  • the specs connected with this process as tests were failing (see below for detail)

Why?

I am doing this because:

  • The use_cds variable is redundant. It was used when uk and xi both used the Taric download service. Following a transition uk now uses the CDS service and xi uses Taric. So logic changed to use if the worker is uk?CDS Synchronizer runs so and won't run as a xi worker. A xi worker will use the Taric Synchronizer

  • Following removal of the use_cds var some tests did not work as expected when running as either a uk/xi worker. Some tests became either CDS or Taric specific (by default) depending on the test and the redundant use_cds env var.

  • Originally there was one spec called spec/controllers/api/admin/rollbacks_controller_spec.rb which was not CDS(uk)/Taric(xi) specific so it is now split into two specs.

  • I have locally tested Rollback, Apply and rake:download_apply_and_reindex for a uk worker and xi worker and both worked as expected locally.

Deployment risks

  • Includes actions which may effect critical data in the daily Taric/CDS sync jobs.

@HWallenberg HWallenberg requested a review from jebw February 8, 2024 17:53
@@ -26,6 +26,7 @@ def import
return unless proceed_with_import?(filename)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes may not be required as Taric Updates and importing is processed in app/lib/tariff_synchronizer/taric_update_downloader.rb. It could be that this code is actually redundant now...

Copy link
Contributor

@jebw jebw left a comment

Choose a reason for hiding this comment

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

Looks great - only query is that create_update_entry which used to be dead code and I'm pretty sure should continue to be dead code

@@ -4,6 +4,11 @@
let(:base_update_importer) { described_class.new(taric_update) }

describe '#apply', truncation: true do
before do
allow(TradeTariffBackend).to receive(:uk?).and_return(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this set the service to xi? as it stands both uk? and xi? will return false i think?

allow(TradeTariffBackend).to receive(:service).and_return('xi')


it 'invokes rollback' do
described_class.new.perform(date)
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is the same for every test so could get moved to the before block?

spec/controllers/api/admin/rollbacks_controller_uk_spec.rb Outdated Show resolved Hide resolved
spec/controllers/api/admin/rollbacks_controller_xi_spec.rb Outdated Show resolved Hide resolved
@@ -122,7 +126,7 @@ def rollback(rollback_date, keep: false)
end
end

Rails.logger.info "Rolled back to #{date}. Forced keeping records: #{!!keep}"
Rails.logger.info "Rolled back to #{date}. Forced keeping records: #{!keep.nil?}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks odd? means that keep == false will print 'Force keeping records: true' , as will keep == true

@@ -6,6 +6,9 @@
describe '#apply', truncation: true do
before do
allow(TradeTariffBackend).to receive(:service).and_return('xi')
# Setting :FIND to NIL as Taric_Importer.rb checks a file doesn't exist to Proceed_With_Import?
# SEE SPECS ON LINES 39 & 58.
allow(TariffSynchronizer::TaricUpdate).to receive(:find).and_return(nil) # Assuming no existing record
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to discuss this, I'm assuming from what you're saying that there are records in the tariff_updates table in which case I think those should be getting removed instead (or never created) but I may be missing something

@@ -148,6 +149,7 @@
before do
failed_update
allow(TradeTariffBackend).to receive(:service).and_return('xi')
allow(TradeTariffBackend).to receive(:service).and_return('xi')
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate line

@@ -101,6 +101,7 @@
allow_any_instance_of(TaricImporter).to receive(:import)
allow(TariffSynchronizer::TariffLogger).to receive(:failed_update)
allow(TradeTariffBackend).to receive(:service).and_return('xi')
allow(TradeTariffBackend).to receive(:service).and_return('xi')
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate line

@@ -15,6 +15,7 @@

context 'when everything is fine' do
it 'applies missing updates' do
# Calls taric_importer.rb and needs Create_Update_Entry!
Copy link
Contributor

Choose a reason for hiding this comment

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

Self referential description loop 😉

Class says to see here for explanation, here effectively says to look at the class

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 66 to 67
#This is required see spec/integration/taric_synchronizer_spec.rb:17
create_update_entry(file_path:, filename:)
Copy link
Contributor

Choose a reason for hiding this comment

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

When I checkout this branch I can comment out this line without impact on specs - not done a sync test though

When I'd look through the codes history, it looks like this was added in the early days of the CDS sync plans - looks like initial they tried to add CDS support to the Taric importer before splitting it into a separate CDS importer.

Presumably it has been dead code since then? create_update_entry, determine_file_size, and determine_filename can all be removed AFAICT

@@ -58,19 +59,24 @@ def taric_failed_log(exception, hash)
private

def proceed_with_import?(filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

This check always returns true (because use_cds? is false)

So the method can go

jebw added 2 commits March 8, 2024 15:35
This was returning early incorrectly causing spec failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants