Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support mvariable dump by prometheus rpc service #1964

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
ldak4747 marked this conversation as resolved.
Show resolved Hide resolved
exceed max dump multi dimension label number["
<< FLAGS_bvar_max_dump_multi_dimension_metric_number
<< "]";
break;
}
}
return n;
}
Expand Down