Skip to content
Snippets Groups Projects
Commit ef7818e6 authored by Austin King's avatar Austin King
Browse files

Renaming kpi_backend_db_hostname and port to kpi_backend_db_url. Updated with...

Renaming kpi_backend_db_hostname and port to kpi_backend_db_url. Updated with KPIggybank endpoint, posting form data
parent ae162831
No related branches found
No related tags found
No related merge requests found
......@@ -124,8 +124,7 @@ var conf = module.exports = convict({
format: 'number = 0.0',
env: 'KPI_BACKEND_SAMPLE_RATE'
},
kpi_backend_db_hostname: 'string = "localhost"',
kpi_backend_db_port: "integer{1,65535} = 80",
kpi_backend_db_url: 'string = "http://localhost/wsapi/interaction_data"',
bcrypt_work_factor: {
doc: "How expensive should we make password checks (to mitigate brute force attacks) ? Each increment is 2x the cost.",
format: 'integer{6,20} = 12',
......
......@@ -6,7 +6,9 @@ const coarse = require('../coarse_user_agent_parser'),
config = require('../configuration.js'),
http = require('http'),
logger = require('../logging.js').logger,
querystring = require('querystring'),
und = require('underscore'),
urlparse = require('urlparse'),
wsapi = require('../wsapi.js');
// Accept JSON formatted interaction data and send it to the KPI Backend
......@@ -21,25 +23,40 @@ exports.i18n = false;
var store = function (kpi_json, cb) {
var options,
db_url,
kpi_req,
kpi_resp = function (res) {
logger.debug('KPI Backend responded ' + res.statusCode);
};
if (!! config.get('kpi_backend_db_hostname') &&
!! config.get('kpi_backend_db_port')) {
if (!! config.get('kpi_backend_db_url')) {
var post_data = querystring.stringify({
'data' : JSON.stringify(kpi_json)
});
var db_url = urlparse(config.get('kpi_backend_db_url'));
options = {
hostname: config.get('kpi_backend_db_hostname'),
port: config.get('kpi_backend_db_port'),
method: 'POST'
hostname: db_url.host,
path: db_url.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
};
if (db_url.port) {
options.port = db_url.port;
}
kpi_req = http.request(options);
kpi_req.on('error', function (e) {
// TODO statsd counter
logger.error('KPI Backend request error: ' + e.message);
});
logger.debug("sending request to KPI backend" + config.get('kpi_backend_db_hostname'));
logger.debug("sending request to KPI backend" + config.get('kpi_backend_db_url'));
kpi_req.write(post_data);
kpi_req.end();
} else {
cb(false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment