Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat(op-msg): add support for OP_MSG to command monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 12, 2019
1 parent c81f609 commit 9124b67
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions lib/connection/apm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const Query = require('../connection/commands').Query;
// const Query = require('../connection/commands').Query;
const Msg = require('../connection/msg').Msg;
const KillCursor = require('../connection/commands').KillCursor;
const GetMore = require('../connection/commands').GetMore;
const calculateDurationInMs = require('../utils').calculateDurationInMs;
Expand All @@ -18,7 +19,7 @@ const SENSITIVE_COMMANDS = new Set([
]);

// helper methods
const extractCommandName = command => Object.keys(command)[0];
const extractCommandName = commandDoc => Object.keys(commandDoc)[0];
const namespace = command => command.ns;
const databaseName = command => command.ns.split('.')[0];
const collectionName = command => command.ns.split('.')[1];
Expand Down Expand Up @@ -76,41 +77,44 @@ const extractCommand = command => {
};
}

command = command instanceof Query ? command.query : command.command;
if (command.$query == null) {
return command;
if (command instanceof Msg) {
return command.command;
}

let result;
if (command.ns === 'admin.$cmd') {
// upconvert legacy command
result = Object.assign({}, command.query.$query);
} else {
// upconvert legacy find command
result = { find: collectionName(command) };
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
if (typeof command.query[key] !== 'undefined')
result[LEGACY_FIND_QUERY_MAP[key]] = command.query[key];
if (command.query && command.query.$query) {
let result;
if (command.ns === 'admin.$cmd') {
// upconvert legacy command
result = Object.assign({}, command.query.$query);
} else {
// upconvert legacy find command
result = { find: collectionName(command) };
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
if (typeof command.query[key] !== 'undefined')
result[LEGACY_FIND_QUERY_MAP[key]] = command.query[key];
});
}

Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach(key => {
if (typeof command[key] !== 'undefined') result[LEGACY_FIND_OPTIONS_MAP[key]] = command[key];
});
}

Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach(key => {
if (typeof command[key] !== 'undefined') result[LEGACY_FIND_OPTIONS_MAP[key]] = command[key];
});
OP_QUERY_KEYS.forEach(key => {
if (command[key]) result[key] = command[key];
});

OP_QUERY_KEYS.forEach(key => {
if (command[key]) result[key] = command[key];
});
if (typeof command.pre32Limit !== 'undefined') {
result.limit = command.pre32Limit;
}

if (typeof command.pre32Limit !== 'undefined') {
result.limit = command.pre32Limit;
}
if (command.query.$explain) {
return { explain: result };
}

if (command.query.$explain) {
return { explain: result };
return result;
}

return result;
return command.query ? command.query : command;
};

const extractReply = (command, reply) => {
Expand Down

0 comments on commit 9124b67

Please sign in to comment.