From fe8294319c49a72358faf0225a2d9f8c271af809 Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Tue, 15 Nov 2011 10:49:23 -0800 Subject: [PATCH] DTrace rework --- lib/dtrace.js | 57 +++++++++++++++++++++++--------- lib/messages/add_response.js | 1 + lib/messages/bind_response.js | 2 ++ lib/messages/compare_response.js | 1 + lib/messages/result.js | 31 +++++++++-------- lib/messages/search_response.js | 15 +++++++++ lib/server.js | 26 ++++++--------- 7 files changed, 87 insertions(+), 46 deletions(-) diff --git a/lib/dtrace.js b/lib/dtrace.js index 15498aa..2842e74 100644 --- a/lib/dtrace.js +++ b/lib/dtrace.js @@ -7,47 +7,65 @@ var dtrace = require('dtrace-provider'); ///--- Globals var SERVER_PROVIDER; +var DTRACE_ID = 0; +var MAX_INT = 4294967295; /* Args: - * 0 -> RequestId (::) + * server-*-start: + * 0 -> id * 1 -> remoteIP * 2 -> bindDN * 3 -> req.dn * 4,5 -> op specific + * + * server-*-done: + * 0 -> id + * 1 -> remoteIp + * 2 -> bindDN + * 3 -> requsetDN + * 4 -> status + * 5 -> errorMessage + * */ var SERVER_PROBES = { // 4: attributes.length - add: ['char *', 'char *', 'char *', 'char *', 'int'], + 'server-add-start': ['int', 'char *', 'char *', 'char *', 'int'], + 'server-add-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], - bind: ['char *', 'char *', 'char *', 'char *'], + 'server-bind-start': ['int', 'char *', 'char *', 'char *'], + 'server-bind-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // 4: attribute, 5: value - compare: ['char *', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-compare-start': ['int', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-compare-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], - 'delete': ['char *', 'char *', 'char *', 'char *'], + 'server-delete-start': ['int', 'char *', 'char *', 'char *'], + 'server-delete-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // 4: requestName, 5: requestValue - exop: ['char *', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-exop-start': ['int', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-exop-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // 4: changes.length - modify: ['char *', 'char *', 'char *', 'char *', 'int'], + 'server-modify-start': ['int', 'char *', 'char *', 'char *', 'int'], + 'server-modify-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // 4: newRdn, 5: newSuperior - modifyDN: ['char *', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-modifydn-start': ['int', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-modifydn-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // 4: filter, 5: scope - search: ['char *', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-search-start': ['int', 'char *', 'char *', 'char *', 'char *', 'char *'], + 'server-search-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], + // Last two are searchEntry.DN and seachEntry.attributes.length + 'server-search-entry': ['int', 'char *', 'char *', 'char *', 'char *', 'int'], - unbind: ['char *', 'char *', 'char *', 'char *'], + 'server-unbind-start': ['int', 'char *', 'char *', 'char *'], + 'server-unbind-done': ['int', 'char *', 'char *', 'char *', 'int', 'char *'], // remote IP - connection: ['char *'], - - request: ['char *', 'char *', 'char *', 'char *'], - - // requestId, remoteIp, bindDN, request.dn, statusCode, errorMessage - response: ['char *', 'char *', 'char *', 'char *', 'int', 'char *'] + 'server-connection': ['char *'], }; @@ -65,6 +83,13 @@ module.exports = function() { }); SERVER_PROVIDER.enable(); + + SERVER_PROVIDER._nextId = function() { + if (DTRACE_ID === MAX_INT) + DTRACE_ID = 0; + + return ++DTRACE_ID; + }; } return SERVER_PROVIDER; diff --git a/lib/messages/add_response.js b/lib/messages/add_response.js index 23fd242..7324f1a 100644 --- a/lib/messages/add_response.js +++ b/lib/messages/add_response.js @@ -6,6 +6,7 @@ var LDAPResult = require('./result'); var Protocol = require('../protocol'); + ///--- API function AddResponse(options) { diff --git a/lib/messages/bind_response.js b/lib/messages/bind_response.js index 1c9f9f8..0f8f3ac 100644 --- a/lib/messages/bind_response.js +++ b/lib/messages/bind_response.js @@ -6,6 +6,7 @@ var LDAPResult = require('./result'); var Protocol = require('../protocol'); + ///--- API function BindResponse(options) { @@ -21,3 +22,4 @@ function BindResponse(options) { } util.inherits(BindResponse, LDAPResult); module.exports = BindResponse; + diff --git a/lib/messages/compare_response.js b/lib/messages/compare_response.js index ff29cac..de7a7b7 100644 --- a/lib/messages/compare_response.js +++ b/lib/messages/compare_response.js @@ -6,6 +6,7 @@ var LDAPResult = require('./result'); var Protocol = require('../protocol'); + ///--- API function CompareResponse(options) { diff --git a/lib/messages/result.js b/lib/messages/result.js index a672080..36b9632 100644 --- a/lib/messages/result.js +++ b/lib/messages/result.js @@ -5,10 +5,10 @@ var util = require('util'); var asn1 = require('asn1'); -var LDAPMessage = require('./message'); - -var Protocol = require('../protocol'); var dtrace = require('../dtrace'); +var LDAPMessage = require('./message'); +var Protocol = require('../protocol'); + ///--- Globals @@ -72,17 +72,20 @@ LDAPResult.prototype.end = function(status) { var self = this; this.connection.write(ber); - dtrace.fire('response', function() { - var c = self.connection || {ldap: {bindDN: ''}}; - return [ - (self.logId || ''), - (c.remoteAddress || ''), - c.ldap.bindDN.toString(), - (self.requestDN ? self.requestDN.toString() : ''), - self.status, - self.errorMessage - ]; - }); + if (self._dtraceOp && self._dtraceId) { + dtrace.fire('server-' + self._dtraceOp + '-done', function() { + var c = self.connection || {ldap: {}}; + return [ + self._dtraceId || 0, + (c.remoteAddress || ''), + c.ldap.bindDN ? c.ldap.bindDN.toString() : '', + (self.requestDN ? self.requestDN.toString() : ''), + status || self.status, + self.errorMessage + ]; + }); + } + } catch (e) { this.log.warn('%s failure to write message %j: %s', this.connection.ldap.id, this.json, e.toString()); diff --git a/lib/messages/search_response.js b/lib/messages/search_response.js index d723f3b..e2e83a0 100644 --- a/lib/messages/search_response.js +++ b/lib/messages/search_response.js @@ -7,6 +7,7 @@ var LDAPResult = require('./result'); var SearchEntry = require('./search_entry'); var SearchReference = require('./search_reference'); +var dtrace = require('../dtrace'); var parseDN = require('../dn').parse; var parseURL = require('../url').parse; var Protocol = require('../protocol'); @@ -87,6 +88,20 @@ SearchResponse.prototype.send = function(entry, nofiltering) { this.connection.write(entry.toBer()); this.sentEntries++; + + if (self._dtraceOp && self._dtraceId) { + dtrace.fire('server-search-entry', function() { + var c = self.connection || {ldap: {}}; + return [ + self._dtraceId || 0, + (c.remoteAddress || ''), + c.ldap.bindDN ? c.ldap.bindDN.toString() : '', + (self.requestDN ? self.requestDN.toString() : ''), + entry.objectName.toString(), + entry.attributes.length, + ]; + }); + } } catch (e) { this.log.warn('%s failure to write message %j: %s', this.connection.ldap.id, this.json, e.toString()); diff --git a/lib/server.js b/lib/server.js index 8dd24bb..feadd07 100644 --- a/lib/server.js +++ b/lib/server.js @@ -195,12 +195,13 @@ function getArgumentsWithDTrace(args, op, cb1, cb2) { index = 1; args.splice(index, 0, function(req, res, next) { - dtrace.fire(op, function() { - var c = req.connection; + req._dtraceId = res._dtraceId = dtrace._nextId(); + res._dtraceOp = op; + dtrace.fire('server-' + res._dtraceOp + '-start', function() { return [ - req.logId, - c.remoteAddress, - c.ldap.bindDN.toString(), + res._dtraceId, + req.connection.remoteAddress, + req.connection.ldap.bindDN.toString(), req.dn.toString(), cb1 ? cb1(req, res) : undefined, cb2 ? cb2(req, res) : undefined @@ -311,7 +312,9 @@ function Server(options) { if (log.isTraceEnabled()) log.trace('new connection from %s', c.ldap.id); - dtrace.fire('connection', function() { return [c.remoteAddress]; }); + dtrace.fire('connection', function() { + return [c.remoteAddress]; + }); c.parser = new Parser({ log4js: options.log4js @@ -324,15 +327,6 @@ function Server(options) { if (log.isDebugEnabled()) log.debug('%s: message received: req=%j', c.ldap.id, req.json); - dtrace.fire('request', function() { - return [ - req.logId, - c.remoteAddress, - c.ldap.bindDN.toString(), - req.dn.toString() - ]; - }); - var res = getResponse(req); if (!res) { log.warn('Unimplemented server method: %s', req.type); @@ -601,7 +595,7 @@ Server.prototype.modify = function(name) { */ Server.prototype.modifyDN = function(name) { var args = getArgumentsWithDTrace(Array.prototype.slice.call(arguments, 1), - 'modifyDN', + 'modifydn', function(req, res) { return req.newRdn.toString(); },