Skip to content

Commit

Permalink
FirehoseClient can now target different streams
Browse files Browse the repository at this point in the history
  • Loading branch information
daynew committed Jul 17, 2020
1 parent 09afa07 commit 197b847
Show file tree
Hide file tree
Showing 29 changed files with 497 additions and 314 deletions.
17 changes: 10 additions & 7 deletions dashboard/app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def milestone
)
if share_filtering_error
FirehoseClient.instance.put_record(
study: 'share_filtering',
study_group: 'v0',
event: 'share_filtering_error',
data_string: "#{share_filtering_error.class.name}: #{share_filtering_error}",
data_json: {
level_source_id: @level_source.id
}.to_json
:analysis,
{
study: 'share_filtering',
study_group: 'v0',
event: 'share_filtering_error',
data_string: "#{share_filtering_error.class.name}: #{share_filtering_error}",
data_json: {
level_source_id: @level_source.id
}.to_json
}
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def submit
)

FirehoseClient.instance.put_record(
:analysis,
{
study: 'amazon-future-engineer-eligibility',
event: 'submit_to_afe',
Expand Down
11 changes: 7 additions & 4 deletions dashboard/app/controllers/api/v1/regional_partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ def find
end

FirehoseClient.instance.put_record(
study: 'regional-partner-search-log',
event: result,
data_string: zip_code,
source_page_id: params[:source_page_id]
:analysis,
{
study: 'regional-partner-search-log',
event: result,
data_string: zip_code,
source_page_id: params[:source_page_id]
}
)
end

Expand Down
27 changes: 15 additions & 12 deletions dashboard/app/controllers/api/v1/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ def search
)
if Gatekeeper.allows('logSchoolSearch')
FirehoseClient.instance.put_record(
study: 'school-search-log',
# TODO: (suresh) Change this to log request.headers["Referer"] (the URL of the page that the current
# XMLHTTPRequest was embedded in) so we can identify which page ("yourschool", "account sign up", etc.) was
# being used. Currently this header evaluates to nil on the Pegasus yourschool page, perhaps because of the way
# the Pegasus request is routed to a dashboardapi Dashboard controller.
event: "school-search",
# TODO: (suresh) Set this to the session id instead of the unique request id generated by our middleware stack,
# to anonymously aggregate a sequence of searches. Currently request.headers["Cookie"] is empty,
# perhaps due to the same problem as above.
project_id: request.uuid,
data_string: params[:q],
data_json: search_results.to_json
:analysis,
{
study: 'school-search-log',
# TODO: (suresh) Change this to log request.headers["Referer"] (the URL of the page that the current
# XMLHTTPRequest was embedded in) so we can identify which page ("yourschool", "account sign up", etc.) was
# being used. Currently this header evaluates to nil on the Pegasus yourschool page, perhaps because of the way
# the Pegasus request is routed to a dashboardapi Dashboard controller.
event: "school-search",
# TODO: (suresh) Set this to the session id instead of the unique request id generated by our middleware stack,
# to anonymously aggregate a sequence of searches. Currently request.headers["Cookie"] is empty,
# perhaps due to the same problem as above.
project_id: request.uuid,
data_string: params[:q],
data_json: search_results.to_json
}
)
end
render json: search_results
Expand Down
13 changes: 8 additions & 5 deletions dashboard/app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,14 @@ def firehose_unreachable
event = original_data['event']
project_id = original_data['project_id'] || nil
FirehoseClient.instance.put_record(
study: 'firehose-error-unreachable',
event: event,
project_id: project_id,
data_string: params.require(:error_text),
data_json: original_data.to_json
:analysis,
{
study: 'firehose-error-unreachable',
event: event,
project_id: project_id,
data_string: params.require(:error_text),
data_json: original_data.to_json
}
)
end

Expand Down
25 changes: 14 additions & 11 deletions dashboard/app/controllers/curriculum_tracking_pixel_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ def index
end

FirehoseClient.instance.put_record(
study: STUDY_NAME,
study_group: 'v1',
event: EVENT_NAME,
user_id: user_id,
data_string: curriculum_page,
data_json: {
locale: locale,
csx: csx,
course_or_unit: course_or_unit,
lesson: lesson
}.to_json
:analysis,
{
study: STUDY_NAME,
study_group: 'v1',
event: EVENT_NAME,
user_id: user_id,
data_string: curriculum_page,
data_json: {
locale: locale,
csx: csx,
course_or_unit: course_or_unit,
lesson: lesson
}.to_json
}
)
end

Expand Down
27 changes: 15 additions & 12 deletions dashboard/app/controllers/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,21 @@ def set_solution_image_url(level)
# to Firehose / Redshift.
def log_save_error(level)
FirehoseClient.instance.put_record(
study: 'level-save-error',
# Make it easy to count most frequent field name in which errors occur.
event: level.errors.keys.first,
# Level ids are different on levelbuilder, so use the level name. The
# level name can be joined on, against the levels table, to determine the
# level type or other level properties.
data_string: level.name,
data_json: {
errors: level.errors.to_h,
# User ids are different on levelbuilder, so use the email.
user_email: current_user.email,
}.to_json
:analysis,
{
study: 'level-save-error',
# Make it easy to count most frequent field name in which errors occur.
event: level.errors.keys.first,
# Level ids are different on levelbuilder, so use the level name. The
# level name can be joined on, against the levels table, to determine the
# level type or other level properties.
data_string: level.name,
data_json: {
errors: level.errors.to_h,
# User ids are different on levelbuilder, so use the email.
user_email: current_user.email,
}.to_json
}
)
end
end
27 changes: 15 additions & 12 deletions dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,21 @@ def show
end

FirehoseClient.instance.put_record(
study: 'project-views',
event: project_view_event_type(iframe_embed, sharing),
# allow cross-referencing with the storage_apps table.
project_id: storage_app_id,
# make it easier to group by project_type.
data_string: params[:key],
data_json: {
# not currently used, but may prove useful to have in the data later.
encrypted_channel_id: params[:channel_id],
# record type again to make it clear what data_string represents.
project_type: params[:key],
}.to_json
:analysis,
{
study: 'project-views',
event: project_view_event_type(iframe_embed, sharing),
# allow cross-referencing with the storage_apps table.
project_id: storage_app_id,
# make it easier to group by project_type.
data_string: params[:key],
data_json: {
# not currently used, but may prove useful to have in the data later.
encrypted_channel_id: params[:channel_id],
# record type again to make it clear what data_string represents.
project_type: params[:key],
}.to_json
}
)
render 'levels/show'
end
Expand Down
34 changes: 20 additions & 14 deletions dashboard/app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,26 +489,32 @@ def email_preference_params(source, form_kind)
def log_account_deletion_to_firehose(current_user, dependent_users)
# Log event for user initiating account deletion.
FirehoseClient.instance.put_record(
study: 'user-soft-delete-audit-v2',
event: 'initiated-account-deletion',
user_id: current_user.id,
data_json: {
user_type: current_user.user_type,
dependent_user_ids: dependent_users.pluck(:id),
}.to_json
:analysis,
{
study: 'user-soft-delete-audit-v2',
event: 'initiated-account-deletion',
user_id: current_user.id,
data_json: {
user_type: current_user.user_type,
dependent_user_ids: dependent_users.pluck(:id),
}.to_json
}
)

# Log separate events for dependent users destroyed in user-initiated account deletion.
# This should only happen for teachers.
dependent_users.each do |user|
FirehoseClient.instance.put_record(
study: 'user-soft-delete-audit-v2',
event: 'dependent-account-deletion',
user_id: user[:id],
data_json: {
user_type: user[:user_type],
deleted_by_id: current_user.id,
}.to_json
:analysis,
{
study: 'user-soft-delete-audit-v2',
event: 'dependent-account-deletion',
user_id: user[:id],
data_json: {
user_type: user[:user_type],
deleted_by_id: current_user.id,
}.to_json
}
)
end
end
Expand Down
15 changes: 9 additions & 6 deletions dashboard/app/helpers/levels_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,15 @@ def redirect_under_13_without_tos_teacher(level)
else
error_message = I18n.t("errors.messages.too_young")
FirehoseClient.instance.put_record(
study: "redirect_under_13",
event: "student_with_no_teacher_redirected",
user_id: current_user.id,
data_json: {
game: level.game.name
}.to_json
:analysis,
{
study: "redirect_under_13",
event: "student_with_no_teacher_redirected",
user_id: current_user.id,
data_json: {
game: level.game.name
}.to_json
}
)
end
redirect_to '/', flash: {alert: error_message}
Expand Down
21 changes: 12 additions & 9 deletions dashboard/app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ def move_sections_and_destroy_source_user(source_user:, destination_user:, takeo

def log_account_takeover_to_firehose(source_user:, destination_user:, type:, provider:, error: nil)
FirehoseClient.instance.put_record(
study: 'user-soft-delete-audit-v2',
event: "#{type}-account-takeover", # Silent or OAuth takeover
user_id: source_user.id, # User account being "taken over" (deleted)
data_int: destination_user.id, # User account after takeover
data_string: provider, # OAuth provider
data_json: {
user_type: destination_user.user_type,
error: error,
}.to_json
:analysis,
{
study: 'user-soft-delete-audit-v2',
event: "#{type}-account-takeover", # Silent or OAuth takeover
user_id: source_user.id, # User account being "taken over" (deleted)
data_int: destination_user.id, # User account after takeover
data_string: provider, # OAuth provider
data_json: {
user_type: destination_user.user_type,
error: error,
}.to_json
}
)
end

Expand Down
25 changes: 14 additions & 11 deletions dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,20 @@ def self.get_script_family_redirect_for_user(family_name, user: nil, locale: 'en

def self.log_redirect(old_script_name, new_script_name, request, event_name, user_type)
FirehoseClient.instance.put_record(
study: 'script-family-redirect',
event: event_name,
data_string: request.path,
data_json: {
old_script_name: old_script_name,
new_script_name: new_script_name,
method: request.method,
url: request.url,
referer: request.referer,
user_type: user_type
}.to_json
:analysis,
{
study: 'script-family-redirect',
event: event_name,
data_string: request.path,
data_json: {
old_script_name: old_script_name,
new_script_name: new_script_name,
method: request.method,
url: request.url,
referer: request.referer,
user_type: user_type
}.to_json
}
)
end

Expand Down
3 changes: 3 additions & 0 deletions dashboard/app/models/studio_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def self.merge(studio_person_a, studio_person_b)
end

FirehoseClient.instance.put_record(
:analysis,
{
study: 'studio_person_audit',
event: 'studio_person_merge',
Expand Down Expand Up @@ -80,6 +81,7 @@ def self.split(studio_person)
users.second.update!(studio_person: StudioPerson.create!(emails: users.second.email))

FirehoseClient.instance.put_record(
:analysis,
{
study: 'studio_person_audit',
event: 'studio_person_split',
Expand All @@ -105,6 +107,7 @@ def add_email_to_emails(email)
update!(emails: (emails_as_array << normalized_email).join(','))

FirehoseClient.instance.put_record(
:analysis,
{
study: 'studio_person_audit',
event: 'studio_person_add_email_to_emails',
Expand Down
Loading

0 comments on commit 197b847

Please sign in to comment.