Skip to content

Commit 47e8847

Browse files
authored
CXXCBC-626: App Telemetry (#712)
1 parent 24dca97 commit 47e8847

37 files changed

+3398
-165
lines changed

.cppcheck_suppressions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ unusedFunction:*
1919
unusedStructMember:*
2020
unusedVariable:*
2121
useStlAlgorithm:*
22+
unusedPrivateFunction:*
2223

2324
# these are not very useful
2425
checkersReport:*
@@ -34,3 +35,4 @@ variableScope:*/test/test_*
3435

3536
# do not scan third-party code
3637
*:*/_deps/*
38+

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ set(couchbase_cxx_client_FILES
438438
core/utils/split_string.cxx
439439
core/utils/url_codec.cxx
440440
core/view_query_options.cxx
441+
core/websocket_codec.cxx
442+
core/app_telemetry_address.cxx
443+
core/app_telemetry_meter.cxx
444+
core/app_telemetry_reporter.cxx
445+
core/cluster_credentials.cxx
441446
)
442447

443448
set(couchbase_cxx_client_LIBRARIES)

core/app_telemetry_address.cxx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2024-Present Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6+
* except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#include "app_telemetry_address.hxx"
17+
18+
#include "topology/configuration.hxx"
19+
20+
#include <algorithm>
21+
#include <random>
22+
23+
namespace couchbase::core
24+
{
25+
auto
26+
get_app_telemetry_addresses(const topology::configuration& config,
27+
bool use_tls,
28+
const std::string& network) -> std::vector<app_telemetry_address>
29+
{
30+
std::vector<app_telemetry_address> addresses;
31+
addresses.reserve(config.nodes.size());
32+
for (const auto& node : config.nodes) {
33+
if (auto app_telemetry_path = node.app_telemetry_path; app_telemetry_path) {
34+
auto node_uuid = node.node_uuid;
35+
if (node_uuid.empty()) {
36+
continue;
37+
}
38+
39+
if (auto port = node.port_or(network, service_type::management, use_tls, 0); port != 0) {
40+
addresses.push_back({
41+
node.hostname_for(network),
42+
std::to_string(port),
43+
app_telemetry_path.value(),
44+
node_uuid,
45+
});
46+
}
47+
}
48+
}
49+
50+
static thread_local std::default_random_engine gen{ std::random_device{}() };
51+
std::shuffle(addresses.begin(), addresses.end(), gen);
52+
return addresses;
53+
}
54+
55+
} // namespace couchbase::core

core/app_telemetry_address.hxx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2024-Present Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
6+
* except in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
* ANY KIND, either express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#pragma once
17+
18+
#include <string>
19+
#include <vector>
20+
21+
namespace couchbase::core
22+
{
23+
namespace topology
24+
{
25+
struct configuration;
26+
} // namespace topology
27+
28+
struct app_telemetry_address {
29+
std::string hostname;
30+
std::string service;
31+
std::string path;
32+
std::string host_uuid;
33+
};
34+
35+
auto
36+
get_app_telemetry_addresses(const topology::configuration& config,
37+
bool use_tls,
38+
const std::string& network) -> std::vector<app_telemetry_address>;
39+
} // namespace couchbase::core

0 commit comments

Comments
 (0)