-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-51875: Add support for collecting metering data [2/n]
Add the skeleton for collecting metering information. Note that all commands implemented in the engine itself would need to update the cookie with the amount of data read / written It is "easy" to track the write path as a successful document write contains the WCU. We can't really use the bucket_get() methods for counting the RCU's as we do multiple of them and might not return the data to the user (also to implement retry logic on the server for dealing with cas conflicts) The intention with this patch is to get the infrastructure in place, so that we can fan out the work to: 1) Get the RCU/WCU pushed to prometheus 2) Create a spec on how to calculate the RCU/WCU for the various commands 3) Account for RCU and WCU for the various commands according to 2. Change-Id: I20d4b7779db95d73236c667255e232b09771f786 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/173672 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Dave Rigby <daver@couchbase.com>
- Loading branch information
Showing
16 changed files
with
182 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright 2022-Present Couchbase, Inc. | ||
* | ||
* Use of this software is governed by the Business Source License included | ||
* in the file licenses/BSL-Couchbase.txt. As of the Change Date specified | ||
* in that file, in accordance with the Business Source License, use of this | ||
* software will be governed by the Apache License, Version 2.0, included in | ||
* the file licenses/APL2.txt. | ||
*/ | ||
|
||
#include "testapp.h" | ||
#include "testapp_client_test.h" | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <protocol/connection/frameinfo.h> | ||
|
||
class ElixirTest : public TestappXattrClientTest { | ||
public: | ||
/// Calculate the number of compute units the provided value should occupy | ||
std::size_t calc_num_cu(std::size_t val) { | ||
return val / 1024 + (val % 1024 ? 1 : 0); | ||
} | ||
|
||
protected: | ||
std::pair<std::size_t, std::size_t> getComputeUnits() { | ||
std::size_t rcu = 0, wcu = 0; | ||
bool found = false; | ||
|
||
adminConnection->stats( | ||
[this, &rcu, &wcu, &found](const auto& k, const auto& v) { | ||
if (!v.empty()) { | ||
auto json = nlohmann::json::parse(v); | ||
for (nlohmann::json& bucket : json["buckets"]) { | ||
if (bucket["name"] == bucketName) { | ||
rcu = bucket["rcu"].get<std::size_t>(); | ||
wcu = bucket["wcu"].get<std::size_t>(); | ||
found = true; | ||
} | ||
} | ||
} | ||
}, | ||
"bucket_details"); | ||
if (found) { | ||
return {rcu, wcu}; | ||
} | ||
throw std::runtime_error("getComputeUnits(): Bucket not found"); | ||
} | ||
|
||
/// Execute a command and verify that RCU and WCU was updated to the | ||
/// correct values | ||
void execute(std::function<std::pair<std::size_t, std::size_t>()> command, | ||
const char* message) { | ||
const auto [pre_rcu, pre_wcu] = getComputeUnits(); | ||
auto [rcu, wcu] = command(); | ||
const auto [post_rcu, post_wcu] = getComputeUnits(); | ||
EXPECT_EQ(pre_rcu + rcu, post_rcu) | ||
<< "Expected " << message << " to increase RCU with " << rcu; | ||
EXPECT_EQ(pre_wcu + wcu, post_wcu) | ||
<< "Expected " << message << " to increase WCU with " << wcu; | ||
} | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
TransportProtocols, | ||
ElixirTest, | ||
::testing::Combine(::testing::Values(TransportProtocols::McbpSsl), | ||
::testing::Values(XattrSupport::Yes), | ||
::testing::Values(ClientJSONSupport::Yes), | ||
::testing::Values(ClientSnappySupport::Yes)), | ||
PrintToStringCombinedName()); | ||
|
||
TEST_P(ElixirTest, TestAddGet) { | ||
const auto ncu = calc_num_cu(document.value.size()); | ||
execute( | ||
[ncu, this]() -> std::pair<std::size_t, std::size_t> { | ||
userConnection->mutate(document, Vbid{0}, MutationType::Add); | ||
return {0, ncu}; | ||
}, | ||
"ADD"); | ||
|
||
execute( | ||
[ncu, this]() -> std::pair<std::size_t, std::size_t> { | ||
userConnection->get(document.info.id, Vbid{0}); | ||
return {ncu, 0}; | ||
}, | ||
"GET"); | ||
} | ||
|
||
// @todo add more tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters