acelyc111 commented on code in PR #1873:
URL: 
https://github.com/apache/incubator-pegasus/pull/1873#discussion_r1470671588


##########
src/runtime/rpc/dns_resolver.cpp:
##########
@@ -19,27 +19,52 @@
 
 #include <algorithm>
 #include <memory>
+#include <set>
 #include <utility>
 
+#include "absl/strings/string_view.h"
+#include "fmt/core.h"
 #include "fmt/format.h"
 #include "runtime/rpc/dns_resolver.h"
 #include "runtime/rpc/group_address.h"
 #include "runtime/rpc/group_host_port.h"
+#include "utils/autoref_ptr.h"
 #include "utils/fmt_logging.h"
 
+METRIC_DEFINE_gauge_int64(server,
+                          dns_resolver_cache_size,
+                          dsn::metric_unit::kKeys,
+                          "The size of the host_port to rpc_address resolve 
results cache");
+
+METRIC_DEFINE_percentile_int64(
+    server,
+    dns_resolver_resolve_duration_ns,
+    dsn::metric_unit::kNanoSeconds,
+    "The duration of resolving a host port, may either get from cache or 
resolve by DNS lookup");
+
+METRIC_DEFINE_percentile_int64(server,
+                               dns_resolver_resolve_by_dns_duration_ns,
+                               dsn::metric_unit::kNanoSeconds,
+                               "The duration of resolving a host port by DNS 
lookup");
 namespace dsn {
 
-void dns_resolver::add_item(const host_port &hp, const rpc_address &addr)
+dns_resolver::dns_resolver()
+    : METRIC_VAR_INIT_server(dns_resolver_cache_size),
+      METRIC_VAR_INIT_server(dns_resolver_resolve_duration_ns),
+      METRIC_VAR_INIT_server(dns_resolver_resolve_by_dns_duration_ns)
 {
-    utils::auto_write_lock l(_lock);
-    _dsn_cache.insert(std::make_pair(hp, addr));
+#ifndef MOCK_TEST
+    static int only_one_instance = 0;

Review Comment:
   I don't think singleton is good design, it's lifetime and ownership is 
confused, I'd prefer to use common object rather than singleton unless it's 
imposiible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to