-
Notifications
You must be signed in to change notification settings - Fork 855
Make sure string metrics are dumped in RecDumpRecords #13074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||||||||||
| /** @file | ||||||||||||||
|
|
||||||||||||||
| Catch-based tests for RecDumpRecords | ||||||||||||||
|
|
||||||||||||||
| @section license License | ||||||||||||||
|
|
||||||||||||||
| Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. | ||||||||||||||
| See the NOTICE file distributed with this work for additional information regarding copyright | ||||||||||||||
| ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||||||||||||||
| "License"); you may not use this file except in compliance with the License. You may obtain a | ||||||||||||||
| copy of the License at | ||||||||||||||
|
|
||||||||||||||
| http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
|
|
||||||||||||||
| Unless required by applicable law or agreed to in writing, software distributed under the License | ||||||||||||||
| is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||||||||||||
| or implied. See the License for the specific language governing permissions and limitations under | ||||||||||||||
| the License. | ||||||||||||||
| */ | ||||||||||||||
| #include <catch2/catch_test_macros.hpp> | ||||||||||||||
| #include <string> | ||||||||||||||
| #include <vector> | ||||||||||||||
|
|
||||||||||||||
| #include "../P_RecCore.h" | ||||||||||||||
| #include "tsutil/Metrics.h" | ||||||||||||||
|
|
||||||||||||||
| struct DumpEntry { | ||||||||||||||
| RecT rec_type; | ||||||||||||||
| int registered; | ||||||||||||||
| std::string name; | ||||||||||||||
| int data_type; | ||||||||||||||
| std::string string_value; | ||||||||||||||
| RecInt int_value{0}; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| static void | ||||||||||||||
| collect_callback(RecT rec_type, void *edata, int registered, const char *name, int data_type, RecData *datum) | ||||||||||||||
| { | ||||||||||||||
| auto *entries = static_cast<std::vector<DumpEntry> *>(edata); | ||||||||||||||
| DumpEntry entry; | ||||||||||||||
|
|
||||||||||||||
| entry.rec_type = rec_type; | ||||||||||||||
| entry.registered = registered; | ||||||||||||||
| entry.name = name; | ||||||||||||||
| entry.data_type = data_type; | ||||||||||||||
|
|
||||||||||||||
| if (data_type == RECD_STRING && datum->rec_string != nullptr) { | ||||||||||||||
| entry.string_value = datum->rec_string; | ||||||||||||||
| } else if (data_type == RECD_INT || data_type == RECD_COUNTER) { | ||||||||||||||
| entry.int_value = datum->rec_int; | ||||||||||||||
|
Comment on lines
+49
to
+50
|
||||||||||||||
| } 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; |
There was a problem hiding this comment.
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 (perMetrics.h). CallingRecDumpRecords()'s externalcallback(...)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 invokingcallback(...)after releasing it.