DTrace rework

This commit is contained in:
Mark Cavage 2011-11-15 10:49:23 -08:00
parent caf258a4f7
commit fe8294319c
7 changed files with 87 additions and 46 deletions

View File

@ -7,47 +7,65 @@ var dtrace = require('dtrace-provider');
///--- Globals ///--- Globals
var SERVER_PROVIDER; var SERVER_PROVIDER;
var DTRACE_ID = 0;
var MAX_INT = 4294967295;
/* Args: /* Args:
* 0 -> RequestId (<ip>:<src port>:<msgID>) * server-*-start:
* 0 -> id
* 1 -> remoteIP * 1 -> remoteIP
* 2 -> bindDN * 2 -> bindDN
* 3 -> req.dn * 3 -> req.dn
* 4,5 -> op specific * 4,5 -> op specific
*
* server-*-done:
* 0 -> id
* 1 -> remoteIp
* 2 -> bindDN
* 3 -> requsetDN
* 4 -> status
* 5 -> errorMessage
*
*/ */
var SERVER_PROBES = { var SERVER_PROBES = {
// 4: attributes.length // 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 // 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 // 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 // 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 // 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 // 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 // remote IP
connection: ['char *'], 'server-connection': ['char *'],
request: ['char *', 'char *', 'char *', 'char *'],
// requestId, remoteIp, bindDN, request.dn, statusCode, errorMessage
response: ['char *', 'char *', 'char *', 'char *', 'int', 'char *']
}; };
@ -65,6 +83,13 @@ module.exports = function() {
}); });
SERVER_PROVIDER.enable(); SERVER_PROVIDER.enable();
SERVER_PROVIDER._nextId = function() {
if (DTRACE_ID === MAX_INT)
DTRACE_ID = 0;
return ++DTRACE_ID;
};
} }
return SERVER_PROVIDER; return SERVER_PROVIDER;

View File

@ -6,6 +6,7 @@ var LDAPResult = require('./result');
var Protocol = require('../protocol'); var Protocol = require('../protocol');
///--- API ///--- API
function AddResponse(options) { function AddResponse(options) {

View File

@ -6,6 +6,7 @@ var LDAPResult = require('./result');
var Protocol = require('../protocol'); var Protocol = require('../protocol');
///--- API ///--- API
function BindResponse(options) { function BindResponse(options) {
@ -21,3 +22,4 @@ function BindResponse(options) {
} }
util.inherits(BindResponse, LDAPResult); util.inherits(BindResponse, LDAPResult);
module.exports = BindResponse; module.exports = BindResponse;

View File

@ -6,6 +6,7 @@ var LDAPResult = require('./result');
var Protocol = require('../protocol'); var Protocol = require('../protocol');
///--- API ///--- API
function CompareResponse(options) { function CompareResponse(options) {

View File

@ -5,10 +5,10 @@ var util = require('util');
var asn1 = require('asn1'); var asn1 = require('asn1');
var LDAPMessage = require('./message');
var Protocol = require('../protocol');
var dtrace = require('../dtrace'); var dtrace = require('../dtrace');
var LDAPMessage = require('./message');
var Protocol = require('../protocol');
///--- Globals ///--- Globals
@ -72,17 +72,20 @@ LDAPResult.prototype.end = function(status) {
var self = this; var self = this;
this.connection.write(ber); this.connection.write(ber);
dtrace.fire('response', function() { if (self._dtraceOp && self._dtraceId) {
var c = self.connection || {ldap: {bindDN: ''}}; dtrace.fire('server-' + self._dtraceOp + '-done', function() {
var c = self.connection || {ldap: {}};
return [ return [
(self.logId || ''), self._dtraceId || 0,
(c.remoteAddress || ''), (c.remoteAddress || ''),
c.ldap.bindDN.toString(), c.ldap.bindDN ? c.ldap.bindDN.toString() : '',
(self.requestDN ? self.requestDN.toString() : ''), (self.requestDN ? self.requestDN.toString() : ''),
self.status, status || self.status,
self.errorMessage self.errorMessage
]; ];
}); });
}
} catch (e) { } catch (e) {
this.log.warn('%s failure to write message %j: %s', this.log.warn('%s failure to write message %j: %s',
this.connection.ldap.id, this.json, e.toString()); this.connection.ldap.id, this.json, e.toString());

View File

@ -7,6 +7,7 @@ var LDAPResult = require('./result');
var SearchEntry = require('./search_entry'); var SearchEntry = require('./search_entry');
var SearchReference = require('./search_reference'); var SearchReference = require('./search_reference');
var dtrace = require('../dtrace');
var parseDN = require('../dn').parse; var parseDN = require('../dn').parse;
var parseURL = require('../url').parse; var parseURL = require('../url').parse;
var Protocol = require('../protocol'); var Protocol = require('../protocol');
@ -87,6 +88,20 @@ SearchResponse.prototype.send = function(entry, nofiltering) {
this.connection.write(entry.toBer()); this.connection.write(entry.toBer());
this.sentEntries++; 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) { } catch (e) {
this.log.warn('%s failure to write message %j: %s', this.log.warn('%s failure to write message %j: %s',
this.connection.ldap.id, this.json, e.toString()); this.connection.ldap.id, this.json, e.toString());

View File

@ -195,12 +195,13 @@ function getArgumentsWithDTrace(args, op, cb1, cb2) {
index = 1; index = 1;
args.splice(index, 0, function(req, res, next) { args.splice(index, 0, function(req, res, next) {
dtrace.fire(op, function() { req._dtraceId = res._dtraceId = dtrace._nextId();
var c = req.connection; res._dtraceOp = op;
dtrace.fire('server-' + res._dtraceOp + '-start', function() {
return [ return [
req.logId, res._dtraceId,
c.remoteAddress, req.connection.remoteAddress,
c.ldap.bindDN.toString(), req.connection.ldap.bindDN.toString(),
req.dn.toString(), req.dn.toString(),
cb1 ? cb1(req, res) : undefined, cb1 ? cb1(req, res) : undefined,
cb2 ? cb2(req, res) : undefined cb2 ? cb2(req, res) : undefined
@ -311,7 +312,9 @@ function Server(options) {
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace('new connection from %s', c.ldap.id); 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({ c.parser = new Parser({
log4js: options.log4js log4js: options.log4js
@ -324,15 +327,6 @@ function Server(options) {
if (log.isDebugEnabled()) if (log.isDebugEnabled())
log.debug('%s: message received: req=%j', c.ldap.id, req.json); 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); var res = getResponse(req);
if (!res) { if (!res) {
log.warn('Unimplemented server method: %s', req.type); log.warn('Unimplemented server method: %s', req.type);
@ -601,7 +595,7 @@ Server.prototype.modify = function(name) {
*/ */
Server.prototype.modifyDN = function(name) { Server.prototype.modifyDN = function(name) {
var args = getArgumentsWithDTrace(Array.prototype.slice.call(arguments, 1), var args = getArgumentsWithDTrace(Array.prototype.slice.call(arguments, 1),
'modifyDN', 'modifydn',
function(req, res) { function(req, res) {
return req.newRdn.toString(); return req.newRdn.toString();
}, },