Commit af7a3220 authored by zhujiashun's avatar zhujiashun

add IsComplete() to SummaryItems

parent e8d15401
...@@ -64,13 +64,11 @@ private: ...@@ -64,13 +64,11 @@ private:
std::string latency_avg; std::string latency_avg;
std::string count; std::string count;
std::string metric_name; std::string metric_name;
bool IsComplete() const { return !metric_name.empty(); }
}; };
// Return true iff name ends with suffix output by LatencyRecorder. const SummaryItems* ProcessLatencyRecorderSuffix(const butil::StringPiece& name,
// If all bvars in LatencyRecorder have been gathered and are ready const butil::StringPiece& desc);
// to output a summary, *si_out is set properly.
bool ProcessLatencyRecorderSuffix(const butil::StringPiece& name,
const butil::StringPiece& desc,
SummaryItems** si_out);
private: private:
butil::IOBufBuilder* _os; butil::IOBufBuilder* _os;
...@@ -95,10 +93,9 @@ bool PrometheusMetricsDumper::dump(const std::string& name, ...@@ -95,10 +93,9 @@ bool PrometheusMetricsDumper::dump(const std::string& name,
return true; return true;
} }
bool PrometheusMetricsDumper::ProcessLatencyRecorderSuffix( const PrometheusMetricsDumper::SummaryItems*
const butil::StringPiece& name, PrometheusMetricsDumper::ProcessLatencyRecorderSuffix(const butil::StringPiece& name,
const butil::StringPiece& desc, const butil::StringPiece& desc) {
PrometheusMetricsDumper::SummaryItems** si_out) {
static std::string latency_names[] = { static std::string latency_names[] = {
butil::string_printf("_latency_%d", (int)bvar::FLAGS_bvar_latency_p1), butil::string_printf("_latency_%d", (int)bvar::FLAGS_bvar_latency_p1),
butil::string_printf("_latency_%d", (int)bvar::FLAGS_bvar_latency_p2), butil::string_printf("_latency_%d", (int)bvar::FLAGS_bvar_latency_p2),
...@@ -115,26 +112,27 @@ bool PrometheusMetricsDumper::ProcessLatencyRecorderSuffix( ...@@ -115,26 +112,27 @@ bool PrometheusMetricsDumper::ProcessLatencyRecorderSuffix(
SummaryItems* si = &_m[metric_name.as_string()]; SummaryItems* si = &_m[metric_name.as_string()];
si->latency_percentiles[i] = desc.as_string(); si->latency_percentiles[i] = desc.as_string();
if (i == NPERCENTILES - 1) { if (i == NPERCENTILES - 1) {
// 'max_latency' is the last suffix name that appear in the sorted bvar // '_max_latency' is the last suffix name that appear in the sorted bvar
// list, which means all related percentiles have been gathered and we are // list, which means all related percentiles have been gathered and we are
// ready to output a Summary. // ready to output a Summary.
si->metric_name = metric_name.as_string(); si->metric_name = metric_name.as_string();
*si_out = si;
} }
return true; return si;
} }
// Get the average of latency in recent window size // Get the average of latency in recent window size
if (metric_name.ends_with("_latency")) { if (metric_name.ends_with("_latency")) {
metric_name.remove_suffix(8); metric_name.remove_suffix(8);
_m[metric_name.as_string()].latency_avg = desc.as_string(); SummaryItems* si = &_m[metric_name.as_string()];
return true; si->latency_avg = desc.as_string();
return si;
} }
if (metric_name.ends_with("_count")) { if (metric_name.ends_with("_count")) {
metric_name.remove_suffix(6); metric_name.remove_suffix(6);
_m[metric_name.as_string()].count = desc.as_string(); SummaryItems* si = &_m[metric_name.as_string()];
return true; si->count = desc.as_string();
return si;
} }
return false; return NULL;
} }
bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix( bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix(
...@@ -143,11 +141,11 @@ bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix( ...@@ -143,11 +141,11 @@ bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix(
if (!name.starts_with(_server_prefix)) { if (!name.starts_with(_server_prefix)) {
return false; return false;
} }
SummaryItems* si = NULL; const SummaryItems* si = ProcessLatencyRecorderSuffix(name, desc);
if (!ProcessLatencyRecorderSuffix(name, desc, &si)) { if (!si) {
return false; return false;
} }
if (!si) { if (!si->IsComplete()) {
return true; return true;
} }
*_os << "# HELP " << si->metric_name << '\n' *_os << "# HELP " << si->metric_name << '\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment