Skip to content

Commit

Permalink
Merge pull request #28634 from code-dot-org/log-firehose-failure
Browse files Browse the repository at this point in the history
log firehose event via server after failing to log via client
  • Loading branch information
davidsbailey committed May 20, 2019
2 parents 58b7fee + 3ec25ef commit 3e88a9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/src/lib/util/firehose.js
Expand Up @@ -180,6 +180,21 @@ class FirehoseClient {
return data;
}

handleError(requestData, error) {
// Report the error via our own servers, in case reporting it directly
// to firehose was blocked by a network firewall.
$.ajax({
url: '/api/firehose_unreachable',
data: JSON.stringify({
original_data: requestData,
error_text: String(error)
}),
contentType: 'application/json; charset=utf-8',
method: 'PUT',
dataType: 'json'
});
}

/**
* Pushes one data record into the delivery stream.
* @param {hash} data The data to push.
Expand All @@ -197,6 +212,7 @@ class FirehoseClient {
options = {alwaysPut: false, includeUserId: false, callback: null}
) {
data = this.addCommonValues(data, options.includeUserId);
const handleError = this.handleError.bind(this, data);
if (!this.shouldPutRecord(options['alwaysPut'])) {
console.groupCollapsed('Skipped sending record to ' + deliveryStreamName);
console.log(data);
Expand All @@ -217,6 +233,8 @@ class FirehoseClient {
function(err, data) {
if (options.callback) {
options.callback(err, data);
} else if (err) {
handleError(err);
}
}
);
Expand Down
14 changes: 14 additions & 0 deletions dashboard/app/controllers/api_controller.rb
Expand Up @@ -441,6 +441,20 @@ def sign_cookies
head :ok
end

# PUT /api/firehose_unreachable
def firehose_unreachable
original_data = params.require(:original_data)
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
)
end

private

def load_student(student_id)
Expand Down
1 change: 1 addition & 0 deletions dashboard/config/routes.rb
Expand Up @@ -575,6 +575,7 @@
get '/api/user_progress/:script', to: 'api#user_progress', as: 'user_progress'
get '/api/user_progress/:script/:stage_position/:level_position', to: 'api#user_progress_for_stage', as: 'user_progress_for_stage'
get '/api/user_progress/:script/:stage_position/:level_position/:level', to: 'api#user_progress_for_stage', as: 'user_progress_for_stage_and_level'
put '/api/firehose_unreachable', to: 'api#firehose_unreachable'
namespace :api do
api_methods.each do |action|
get action, action: action
Expand Down

0 comments on commit 3e88a9e

Please sign in to comment.