Skip to content

Commit

Permalink
support mvariable dump by prometheus rpc service (#1964)
Browse files Browse the repository at this point in the history
Co-authored-by: Liu Mander <mander.liu@shopee.com>
  • Loading branch information
ldak4747 and Liu Mander authored Oct 27, 2022
1 parent 84c7734 commit 90dce8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/brpc/builtin/prometheus_metrics_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/bvar/bvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/bvar/mvariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<size_t>(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;
}
Expand Down

0 comments on commit 90dce8b

Please sign in to comment.