This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 1839ba4807f7df7b1ffef225cbac941bfac63815 Author: Damian Meden <dme...@apache.org> AuthorDate: Thu Mar 7 10:20:53 2024 +0100 Fix for issue 11123. (#11127) Records - Do not return metrics when a config record is requested. (cherry picked from commit a6d9c4a5755eadae37d81b50d6edc297e1a2196b) --- src/mgmt/rpc/handlers/common/RecordsUtils.cc | 13 +++++++++++++ src/records/RecCore.cc | 28 ++++++++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/mgmt/rpc/handlers/common/RecordsUtils.cc b/src/mgmt/rpc/handlers/common/RecordsUtils.cc index 9a5276ef6a..c285f0e50f 100644 --- a/src/mgmt/rpc/handlers/common/RecordsUtils.cc +++ b/src/mgmt/rpc/handlers/common/RecordsUtils.cc @@ -148,6 +148,11 @@ void static get_record_regex_impl(std::string const ®ex, unsigned recType, Co return; } + if (!ctx.checkCb(record->rec_type, ctx.ec)) { + // error_code in the callback will be set. + return; + } + YAML::Node recordYaml; try { @@ -161,6 +166,14 @@ void static get_record_regex_impl(std::string const ®ex, unsigned recType, Co ctx.yaml.push_back(recordYaml); }; + ctx.checkCb = [recType](RecT rec_type, std::error_code &ec) { + if ((recType & rec_type) == 0) { + ec = rpc::handlers::errors::RecordError::REQUESTED_TYPE_MISMATCH; + return false; + } + return true; + }; + const auto ret = RecLookupMatchingRecords(recType, regex.c_str(), yamlConverter, &ctx); // if the passed regex didn't match, it will not report any error. We will only get errors when converting // the record into yaml(so far). diff --git a/src/records/RecCore.cc b/src/records/RecCore.cc index 1ba7d25d3e..fe52b9eb84 100644 --- a/src/records/RecCore.cc +++ b/src/records/RecCore.cc @@ -560,19 +560,23 @@ RecLookupMatchingRecords(unsigned rec_type, const char *match, void (*callback)( return REC_ERR_FAIL; } - // First find the new metrics, this is a bit of a hack, beacuse we still use the old - // librecords callback with a "pseudo" record. - RecRecord tmp; - - tmp.rec_type = RECT_ALL; - tmp.data_type = RECD_INT; - - for (auto &&[name, val] : ts::Metrics::instance()) { - if (regex.match(name.data()) >= 0) { - tmp.name = name.data(); - tmp.data.rec_int = val; - callback(&tmp, data); + if ((rec_type & (RECT_PROCESS | RECT_NODE | RECT_PLUGIN))) { + // First find the new metrics, this is a bit of a hack, because we still use the old + // librecords callback with a "pseudo" record. + RecRecord tmp; + + tmp.rec_type = RECT_PROCESS; + tmp.data_type = RECD_INT; + + for (auto &&[name, val] : ts::Metrics::instance()) { + if (regex.match(name.data()) >= 0) { + tmp.name = name.data(); + tmp.data.rec_int = val; + callback(&tmp, data); + } } + // all done for metrics + return REC_ERR_OKAY; } num_records = g_num_records;