Skip to content

Commit

Permalink
Minor cleanup of event names and classes to make the API less specific.
Browse files Browse the repository at this point in the history
  • Loading branch information
Subbu Allamaraju committed Apr 17, 2012
1 parent 7c169d8 commit 36a5715
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
@@ -1,3 +1,7 @@
## Apr 16, 2012

* Minor cleanup of event names and classes to make the API less specific.

## Apr 15, 2012

* Refactor logging to error, access, proxy and default logs. The proxy log file contains outgoing
Expand Down
44 changes: 26 additions & 18 deletions modules/console/app.js
Expand Up @@ -21,6 +21,7 @@ var winston = require('winston'),
browserify = require('browserify'),
headers = require('headers'),
fs = require('fs'),
os = require('os'),
sanitize = require('validator').sanitize,
connect = require('connect'),
expat = require('xml2json'),
Expand Down Expand Up @@ -212,10 +213,11 @@ var Console = module.exports = function(config, cb) {
holder.connection = {
remoteAddress: req.connection.remoteAddress
};
// Start the top level URL transaction
// Start the top level event
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: route.routeInfo.method.toUpperCase() + ' ' + route.routeInfo.path,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -266,10 +268,11 @@ var Console = module.exports = function(config, cb) {
});
}

// Start the top level URL transaction
// Start the top level event
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: req.method.toUpperCase() + ' ' + req.url,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -342,10 +345,11 @@ var Console = module.exports = function(config, cb) {
return;
}

// Start the top level URL transaction
// Start the top level event
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: req.method.toUpperCase() + ' ' + req.url,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -395,10 +399,11 @@ var Console = module.exports = function(config, cb) {
});
}

// Start the top level URL transaction
// Start the top level event
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: req.method.toUpperCase() + ' ' + req.url,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -482,10 +487,11 @@ var Console = module.exports = function(config, cb) {
});
}

// Start the top level URL transaction
// Start the top level event
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: req.method.toUpperCase() + ' ' + req.url,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -540,8 +546,9 @@ var Console = module.exports = function(config, cb) {
collectHttpQueryParams(req, holder, true);
collectHttpHeaders(req, holder);
var urlEvent = engine.beginEvent({
type: 'URL',
name: req.url,
clazz: 'info',
type: 'route',
name: req.method.toUpperCase() + ' ' + req.url,
message: {
ip: req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -613,7 +620,8 @@ var Console = module.exports = function(config, cb) {
var heartbeat = setInterval(function () {
engine.emit(Engine.Events.HEART_BEAT, {
pid: process.pid,
uptime: process.uptime()
uptime: process.uptime(),
freemem: os.freemem()
});
}, 60000);

Expand Down
2 changes: 1 addition & 1 deletion modules/console/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-console",
"version": "0.5.3",
"version": "0.5.4",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
Expand Down
3 changes: 1 addition & 2 deletions modules/engine/lib/engine/delet.js
Expand Up @@ -78,7 +78,6 @@ exports.exec = function (opts, statement, parentEvent, cb) {
if(context.hasOwnProperty(name)) { // The value may be null/undefined, and hence the check the property
apiTx = opts.logEmitter.beginEvent({
parent: deleteExecTx.event,
type: 'API',
name: name,
message: {
line: statement.line
Expand Down Expand Up @@ -112,7 +111,7 @@ exports.exec = function (opts, statement, parentEvent, cb) {
resource = tempResources[name] || tables[name];
apiTx = opts.logEmitter.beginEvent({
parent: deleteExecTx.event,
type: 'API',
type: 'table',
name: name,
message: {
line: statement.line
Expand Down
29 changes: 20 additions & 9 deletions modules/engine/lib/engine/log-emitter.js
Expand Up @@ -35,6 +35,7 @@ var LogEmitter = module.exports = function() {
* The arg is an object with the following properties:
*
* - parent: Parent event, if nested.
* - clazz: class of the event, such as 'info', 'warn', 'error'
* - type: Type of the event
* - name: Name of the event
* - message: A message payload
Expand All @@ -56,7 +57,7 @@ var LogEmitter = module.exports = function() {
eventId: getEventId(),
parentEventId: (parent ? parent.eventId = parent.eventId || 0 : 0),
startTime: Date.now(),
tx: 'begin',
clazz: 'begin',
type: type || 'ql.io',
name: name || 'ql.io',
uuid: (parent && parent.uuid ? parent.uuid : uuid())
Expand All @@ -70,7 +71,7 @@ var LogEmitter = module.exports = function() {
var message = {status : 'Success'};
if (e) {
if(e.emitted === undefined) {
event.tx = 'error';
event.clazz = 'error';
that.emit(eventTypes.ERROR, event, e);
e.emitted = true;
}
Expand All @@ -87,7 +88,7 @@ var LogEmitter = module.exports = function() {
var message = {status : 'Success'};
if(err) {
if(err.emitted === undefined) {
event.tx = 'error';
event.clazz = 'error';
that.emitError(event, err);
err.emitted = true;
}
Expand All @@ -113,19 +114,29 @@ var LogEmitter = module.exports = function() {
event.duration = Date.now() - startTime;
}
catch(e) {
event.txDuration = 0;
event.duration = 0;
}

event.tx = 'end';
event.clazz = 'end';

this.emit(eventTypes.END_EVENT, event, message); //end
}

/**
* Emits an event
*/
this.emitEvent = function(event, msg){
event.tx = 'info';
this.emitEvent = function(){
var event, msg;
if(arguments.length === 1) {
event = {
clazz: 'info'
};
msg = arguments[0];
}
else if(arguments.length === 2) {
event = arguments[0];
msg = arguments[1];
}
this.emit(eventTypes.EVENT, event, msg);
}

Expand All @@ -141,7 +152,7 @@ var LogEmitter = module.exports = function() {
else if (arguments.length === 1) {
msg = arguments[0];
}
event.tx = 'warn';
event.clazz = 'warn';
this.emit(eventTypes.WARNING, event, msg);
}

Expand All @@ -161,7 +172,7 @@ var LogEmitter = module.exports = function() {
else if (arguments.length === 1) {
msg = arguments[0];
}
event.tx = 'error';
event.clazz = 'error';
this.emit(eventTypes.ERROR, event, msg, cause);
}

Expand Down
16 changes: 8 additions & 8 deletions modules/engine/lib/engine/select.js
Expand Up @@ -180,12 +180,12 @@ function execInternal(opts, statement, cb, parentEvent) {
request = opts.request, emitter = opts.emitter;

var selectExecTx = opts.logEmitter.beginEvent({
parent: parentEvent,
name: 'select-exec',
message: {
line: statement.line
},
cb: cb});
parent: parentEvent,
name: 'select-exec',
message: {
line: statement.line
},
cb: cb});

//
// Pre-fill columns
Expand Down Expand Up @@ -242,7 +242,7 @@ function execInternal(opts, statement, cb, parentEvent) {
if(context.hasOwnProperty(name)) { // The value may be null/undefined, and hence the check the property
apiTx = opts.logEmitter.beginEvent({
parent: selectExecTx.event,
type: 'API',
type: 'table',
name: name,
message: {
line: statement.line
Expand Down Expand Up @@ -270,7 +270,7 @@ function execInternal(opts, statement, cb, parentEvent) {
resource = tempResources[from.name] || tables[from.name];
apiTx = opts.logEmitter.beginEvent({
parent: selectExecTx.event,
type: 'API',
type: 'table',
name: from.name,
message: {line: statement.line},
cb: selectExecTx.cb});
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-engine",
"version": "0.5.9",
"version": "0.5.10",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
Expand Down
2 changes: 1 addition & 1 deletion modules/engine/test/error-events-for-logutil-test.js
Expand Up @@ -98,7 +98,7 @@ module.exports = {

var errorHandler = function(ctx, msg) {
ctx = ctx || {};
test.equals(ctx.type, 'API', 'API expected');
test.equals(ctx.type, 'table', 'table expected');
test.equals(msg.type, 'undefined_method');
errorGot = true;
}
Expand Down

0 comments on commit 36a5715

Please sign in to comment.