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

Remove null values from events #82

Merged
merged 5 commits into from
Jul 17, 2023
Merged

Conversation

asatwal
Copy link
Collaborator

@asatwal asatwal commented Jul 6, 2023

Trello-1253

In TV a number of events are not being sent to BQ from the vacancies table. When we attempted a backfill, there were a lot of errors in the sidekiq dead queues.

After adding more diagnosis to the error logs (See PR), we were able to find the bug.

In the values field of the event data, some value array fields have nil values.

For example these entries for the vacancies table are causing API errors:

{"key"=>"working_patterns", "value"=>["full_time", nil]}, 
{"key"=>"working_patterns", "value"=>["full_time", "part_time", "job_share", "term_time", nil]}, 

The following changes have been made by this PR:

  • Remove the nil values and write a warning message to the logs
  • Refine the previous error message to reduce the information overload
  • Fix rubocop offenses

@asatwal asatwal requested a review from duncanjbrown July 6, 2023 16:17
@asatwal asatwal self-assigned this Jul 6, 2023
@asatwal asatwal force-pushed the remove-null-values-from-events branch from a059968 to 29a98c2 Compare July 11, 2023 11:48
Gemfile Outdated
@@ -6,6 +6,21 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Specify your gem's dependencies in dfe-analytics.gemspec
gemspec

group :development do
Copy link
Contributor

Choose a reason for hiding this comment

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

🤷 If this is what rubocop wants!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't work so I had to enforce the gemspec style. This required rubocop updates and subsequent updates of all the Gemfiles.

@@ -115,10 +110,14 @@ def convert_value_to_json(value)

def hash_to_kv_pairs(hash)
hash.map do |(key, values)|
values_as_json = Array.wrap(values).map do |value|
convert_value_to_json(value)
if Array.wrap(values).count(&:nil?).positive?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if Array.wrap(values).count(&:nil?).positive?
if Array.wrap(values).any?(&:nil?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. That's better !

values_as_json = Array.wrap(values).map do |value|
convert_value_to_json(value)
if Array.wrap(values).count(&:nil?).positive?
message = "event has missing values in data - event: #{@event_hash} key: #{key} values: #{values}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message = "event has missing values in data - event: #{@event_hash} key: #{key} values: #{values}"
message = "an array field contains nulls - event: #{@event_hash} key: #{key} values: #{values}"

@asatwal asatwal force-pushed the remove-null-values-from-events branch 2 times, most recently from 974239d to d673ca3 Compare July 11, 2023 16:38
@asatwal asatwal force-pushed the remove-null-values-from-events branch from d673ca3 to c48cdd9 Compare July 11, 2023 16:53
@asatwal asatwal merged commit 216495f into main Jul 17, 2023
@asatwal asatwal deleted the remove-null-values-from-events branch July 17, 2023 10:42
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.

2 participants