Skip to content

Commit 3c80b42

Browse files
BenHuddlestontrondn
authored andcommitted
MB-30041: Complete client connection stats migration
Complete the migration of the client connection stats function to nlohmann::json by renaming the "overload" to the old name. Change-Id: Ia6dbb1ab162946936ca70f2c89db55adf8f6a0de Reviewed-on: http://review.couchbase.org/104148 Tested-by: Build Bot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent d1b23bf commit 3c80b42

File tree

9 files changed

+47
-71
lines changed

9 files changed

+47
-71
lines changed

programs/mcctl/mcctl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @param bio connection to the server.
4747
*/
4848
static int get_verbosity(MemcachedConnection& connection) {
49-
auto stats = connection.statsN("settings");
49+
auto stats = connection.stats("settings");
5050
if (stats) {
5151
auto verbosity = stats.find("verbosity");
5252
if (verbosity == stats.end()) {

programs/mcstat/mcstat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void request_stat(MemcachedConnection& connection,
3838
bool format) {
3939
try {
4040
if (json) {
41-
auto stats = connection.statsN(key);
41+
auto stats = connection.stats(key);
4242
std::cout << stats.dump(format ? 1 : -1, '\t') << std::endl;
4343
} else {
4444
connection.stats(

protocol/connection/client_connection.cc

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -587,29 +587,7 @@ void MemcachedConnection::read(Frame& frame, size_t bytes) {
587587
}
588588
}
589589

590-
unique_cJSON_ptr MemcachedConnection::stats(const std::string& subcommand) {
591-
unique_cJSON_ptr ret(cJSON_CreateObject());
592-
593-
for (auto& pair : statsMap(subcommand)) {
594-
const std::string& key = pair.first;
595-
const std::string& value = pair.second;
596-
if (value == "false") {
597-
cJSON_AddFalseToObject(ret.get(), key.c_str());
598-
} else if (value == "true") {
599-
cJSON_AddTrueToObject(ret.get(), key.c_str());
600-
} else {
601-
try {
602-
int64_t val = std::stoll(value);
603-
cJSON_AddNumberToObject(ret.get(), key.c_str(), val);
604-
} catch (...) {
605-
cJSON_AddStringToObject(ret.get(), key.c_str(), value.c_str());
606-
}
607-
}
608-
}
609-
return ret;
610-
}
611-
612-
nlohmann::json MemcachedConnection::statsN(const std::string& subcommand) {
590+
nlohmann::json MemcachedConnection::stats(const std::string& subcommand) {
613591
nlohmann::json ret;
614592

615593
for (auto& pair : statsMap(subcommand)) {

protocol/connection/client_connection.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "config.h"
2020

2121
#include <boost/optional/optional_fwd.hpp>
22-
#include <cJSON.h>
23-
#include <cJSON_utils.h>
2422
#include <engines/ewouldblock_engine/ewouldblock_engine.h>
2523
#include <memcached/engine_error.h>
2624
#include <memcached/openssl.h>
@@ -487,8 +485,7 @@ class MemcachedConnection {
487485
*/
488486
std::map<std::string, std::string> statsMap(const std::string& subcommand);
489487

490-
unique_cJSON_ptr stats(const std::string& subcommand);
491-
nlohmann::json statsN(const std::string& subcommand);
488+
nlohmann::json stats(const std::string& subcommand);
492489

493490
/**
494491
* Instruct the audit daemon to reload the configuration

protocol/connection/client_connection_map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include "client_connection.h"
20+
#include <cJSON_utils.h>
2021

2122
class ConnectionMap {
2223
public:

tests/testapp/testapp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ BinprotSubdocResponse TestappTest::getXattr(const std::string& path,
13111311
}
13121312

13131313
int TestappTest::getResponseCount(cb::mcbp::Status statusCode) {
1314-
auto stats = getConnection().statsN("responses detailed");
1314+
auto stats = getConnection().stats("responses detailed");
13151315
auto responses =
13161316
nlohmann::json::parse(stats["responses"].get<std::string>());
13171317
std::stringstream stream;

tests/testapp/testapp_bucket.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ TEST_P(BucketTest, MB19981TestDeleteWhileClientConnectedAndEWouldBlocked) {
245245
while (!deleting) {
246246
usleep(10); // Avoid busy-wait ;-)
247247
auto details = nlohmann::json::parse(
248-
connection->statsN("bucket_details")
248+
connection->stats("bucket_details")
249249
.begin()
250250
->get<std::string>());
251251
auto bucketDetails = details["buckets"];
@@ -325,7 +325,7 @@ TEST_P(BucketTest, MB19748TestDeleteWhileConnShipLogAndFullWriteBuffer) {
325325
std::this_thread::sleep_for(std::chrono::milliseconds(500))) {
326326
// Get stats for all connections, then locate this connection
327327
// - should be the one with dcp:true.
328-
auto all_stats = conn.statsN("connections");
328+
auto all_stats = conn.stats("connections");
329329
boost::optional<nlohmann::json> my_conn_stats;
330330

331331
for (const auto conn_str : all_stats) {
@@ -398,7 +398,7 @@ intptr_t getConnectionId(MemcachedConnection& conn) {
398398
const std::string agent_name{"getConnectionId 1.0"};
399399
conn.hello("getConnectionId", "1.0", "test connections test");
400400

401-
auto stats = conn.statsN("connections");
401+
auto stats = conn.stats("connections");
402402
if (stats.empty()) {
403403
throw std::runtime_error("getConnectionId: stats connections failed");
404404
}
@@ -434,7 +434,7 @@ int64_t getTotalSent(const nlohmann::json& payload) {
434434

435435
static nlohmann::json getConnectionStats(MemcachedConnection& conn,
436436
intptr_t id) {
437-
const auto stats = conn.statsN("connections " + std::to_string(id));
437+
const auto stats = conn.stats("connections " + std::to_string(id));
438438
if (stats.empty()) {
439439
throw std::runtime_error("getConnectionStats(): nothing returned");
440440
}

tests/testapp/testapp_hello.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ TEST_F(HelloTest, AgentName) {
5858
conn.executeCommand(cmd, resp);
5959
ASSERT_TRUE(resp.isSuccess());
6060

61-
auto stats = conn.statsN("connections");
61+
auto stats = conn.stats("connections");
6262
bool found = false;
6363

6464
// look over all of the entries and verify that it's set :)
@@ -89,7 +89,7 @@ TEST_F(HelloTest, JsonAgentInformation) {
8989
conn.executeCommand(cmd, resp);
9090
ASSERT_TRUE(resp.isSuccess());
9191

92-
auto stats = conn.statsN("connections");
92+
auto stats = conn.stats("connections");
9393
bool found = false;
9494

9595
// look over all of the entries and verify that it's set :)
@@ -134,7 +134,7 @@ TEST_F(HelloTest, JsonAgentInformationStringsTruncated) {
134134
conn.executeCommand(cmd, resp);
135135
ASSERT_TRUE(resp.isSuccess());
136136

137-
auto stats = conn.statsN("connections");
137+
auto stats = conn.stats("connections");
138138
bool found = false;
139139

140140
// look over all of the entries and verify that it's set :)

0 commit comments

Comments
 (0)