Permalink
Browse files

use strict mode everywhere

  • Loading branch information...
1 parent e592724 commit 402f68b9cbe2a0fb332343788df6fae5682e1401 Philip (flip) Kromer committed Sep 3, 2012
View
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include("collector"),
cube = require("../"),
server = cube.server(options);
View
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include('evaluator'),
cube = require("../"),
server = cube.server(options);
View
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include('warmer'),
cube = require("../"),
warmer = cube.warmer(options);
@@ -1,3 +1,5 @@
+'use strict';
+
//
// authentication -- authenticate user identities and authorize their action
//
@@ -106,8 +108,8 @@ authentication.mongo_cookie = function(db, options){
// base-64 encode a uid and bcrypted secret
authentication.gen_cookie = function(session_name, uid, secret){
- encoded_uid = new Buffer(uid, 'utf8').toString('base64');
- encoded_sec = new Buffer(secret, 'utf8').toString('base64');
+ var encoded_uid = new Buffer(uid, 'utf8').toString('base64');
+ var encoded_sec = new Buffer(secret, 'utf8').toString('base64');
return (session_name+"="+encoded_uid+"--"+encoded_sec+";");
};
View
@@ -1,3 +1,5 @@
+'use strict';
+
module.exports = bisect;
function bisect(a, x) {
View
@@ -1,3 +1,5 @@
+'use strict';
+
exports.putter = function(putter) {
var valuesByKey = {};
View
@@ -1,3 +1,5 @@
+'use strict';
+
//
// collector -- listen for incoming metrics
//
View
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
http = require("http");
View
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
dgram = require("dgram");
View
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
websocket = require("websocket");
View
@@ -1,3 +1,5 @@
+'use strict';
+
//
// emitter - writes events to the collector.
//
View
@@ -1,3 +1,5 @@
+'use strict';
+
//
// endpoint -- router for requests.
//
@@ -8,6 +10,7 @@
//
module.exports = function(method, path, dispatch) {
+ var match;
if (method instanceof RegExp) {
dispatch = path, path = method;
match = function(p, m) { return path.test(p); };
View
@@ -1,3 +1,5 @@
+'use strict';
+
var endpoint = require("./endpoint"),
url = require("url");
View
@@ -1,3 +1,5 @@
+'use strict';
+
// TODO include the event._id (and define a JSON encoding for ObjectId?)
// TODO allow the event time to change when updating (fix invalidation)
@@ -53,7 +55,7 @@ exports.putter = function(db){
// Validate the date and type.
if (!type_re.test(type)) return callback({error: "invalid type"}), -1;
if (isNaN(time)) return callback({error: "invalid time"}), -1;
-
+
// Drop events from before invalidation horizon
if(time < new Date(new Date() - options.horizons.invalidation)) return callback({error: "event before invalidation horizon"}), -1;
@@ -80,6 +82,7 @@ exports.putter = function(db){
// that if you want to customize the size of the capped metrics collection,
// or add custom indexes, you can still do all that by hand.
db.collectionNames(type + "_events", function(error, names) {
+ handle(error);
var events = collection(type).events;
if (names.length) return saveEvents();
@@ -88,7 +91,7 @@ exports.putter = function(db){
db.createCollection(type + "_events", event_options, function(error, events){
handle(error);
events.ensureIndex({"t": 1}, handle);
-
+
// Create a collection for metrics. Three indexes are required: one
// for finding metrics, one (_id) for updating, and one for invalidation.
db.createCollection(type + "_metrics", metric_options, function(error, metrics) {
@@ -159,7 +162,6 @@ exports.putter = function(db){
"_id.t": {$in: timesToInvalidateByTier[tier]}
}, invalidate, multi);
}
- flushed = true;
}
timesToInvalidateByTierByType = {}; // copy-on-write
}, invalidateInterval));
@@ -199,7 +201,7 @@ exports.getter = function(db) {
try {
expression = parser.parse(request.expression);
} catch (error) {
- var resp = { is: "invalid expression", expression: request.expression, error: error }
+ var resp = { is: "invalid expression", expression: request.expression, error: error };
metalog.info('cube_getter', resp);
return callback(resp), -1;
}
@@ -305,6 +307,7 @@ exports.getter = function(db) {
};
function handle(error) {
+ metalog.info('cube_request', {is: 'event error', error: error });
if (error) throw error;
}
View
@@ -1,3 +1,5 @@
+'use strict';
+
exports.authentication = require("./authentication");
exports.metalog = require("./metalog");
exports.emitter = require("./emitter");
View
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util");
var metalog = {
@@ -39,9 +41,8 @@ metalog.minor = function(name, hsh){
// Dump the 'util.inspect' view of each argument to the console.
metalog.inspectify = function(args){
- var whence = metalog.inspectify.caller.name || '(anon)';
- for (idx in arguments) {
- if (whence){ util.print(whence + ' ' + idx + ": "); }
+ for (var idx in arguments) {
+ util.print(idx + ": ");
util.print(util.inspect(arguments[idx])+"\n");
};
};
View
@@ -1,3 +1,5 @@
+'use strict';
+
// TODO use expression ids or hashes for more compact storage
var parser = require("./metric-expression"),
@@ -114,9 +116,8 @@ exports.getter = function(db) {
reduce = reduces[expression.reduce],
filter = {t: {}},
fields = {t: 1};
-
+
if (!reduce) return callback({error: "invalid reduce operation"}), -1;
-
// Copy any expression filters into the query object.
expression.filter(filter);
@@ -175,7 +176,7 @@ exports.getter = function(db) {
// the order in which rows are returned from the database. Thus, we know
// when we've seen all of the events for a given time interval.
function computeFlat(start, stop) {
- if(tier.floor(start) < new Date(new Date() - options.horizons.calculation)){
+ if (tier.floor(start) < new Date(new Date() - options.horizons.calculation)){
metalog.info('cube_compute', {is: 'past_horizon', metric: metric });
start = tier.step(tier.floor(new Date(new Date() - options.horizons.calculation)))
}
@@ -248,5 +249,6 @@ exports.getter = function(db) {
};
function handle(error) {
+ metalog.info('cube_request', {is: 'event error', error: error });
if (error) throw error;
}
View
@@ -0,0 +1,9 @@
+
+exports.units = {
+ second: 1e3,
+ second10: 10e3,
+ minute: 60e3,
+ minute5: 300e3,
+ hour: 3600e3,
+ day: 86400e3
+};
View
@@ -1,3 +1,5 @@
+'use strict';
+
var reduces = module.exports = {
sum: function(values) {
@@ -23,7 +25,7 @@ var reduces = module.exports = {
// while (++i < n) if (!((value = values[i]) in map)) map[value] = ++count;
// return count;
// },
- //
+ //
// median: function(values) {
// return quantile(values.sort(ascending), .5);
// }
View
@@ -1,3 +1,5 @@
+'use strict';
+
// Server -- generic HTTP, UDP and websockets server
//
// Used by the collector to accept new events via HTTP or websockets
@@ -17,7 +19,7 @@ var util = require("util"),
dgram = require("dgram"),
websocket = require("websocket"),
websprocket = require("websocket-server"),
- static = require("node-static"),
+ file_server = require("node-static"),
mongodb = require("mongodb"),
authentication = require("./authentication"),
event = require("./event"),
@@ -52,7 +54,7 @@ module.exports = function(options) {
var server = {},
primary = http.createServer(),
secondary = websprocket.createServer(),
- file = new static.Server("static"),
+ file = new file_server.Server("static"),
udp,
endpoints = {ws: [], http: []},
server_options = options["mongo-server_options"],
@@ -108,26 +110,26 @@ module.exports = function(options) {
// save auth from connection requesta
var authorization = request.authorized;
+ function connection_callback(response) {
+ connection.sendUTF(JSON.stringify(response));
+ }
+
// Forward messages to the appropriate endpoint, or close the connection.
for (var i = -1, n = endpoints.ws.length, e; ++i < n;) {
if ((e = endpoints.ws[i]).match(request.url)) {
- function callback(response) {
- connection.sendUTF(JSON.stringify(response));
- }
-
- callback.id = ++id;
+ connection_callback.id = ++id;
// Listen for socket disconnect.
if (e.dispatch.close) connection.socket.on("end", function() {
- e.dispatch.close(callback);
+ e.dispatch.close(connection_callback);
});
connection.on("message", function(message) {
// staple the authorization back on
var payload = JSON.parse(message.utf8Data || message);
payload.authorized = authorization;
- e.dispatch(payload, callback);
+ e.dispatch(payload, connection_callback);
});
metalog.event('cube_request', { is: 'ws', method: "WebSocket", ip: connection.remoteAddress, path: request.url}, 'minor');
@@ -141,20 +143,19 @@ module.exports = function(options) {
primary.on("request", function(request, response) {
var u = url.parse(request.url);
+ function auth_ok(perms) {
+ metalog.event('cube_request', { is: 'auth_ok', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: true, user: perms });
+ e.dispatch(request, response);
+ }
+ function auth_no(reason) {
+ metalog.event('cube_request', { is: 'auth_no', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: false });
+ response.writeHead(403, {"Content-Type": "text/plain"});
+ response.end("403 Forbidden");
+ }
+
// Forward messages to the appropriate endpoint, or 404.
for (var i = -1, n = endpoints.http.length, e; ++i < n;) {
if ((e = endpoints.http[i]).match(u.pathname, request.method)) {
-
- function auth_ok(perms) {
- metalog.event('cube_request', { is: 'auth_ok', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: true, user: perms });
- e.dispatch(request, response);
- }
- function auth_no(reason) {
- metalog.event('cube_request', { is: 'auth_no', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: false });
- response.writeHead(403, {"Content-Type": "text/plain"});
- response.end("403 Forbidden");
- }
-
return authenticator.check(request, auth_ok, auth_no);
}
}
@@ -178,7 +179,7 @@ module.exports = function(options) {
server.start = function(server_start_cb) {
// Connect to mongodb.
- mongo_password = options["mongo-password"]; delete options["mongo-password"];
+ var mongo_password = options["mongo-password"]; delete options["mongo-password"];
metalog.info('cube_life', {is: 'mongo_connect', options: options });
db.open(function(error) {
if (error) throw error;
View
@@ -1,3 +1,5 @@
+'use strict';
+
var tiers = module.exports = {};
var second = 1000,
View
@@ -1,3 +1,5 @@
+'use strict';
+
// Much like db.collection, but caches the result for both events and metrics.
// Also, this is synchronous, since we are opening a collection unsafely.
var types = module.exports = function(db) {
View
@@ -1,3 +1,5 @@
+'use strict';
+
var url = require("url"),
path = require("path"),
endpoint = require("./endpoint"),
Oops, something went wrong.

0 comments on commit 402f68b

Please sign in to comment.