DTrace rework
This commit is contained in:
parent
caf258a4f7
commit
fe8294319c
|
@ -7,47 +7,65 @@ var dtrace = require('dtrace-provider');
|
|||
///--- Globals
|
||||
|
||||
var SERVER_PROVIDER;
|
||||
var DTRACE_ID = 0;
|
||||
var MAX_INT = 4294967295;
|
||||
|
||||
/* Args:
|
||||
* 0 -> RequestId (<ip>:<src port>:<msgID>)
|
||||
* 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;
|
||||
|
|
|
@ -6,6 +6,7 @@ var LDAPResult = require('./result');
|
|||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function AddResponse(options) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ var LDAPResult = require('./result');
|
|||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function CompareResponse(options) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue