You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/07/26 08:50:24 UTC

[rocketmq-clients] branch cpp_dev created (now 319d18f)

This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a change to branch cpp_dev
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


      at 319d18f  Extract metric service endpoint parsing

This branch includes the following new commits:

     new 319d18f  Extract metric service endpoint parsing

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[rocketmq-clients] 01/01: Extract metric service endpoint parsing

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch cpp_dev
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git

commit 319d18fb4a9cd87ad593949f7593239237067f0c
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Tue Jul 26 16:49:37 2022 +0800

    Extract metric service endpoint parsing
---
 cpp/source/rocketmq/ClientImpl.cpp       | 44 ++++++++++++++++++--------------
 cpp/source/rocketmq/include/ClientImpl.h |  2 ++
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/cpp/source/rocketmq/ClientImpl.cpp b/cpp/source/rocketmq/ClientImpl.cpp
index b90035e..d47133a 100644
--- a/cpp/source/rocketmq/ClientImpl.cpp
+++ b/cpp/source/rocketmq/ClientImpl.cpp
@@ -179,19 +179,35 @@ void ClientImpl::start() {
   telemetry_handle_ = client_manager_->getScheduler()->schedule(telemetry_functor, TELEMETRY_TASK_NAME,
                                                                 std::chrono::minutes(5), std::chrono::minutes(5));
 
+  auto&& metric_service_endpoint = metricServiceEndpoint();
+  if (!metric_service_endpoint.empty()) {
+    std::weak_ptr<Client> client_weak_ptr(self());
+#ifdef DEBUG_METRIC_EXPORTING
+    opencensus::stats::StatsExporter::SetInterval(absl::Seconds(1));
+    opencensus::stats::StatsExporter::RegisterPushHandler(absl::make_unique<StdoutHandler>());
+#else
+    opencensus::stats::StatsExporter::SetInterval(absl::Minutes(1));
+#endif
+    SPDLOG_INFO("Export client metrics to {}", metric_service_endpoint);
+    opencensus::stats::StatsExporter::RegisterPushHandler(
+        absl::make_unique<OpencensusHandler>(metric_service_endpoint, client_weak_ptr));
+  }
+}
+
+std::string ClientImpl::metricServiceEndpoint() const {
   auto endpoints = client_config_.metric.endpoints;
-  std::string target;
+  std::string service_endpoint;
   switch (endpoints.scheme()) {
     case rmq::AddressScheme::IPv4: {
-      target.append("ipv4:");
+      service_endpoint.append("ipv4:");
       break;
     }
     case rmq::AddressScheme::IPv6: {
-      target.append("ipv6:");
+      service_endpoint.append("ipv6:");
       break;
     }
     case rmq::AddressScheme::DOMAIN_NAME: {
-      target.append("dns:");
+      service_endpoint.append("dns:");
       break;
     }
     default: {
@@ -202,25 +218,15 @@ void ClientImpl::start() {
   bool first = true;
   for (const auto& address : endpoints.addresses()) {
     if (!first) {
-      target.push_back(',');
+      service_endpoint.push_back(',');
     } else {
       first = false;
     }
-    target.append(address.host());
-    target.push_back(':');
-    target.append(std::to_string(address.port()));
+    service_endpoint.append(address.host());
+    service_endpoint.push_back(':');
+    service_endpoint.append(std::to_string(address.port()));
   }
-
-  std::weak_ptr<Client> client_weak_ptr(self());
-
-#ifdef DEBUG_METRIC_EXPORTING
-  opencensus::stats::StatsExporter::SetInterval(absl::Seconds(1));
-  opencensus::stats::StatsExporter::RegisterPushHandler(absl::make_unique<StdoutHandler>());
-#else
-  opencensus::stats::StatsExporter::SetInterval(absl::Minutes(1));
-#endif
-  SPDLOG_INFO("Export client metrics to {}", target);
-  opencensus::stats::StatsExporter::RegisterPushHandler(absl::make_unique<OpencensusHandler>(target, client_weak_ptr));
+  return service_endpoint;
 }
 
 void ClientImpl::shutdown() {
diff --git a/cpp/source/rocketmq/include/ClientImpl.h b/cpp/source/rocketmq/include/ClientImpl.h
index 2a06a0f..f0b29f7 100644
--- a/cpp/source/rocketmq/include/ClientImpl.h
+++ b/cpp/source/rocketmq/include/ClientImpl.h
@@ -229,6 +229,8 @@ private:
   void doVerify(std::string target, std::string command_id, MessageConstPtr message);
 
   static std::string clientId();
+
+  std::string metricServiceEndpoint() const;
 };
 
 ROCKETMQ_NAMESPACE_END
\ No newline at end of file