summaryrefslogtreecommitdiff
path: root/src/mongo/db/clientlistplugin.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-10-27 08:41:54 -0400
committerEliot Horowitz <eliot@10gen.com>2014-10-27 08:41:54 -0400
commit1efcb9b092f218178bbc78ca4bf5f7c1a720ffb8 (patch)
tree93923726e168616c2d41d1170b18e1aa51fa3980 /src/mongo/db/clientlistplugin.cpp
parentf863b0bf23bd2a0c573f0a3cfbf603a492f1741d (diff)
downloadmongo-1efcb9b092f218178bbc78ca4bf5f7c1a720ffb8.tar.gz
SERVER-15683: add optional filter to currentOpCtx command
Diffstat (limited to 'src/mongo/db/clientlistplugin.cpp')
-rw-r--r--src/mongo/db/clientlistplugin.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/mongo/db/clientlistplugin.cpp b/src/mongo/db/clientlistplugin.cpp
index 3300e2b5d22..a1b7abb373e 100644
--- a/src/mongo/db/clientlistplugin.cpp
+++ b/src/mongo/db/clientlistplugin.cpp
@@ -33,12 +33,12 @@
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
#include "mongo/db/global_environment_experiment.h"
+#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/dbwebserver.h"
#include "mongo/util/mongoutils/html.h"
#include "mongo/util/stringutils.h"
-
namespace mongo {
class OperationsDataBuilder : public GlobalEnvironmentExperiment::ProcessOperationContext {
@@ -122,6 +122,10 @@ namespace {
class CommandHelper : public GlobalEnvironmentExperiment::ProcessOperationContext {
public:
+ CommandHelper( MatchExpression* me )
+ : matcher( me ) {
+ }
+
virtual void processOpContext(OperationContext* txn) {
BSONObjBuilder b;
if ( txn->getClient() )
@@ -136,15 +140,25 @@ namespace {
}
if ( txn->recoveryUnit() )
txn->recoveryUnit()->reportState( &b );
- array.append( b.obj() );
+
+ BSONObj obj = b.obj();
+
+ if ( matcher && !matcher->matchesBSON( obj ) ) {
+ return;
+ }
+
+ array.append( obj );
}
BSONArrayBuilder array;
+ MatchExpression* matcher;
};
class CurrentOpContexts : public Command {
public:
- CurrentOpContexts() : Command( "currentOpCtx" ) { }
+ CurrentOpContexts()
+ : Command( "currentOpCtx" ) {
+ }
virtual bool isWriteCommandForConfigServer() const { return false; }
@@ -158,13 +172,24 @@ namespace {
BSONObjBuilder& result,
bool fromRepl) {
- CommandHelper helper;
+ scoped_ptr<MatchExpression> filter;
+ if ( cmdObj["filter"].isABSONObj() ) {
+ StatusWithMatchExpression res =
+ MatchExpressionParser::parse( cmdObj["filter"].Obj() );
+ if ( !res.isOK() ) {
+ return appendCommandStatus( result, res.getStatus() );
+ }
+ filter.reset( res.getValue() );
+ }
+
+ CommandHelper helper( filter.get() );
getGlobalEnvironment()->forEachOperationContext(&helper);
result.appendArray( "operations", helper.array.arr() );
return true;
}
+
} currentOpContexts;
} // namespace