Skip to content

Commit 2fc7ef4

Browse files
Fix code formatting
1 parent 376505c commit 2fc7ef4

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

be/src/util/metrics.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,10 @@ std::string MetricRegistry::to_prometheus(bool with_tablet_metrics) const {
325325
// Reorder by MetricPrototype
326326
EntityMetricsByType entity_metrics_by_types;
327327
std::lock_guard<std::mutex> l1(_lock);
328-
329-
// 关键:在这里就确保 _name 不为空
328+
330329
std::string registry_name = _name.empty() ? "unknown" : _name;
331330
const char* safe_name_ptr = registry_name.c_str();
332-
331+
333332
for (const auto& entity : _entities) {
334333
if (entity.first->_type == MetricEntityType::kTablet && !with_tablet_metrics) {
335334
continue;
@@ -359,8 +358,8 @@ std::string MetricRegistry::to_prometheus(bool with_tablet_metrics) const {
359358
continue;
360359
}
361360

362-
const std::string& g_str = proto->group_name;
363-
const std::string& n_str = proto->name;
361+
const std::string& g_str = proto->group_name;
362+
const std::string& n_str = proto->name;
364363

365364
std::string metric_name = registry_name + "_" + g_str + "_" + n_str;
366365

@@ -372,10 +371,9 @@ std::string MetricRegistry::to_prometheus(bool with_tablet_metrics) const {
372371
if (entity_metric.second == nullptr || entity_metric.first == nullptr) {
373372
continue;
374373
}
375-
376-
ss << entity_metric.second->to_prometheus(metric_name,
377-
entity_metric.first->_labels,
378-
proto->labels);
374+
375+
ss << entity_metric.second->to_prometheus(metric_name, entity_metric.first->_labels,
376+
proto->labels);
379377
}
380378
}
381379

be/test/util/metrics_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,16 @@ TEST_F(MetricsTest, PrometheusDuplicateTypeFix) {
493493
// 1. Create the first entity and register a metric with a group name
494494
auto entity1 = registry.register_entity("entity1");
495495
// Using MetricPrototype is the "official way" in Doris metrics_test
496-
MetricPrototype requests_type(MetricType::COUNTER, MetricUnit::OPERATIONS, "requests_total", "", "engine_requests");
496+
MetricPrototype requests_type(MetricType::COUNTER, MetricUnit::OPERATIONS, "requests_total",
497+
"", "engine_requests");
497498
IntCounter* m1 = (IntCounter*)entity1->register_metric<IntCounter>(&requests_type);
498499
m1->increment(1);
499500

500501
// 2. Create the second entity and register a metric with a DIFFERENT name to break continuity
501502
auto entity2 = registry.register_entity("entity2");
502-
MetricPrototype other_type(MetricType::COUNTER, MetricUnit::OPERATIONS, "other_metric", "", "");
503-
IntCounter* m2 = (IntCounter*)entity2->register_metric<IntCounter>(&other_type); // 修复:使用 register_metric
503+
MetricPrototype other_type(MetricType::COUNTER, MetricUnit::OPERATIONS, "other_metric", "",
504+
"");
505+
IntCounter* m2 = (IntCounter*)entity2->register_metric<IntCounter>(&other_type);
504506
m2->increment(5);
505507

506508
// 3. Create the third entity and register the SAME group name metric again
@@ -515,9 +517,9 @@ TEST_F(MetricsTest, PrometheusDuplicateTypeFix) {
515517
// Verification: Count the occurrences of "# TYPE test_registry_engine_requests counter"
516518
// In your official snippet, the format is: # TYPE {registry_name}_{group_name} {type}
517519
std::string target_type_line = "# TYPE test_registry_engine_requests counter";
518-
520+
519521
int occurrences = 0;
520-
size_t pos = 0; // 修复:使用 size_t 而不是 std::string::size_t
522+
size_t pos = 0;
521523
while ((pos = output.find(target_type_line, pos)) != std::string::npos) {
522524
occurrences++;
523525
pos += target_type_line.length();
@@ -533,4 +535,3 @@ TEST_F(MetricsTest, PrometheusDuplicateTypeFix) {
533535
}
534536
}
535537
} // namespace doris
536-

0 commit comments

Comments
 (0)