Copilot commented on code in PR #13505:
URL: https://github.com/apache/trafficserver/pull/13505#discussion_r3771312217


##########
src/records/RecCore.cc:
##########
@@ -612,6 +612,27 @@ RecLookupMatchingRecords(unsigned rec_type, const char 
*match, void (*callback)(
     });
   }
 
+  if (rec_type & RECT_HIDDEN_METRIC) {
+    // Opt-in only: hidden metrics are never reachable through RECT_ALL, see 
RecDefs.h.
+    for (auto &&[name, type, val] : ts::Metrics::hidden_instance()) {
+      if (regex.exec(name.data())) {
+        RecRecord tmp;
+
+        // Tag both bits so that a caller asking only for RECT_HIDDEN_METRIC 
passes the rec_type
+        // check the lookup callback applies to every record it is handed. 
Note this combination
+        // satisfies neither REC_TYPE_IS_STAT nor REC_TYPE_IS_CONFIG (both 
compare for equality),
+        // so the YAML encoder emits no stat_meta block for hidden metrics. 
That is intentional:
+        // the meta fields of this synthetic record were never populated.
+        tmp.rec_type = static_cast<RecT>(RECT_PROCESS | RECT_HIDDEN_METRIC);
+
+        tmp.name         = name.data();
+        tmp.data_type    = type == ts::Metrics::MetricType::COUNTER ? 
RECD_COUNTER : RECD_INT;
+        tmp.data.rec_int = val;
+        callback(&tmp, data);

Review Comment:
   RecLookupMatchingRecords builds a synthetic RecRecord for hidden metrics, 
but leaves several fields (version/registered/order/rsb_id and data_default) 
uninitialized. The JSONRPC YAML encoder (convert<RecRecord>) reads those fields 
unconditionally, so this can produce nondeterministic output or undefined 
behavior. Value-initialize the struct and set required fields to safe defaults 
before invoking the callback.



-- 
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]

Reply via email to