<commit_before>/* logger_metrics_interface.cc
   <NAME>, 21 May 2013
   Copyright (c) 2013 Datacratic.  All rights reserved.
*/

#include "mongo/bson/bson.h"
#include "mongo/util/net/hostandport.h"
#include "jml/utils/string_functions.h"
#include "logger_metrics_mongo.h"
#include "soa/utils/mongo_init.h"


using namespace std;
using namespace mongo;
using namespace Datacratic;


/****************************************************************************/
/* LOGGER METRICS MONGO                                                     */
/****************************************************************************/

LoggerMetricsMongo::
LoggerMetricsMongo(Json::Value config, const string & coll,
                   const string & appName)
    : ILoggerMetrics(coll)
{
    for (const string & s: {"hostAndPort", "database", "user", "pwd"}) {
        if (config[s].isNull()) {
            throw ML::Exception("Missing LoggerMetricsMongo parameter [%s]",
                                s.c_str());
        }
    }

    vector<string> hapStrs = ML::split(config["hostAndPort"].asString(), ',');
    if (hapStrs.size() > 1) {
        vector<HostAndPort> haps;
        for (const string & hapStr: hapStrs) {
            haps.emplace_back(hapStr);
        }
        conn.reset(new mongo::DBClientReplicaSet(hapStrs[0], haps, 100));
    }
    else {
        auto tmpConn = make_shared<DBClientConnection>();
        tmpConn->connect(hapStrs[0]);
        conn = tmpConn;
    }
    db = config["database"].asString();

    auto impl = [&] (string mechanism) {
        BSONObj b = BSON("user" << config["user"].asString()
                  << "pwd" << config["pwd"].asString()
                  << "mechanism" << mechanism
                  << "db" << db);

        try {
            JML_TRACE_EXCEPTIONS(false);
            conn->auth(b);
        }
        catch (const UserException & _) {
            return false;
        }
        return true;<commit_msg>logger_metrics_mongo: do not register the replica set id as a server<commit_after>/* logger_metrics_interface.cc
   <NAME>, 21 May 2013
   Copyright (c) 2013 Datacratic.  All rights reserved.
*/

#include "mongo/bson/bson.h"
#include "mongo/util/net/hostandport.h"
#include "jml/utils/string_functions.h"
#include "logger_metrics_mongo.h"
#include "soa/utils/mongo_init.h"


using namespace std;
using namespace mongo;
using namespace Datacratic;


/****************************************************************************/
/* LOGGER METRICS MONGO                                                     */
/****************************************************************************/

LoggerMetricsMongo::
LoggerMetricsMongo(Json::Value config, const string & coll,
                   const string & appName)
    : ILoggerMetrics(coll)
{
    for (const string & s: {"hostAndPort", "database", "user", "pwd"}) {
        if (config[s].isNull()) {
            throw ML::Exception("Missing LoggerMetricsMongo parameter [%s]",
                                s.c_str());
        }
    }

    vector<string> hapStrs = ML::split(config["hostAndPort"].asString(), ',');
    if (hapStrs.size() > 1) {
        /* The 1st entry is the replica set id, followed by the member
           servers. */
        vector<HostAndPort> haps;
        for (int i = 1; i < hapStrs.size(); i++) {
            haps.emplace_back(hapStrs[i]);
        }
        conn.reset(new mongo::DBClientReplicaSet(hapStrs[0], haps, 100));
    }
    else {
        auto tmpConn = make_shared<DBClientConnection>();
        tmpConn->connect(hapStrs[0]);
        conn = tmpConn;
    }
    db = config["database"].asString();

    auto impl = [&] (string mechanism) {
        BSONObj b = BSON("user" << config["user"].asString()
                  << "pwd" << config["pwd"].asString()
                  << "mechanism" << mechanism
                  << "db" << db);

        try {
            JML_TRACE_EXCEPTIONS(false);
            conn->auth(b);
        }
        catch (const UserException & _) {
            return false;
        }
        return true;
{'fraction_non_alphanumeric': 0.20309810671256454, 'fraction_numerical': 0.008359970494221785, 'mean_word_length': 2.3344262295081966, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285305', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1169, 'n_words': 248}