masaori335 commented on code in PR #10694:
URL: https://github.com/apache/trafficserver/pull/10694#discussion_r1385878893


##########
src/proxy/http/PreWarmManager.cc:
##########
@@ -1122,48 +1133,64 @@ PreWarmManager::_parse_sni_conf(PreWarm::ParsedSNIConf 
&parsed_conf, const SNICo
    Create stats per pool.
    Registered stats id is stored in _stat_id_map.
  */
+
+// This is a little helper, since this is reused twice for making counters and 
gauges
+void
+_makeName(const PreWarm::SPtrConstDst &dst, std::string_view statname, char 
*name, size_t namesize)
+{
+  if (dst->alpn_index != SessionProtocolNameRegistry::INVALID) {
+    std::string_view alpn_name = alpn_name_for_stat(dst->alpn_index);
+
+    snprintf(name, namesize, "%s.%.*s:%d.tls.%s.%s", STAT_NAME_PREFIX.data(), 
static_cast<int>(dst->host.size()), dst->host.data(),
+             dst->port, alpn_name.data(), statname.data());
+  } else {
+    snprintf(name, namesize, "%s.%.*s:%d.%s.%s", STAT_NAME_PREFIX.data(), 
static_cast<int>(dst->host.size()), dst->host.data(),
+             dst->port, (dst->type == SNIRoutingType::PARTIAL_BLIND) ? "tls" : 
"tcp", statname.data());
+  }
+}
+
 void
 PreWarmManager::_register_stats(const PreWarm::ParsedSNIConf &parsed_conf)
 {
   int stats_counter = 0;
 
-  ts::Metrics &intm = ts::Metrics::getInstance();
-
   for (auto &entry : parsed_conf) {
     const PreWarm::SPtrConstDst &dst = entry.first;
-
     PreWarm::StatsIds ids;
-    for (int j = 0; j < static_cast<int>(PreWarm::Stat::LAST_ENTRY); ++j) {
+    auto &[counters, gauges] = ids;
+
+    // First the Counters
+    for (int j = 0; j < static_cast<int>(PreWarm::CounterStat::LAST_ENTRY); 
++j) {
       char name[STAT_NAME_BUF_LEN];
 
-      if (dst->alpn_index != SessionProtocolNameRegistry::INVALID) {
-        std::string_view alpn_name = alpn_name_for_stat(dst->alpn_index);
+      _makeName(dst, COUNTER_STAT_ENTRIES[j], name, sizeof(name));
+
+      auto metric = Metrics::Counter::createPtr(name); // This will do a 
lookup if it already exists

Review Comment:
   This looks much convenient 👍



##########
src/proxy/http/PreWarmManager.cc:
##########
@@ -1122,48 +1133,64 @@ PreWarmManager::_parse_sni_conf(PreWarm::ParsedSNIConf 
&parsed_conf, const SNICo
    Create stats per pool.
    Registered stats id is stored in _stat_id_map.
  */
+
+// This is a little helper, since this is reused twice for making counters and 
gauges
+void
+_makeName(const PreWarm::SPtrConstDst &dst, std::string_view statname, char 
*name, size_t namesize)
+{
+  if (dst->alpn_index != SessionProtocolNameRegistry::INVALID) {
+    std::string_view alpn_name = alpn_name_for_stat(dst->alpn_index);
+
+    snprintf(name, namesize, "%s.%.*s:%d.tls.%s.%s", STAT_NAME_PREFIX.data(), 
static_cast<int>(dst->host.size()), dst->host.data(),
+             dst->port, alpn_name.data(), statname.data());
+  } else {
+    snprintf(name, namesize, "%s.%.*s:%d.%s.%s", STAT_NAME_PREFIX.data(), 
static_cast<int>(dst->host.size()), dst->host.data(),
+             dst->port, (dst->type == SNIRoutingType::PARTIAL_BLIND) ? "tls" : 
"tcp", statname.data());
+  }
+}
+
 void
 PreWarmManager::_register_stats(const PreWarm::ParsedSNIConf &parsed_conf)
 {
   int stats_counter = 0;
 
-  ts::Metrics &intm = ts::Metrics::getInstance();
-
   for (auto &entry : parsed_conf) {
     const PreWarm::SPtrConstDst &dst = entry.first;
-
     PreWarm::StatsIds ids;
-    for (int j = 0; j < static_cast<int>(PreWarm::Stat::LAST_ENTRY); ++j) {
+    auto &[counters, gauges] = ids;
+
+    // First the Counters
+    for (int j = 0; j < static_cast<int>(PreWarm::CounterStat::LAST_ENTRY); 
++j) {
       char name[STAT_NAME_BUF_LEN];
 
-      if (dst->alpn_index != SessionProtocolNameRegistry::INVALID) {
-        std::string_view alpn_name = alpn_name_for_stat(dst->alpn_index);
+      _makeName(dst, COUNTER_STAT_ENTRIES[j], name, sizeof(name));
+
+      auto metric = Metrics::Counter::createPtr(name); // This will do a 
lookup if it already exists

Review Comment:
   This looks much convenient 👍



-- 
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: github-unsubscr...@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to