Skip to content

Make sure string metrics are dumped in RecDumpRecords#13074

Open
cmcfarlen wants to merge 1 commit intoapache:masterfrom
cmcfarlen:fix-string-metric-dump
Open

Make sure string metrics are dumped in RecDumpRecords#13074
cmcfarlen wants to merge 1 commit intoapache:masterfrom
cmcfarlen:fix-string-metric-dump

Conversation

@cmcfarlen
Copy link
Copy Markdown
Contributor

This bug was preventing string metrics from showing up in plugins like stats_over_http.

@cmcfarlen cmcfarlen added this to the 11.0.0 milestone Apr 9, 2026
@cmcfarlen cmcfarlen self-assigned this Apr 9, 2026
@cmcfarlen cmcfarlen added the Bug label Apr 9, 2026
@cmcfarlen
Copy link
Copy Markdown
Contributor Author

[approve ci autest 1]

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the records dump path so plugin string metrics (e.g., used by stats_over_http) are included when RecDumpRecords / TSRecordDump enumerates metrics.

Changes:

  • Extend RecDumpRecords() to also emit ts::Metrics::StaticString entries as RECT_PLUGIN / string data.
  • Add a Catch2 unit test that registers a StaticString metric and asserts it appears in RecDumpRecords() output.
  • Wire the new unit test into the test_records target.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/records/RecCore.cc Adds dumping of static string metrics via StaticString::for_each() into RecDumpRecords().
src/records/unit_tests/test_RecDumpRecords.cc New unit test validating string metrics appear in RecDumpRecords() output.
src/records/CMakeLists.txt Adds the new unit test source to the test_records executable.

Comment on lines +49 to +50
} else if (data_type == RECD_INT || data_type == RECD_COUNTER) {
entry.int_value = datum->rec_int;
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collect_callback() reads datum->rec_int for RECD_COUNTER entries. Since RecData is a union, counters should be read from datum->rec_counter when data_type == RECD_COUNTER (reading a non-active union member is undefined behavior and can trip UBSan even if the value isn't later asserted in this test).

Suggested change
} else if (data_type == RECD_INT || data_type == RECD_COUNTER) {
entry.int_value = datum->rec_int;
} else if (data_type == RECD_INT) {
entry.int_value = datum->rec_int;
} else if (data_type == RECD_COUNTER) {
entry.int_value = datum->rec_counter;

Copilot uses AI. Check for mistakes.
Comment on lines +945 to +949
ts::Metrics::StaticString::instance().for_each([&](const std::string &name, const std::string &value) {
datum.rec_string = const_cast<char *>(value.c_str());

callback(RECT_PLUGIN, edata, true, name.data(), TS_RECORDDATATYPE_STRING, &datum);
});
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts::Metrics::StaticString::for_each() invokes its callback while holding the internal mutex (per Metrics.h). Calling RecDumpRecords()'s external callback(...) under that lock risks deadlocks / long lock hold times if the callback does anything non-trivial. Consider snapshotting the (name,value) pairs while holding the mutex, then invoking callback(...) after releasing it.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants