@@ -547,6 +547,23 @@ RecLookupRecord(const char *name, void (*callback)(const RecRecord *, void *), v
547547 if (lock) {
548548 ink_rwlock_unlock (&g_records_rwlock);
549549 }
550+
551+ // Also check for StaticString metrics
552+ if (err == REC_ERR_FAIL) {
553+ auto &strings = ts::Metrics::StaticString::instance ();
554+
555+ if (auto m = strings.lookup (std::string{name}); m) {
556+ RecRecord r;
557+ r.rec_type = RECT_PLUGIN;
558+ r.data_type = RECD_STRING;
559+ r.name = name;
560+ r.data .rec_string = const_cast <char *>(m->data ());
561+ r.data_default .rec_string = const_cast <char *>(m->data ());
562+
563+ callback (&r, data);
564+ err = REC_ERR_OKAY;
565+ }
566+ }
550567 }
551568
552569 return err;
@@ -556,7 +573,6 @@ RecErrT
556573RecLookupMatchingRecords (unsigned rec_type, const char *match, void (*callback)(const RecRecord *, void *), void *data,
557574 bool /* lock ATS_UNUSED */ )
558575{
559- int num_records;
560576 Regex regex;
561577
562578 if (!regex.compile (match, RE_CASE_INSENSITIVE | RE_UNANCHORED)) {
@@ -566,22 +582,36 @@ RecLookupMatchingRecords(unsigned rec_type, const char *match, void (*callback)(
566582 if ((rec_type & (RECT_PROCESS | RECT_NODE | RECT_PLUGIN))) {
567583 // First find the new metrics, this is a bit of a hack, because we still use the old
568584 // librecords callback with a "pseudo" record.
569- RecRecord tmp;
570-
571- tmp.rec_type = RECT_PROCESS;
572-
573585 for (auto &&[name, type, val] : ts::Metrics::instance ()) {
574586 if (regex.exec (name.data ())) {
587+ RecRecord tmp;
588+
589+ tmp.rec_type = RECT_PROCESS;
590+
575591 tmp.name = name.data ();
576592 tmp.data_type = type == ts::Metrics::MetricType::COUNTER ? RECD_COUNTER : RECD_INT;
577593 tmp.data .rec_int = val;
578594 callback (&tmp, data);
579595 }
580596 }
581- // Fall through to return any matching string metrics
597+ // Finally check string metrics
598+ for (auto &&[name, value] : ts::Metrics::StaticString::instance ()) {
599+ if (regex.exec (name)) {
600+ RecRecord tmp;
601+
602+ tmp.rec_type = RECT_PROCESS;
603+
604+ tmp.name = name.data ();
605+ tmp.data_type = RECD_STRING;
606+ // NOTE(cmcfarlen): unfortunate relic here that the callbacks expect a non-const rec_string
607+ // This should be temp until traffic_ctl uses ts::Metrics directly
608+ tmp.data .rec_string = const_cast <char *>(value.c_str ());
609+ callback (&tmp, data);
610+ }
611+ }
582612 }
583613
584- num_records = g_num_records;
614+ int num_records = g_num_records;
585615 for (int i = 0 ; i < num_records; i++) {
586616 RecRecord *r = &(g_records[i]);
587617
0 commit comments