From 90dce8b720e8fd879278f9a77a61ba27cd843f66 Mon Sep 17 00:00:00 2001 From: ldak4747 <245217112@qq.com> Date: Thu, 27 Oct 2022 20:31:12 +0800 Subject: [PATCH] support mvariable dump by prometheus rpc service (#1964) Co-authored-by: Liu Mander --- src/brpc/builtin/prometheus_metrics_service.cpp | 10 ++++++++++ src/bvar/bvar.h | 1 + src/bvar/mvariable.cpp | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/src/brpc/builtin/prometheus_metrics_service.cpp b/src/brpc/builtin/prometheus_metrics_service.cpp index 5eddb1a841..f7948221a0 100644 --- a/src/brpc/builtin/prometheus_metrics_service.cpp +++ b/src/brpc/builtin/prometheus_metrics_service.cpp @@ -30,6 +30,7 @@ namespace bvar { DECLARE_int32(bvar_latency_p1); DECLARE_int32(bvar_latency_p2); DECLARE_int32(bvar_latency_p3); +DECLARE_int32(bvar_max_dump_multi_dimension_metric_number); } namespace brpc { @@ -200,6 +201,15 @@ int DumpPrometheusMetricsToIOBuf(butil::IOBuf* output) { return -1; } os.move_to(*output); + + if (bvar::FLAGS_bvar_max_dump_multi_dimension_metric_number > 0) { + PrometheusMetricsDumper dumper_md(&os, g_server_info_prefix); + const int ndump_md = bvar::MVariable::dump_exposed(&dumper_md, NULL); + if (ndump_md < 0) { + return -1; + } + output->append(butil::IOBuf::Movable(os.buf())); + } return 0; } diff --git a/src/bvar/bvar.h b/src/bvar/bvar.h index 5a54a09324..85e7442dc4 100644 --- a/src/bvar/bvar.h +++ b/src/bvar/bvar.h @@ -27,5 +27,6 @@ #include "bvar/latency_recorder.h" #include "bvar/gflag.h" #include "bvar/scoped_timer.h" +#include "bvar/mvariable.h" #endif //BVAR_BVAR_H diff --git a/src/bvar/mvariable.cpp b/src/bvar/mvariable.cpp index 2e191a1654..a2ad94b049 100644 --- a/src/bvar/mvariable.cpp +++ b/src/bvar/mvariable.cpp @@ -36,6 +36,8 @@ DECLARE_bool(bvar_abort_on_same_name); extern bool s_bvar_may_abort; DEFINE_int32(bvar_max_multi_dimension_metric_number, 1024, "Max number of multi dimension"); +DEFINE_int32(bvar_max_dump_multi_dimension_metric_number, 0, + "Max number of multi dimension metric number to dump by prometheus rpc service"); static bool validator_bvar_max_multi_dimension_metric_number(const char*, int32_t v) { if (v < 1) { @@ -246,6 +248,13 @@ size_t MVariable::dump_exposed(Dumper* dumper, const DumpOptions* options) { if (entry) { n += entry->var->dump(dumper, &opt); } + if (n > static_cast(FLAGS_bvar_max_dump_multi_dimension_metric_number)) { + LOG(WARNING) << "truncated because of \ + exceed max dump multi dimension label number[" + << FLAGS_bvar_max_dump_multi_dimension_metric_number + << "]"; + break; + } } return n; }