Skip to content

Commit fba27f8

Browse files
committed
Fixed some potential bugs
1 parent 1f046c4 commit fba27f8

4 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/pika_admin.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,9 @@ void InfoCmd::InfoCommandP99(std::string& info) {
15411541
tmp_stream << "Command: " << command_name << "\r\n";
15421542
}
15431543

1544+
if (total_count < 100) {
1545+
continue;
1546+
}
15441547
double tp99_threshold = total_count * 0.99;
15451548
double tp999_threshold = total_count * 0.999;
15461549
double tp9999_threshold = total_count * 0.9999;

src/pika_cmd_table_manager.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,12 @@ prometheus::Histogram& PikaCmdTableManager::GetHistogram(const std::string& opt)
8282
data_copy = data_;
8383
}
8484

85-
{
86-
std::shared_lock<std::shared_mutex> read_lock(histograms_mutex_);
87-
auto it = data_copy->histograms.find(opt);
88-
if (it != data_copy->histograms.end()) {
89-
return *(it->second);
90-
}
85+
std::unique_lock<std::shared_mutex> write_lock(histograms_mutex_);
86+
auto it = data_copy->histograms.find(opt);
87+
if (it != data_copy->histograms.end()) {
88+
return *(it->second);
9189
}
9290

93-
std::unique_lock<std::shared_mutex> write_lock(histograms_mutex_);
9491
auto& new_histogram = data_copy->family->Add(
9592
{{"command", opt}},
9693
prometheus::Histogram::BucketBoundaries{0.5, 1, 2, 3, 5, 7, 10, 15, 20, 30, 40, 50, 65, 75, 85, 100, 125, 140, 150, 160, 175, 185, 200, 300, 400, 500, 750, 1000, 2000, 5000, 10000}
@@ -109,19 +106,7 @@ std::shared_ptr<HistogramData> PikaCmdTableManager::GetHistogramsData() {
109106
}
110107

111108
void PikaCmdTableManager::UpdateSlowCommandCount(const std::string& opt) {
112-
{
113-
std::shared_lock<std::shared_mutex> read_lock(slow_command_mutex_);
114-
if (slow_command_count_.find(opt) != slow_command_count_.end()) {
115-
slow_command_count_[opt].cmd_count.fetch_add(1);
116-
return;
117-
}
118-
}
119-
120-
{
121-
std::unique_lock<std::shared_mutex> write_lock(slow_command_mutex_);
122-
slow_command_count_[opt];
123-
}
124-
109+
std::unique_lock<std::shared_mutex> write_lock(slow_command_mutex_);
125110
slow_command_count_[opt].cmd_count.fetch_add(1);
126111
}
127112

tools/pika_exporter/exporter/metrics/commandp99.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var collectCommandP99Metrics = map[string]MetricConfig{
1212
"command_p99_info": {
1313
Parser: &regexParser{
1414
name: "command_p99_info",
15-
reg: regexp.MustCompile(`Command:\s*(?P<cmd>\S+)\s*\r?\n(?:.*\r?\n)*?TP99 ms:\s*(?P<tp99>[\d.]+)\s*\r?\n.*?TP999 ms:\s*(?P<tp999>[\d.]+)\s*\r?\n.*?TP9999 ms:\s*(?P<tp9999>[\d.]+)`),
15+
reg: regexp.MustCompile(`Command:\s*(?P<cmd>\S+)[\s\S]*?TP99 ms:\s*(?P<tp99>[\d.]+)[\s\S]*?TP999 ms:\s*(?P<tp999>[\d.]+)[\s\S]*?TP9999 ms:\s*(?P<tp9999>[\d.]+)`),
1616
Parser: &normalParser{},
1717
},
1818
MetricMeta: MetaDatas{

tools/pika_exporter/exporter/metrics/slowcommand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var collectSlowCommandMetrics = map[string]MetricConfig{
1212
"slow_command_info": {
1313
Parser: &regexParser{
1414
name: "slow_command_info",
15-
reg: regexp.MustCompile(`(?P<cmd>\S+):slow_count=(?P<slow_count>\d+)`),
15+
reg: regexp.MustCompile(`(?P<cmd>[^\s:]+):slow_count=(?P<slow_count>\d+)`),
1616
Parser: &normalParser{},
1717
},
1818
MetricMeta: MetaDatas{

0 commit comments

Comments
 (0)