Permalink
Browse files

Renaming kpi_backend_db_hostname and port to kpi_backend_db_url. Upda…

…ted with KPIggybank endpoint, posting form data
  • Loading branch information...
1 parent ae16283 commit ef7818e6b24753c605316486ab06f3e555aef1bf @ozten ozten committed May 3, 2012
Showing with 24 additions and 8 deletions.
  1. +1 −2 lib/configuration.js
  2. +23 −6 lib/wsapi/interaction_data.js
View
@@ -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 comments on commit ef7818e

Please sign in to comment.