Skip to content

Commit

Permalink
Escape span method name (#2411)
Browse files Browse the repository at this point in the history
* Escape span method name

* Reuse WebEscape
  • Loading branch information
wwbmmm authored and lei.li committed Oct 13, 2023
1 parent d2b73ec commit 39804c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/brpc/builtin/rpcz_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void PrintAnnotations(
while (extractors[i]->PopAnnotation(cur_time, &anno_time, &a)) {
PrintRealTime(os, anno_time);
PrintElapse(os, anno_time, last_time);
os << ' ' << a;
os << ' ' << WebEscape(a);
if (a.empty() || butil::back_char(a) != '\n') {
os << '\n';
}
Expand Down Expand Up @@ -249,7 +249,7 @@ static void PrintClientSpan(
if (abs_remote_side.ip == loopback_ip) {
abs_remote_side.ip = butil::my_ip();
}
os << " Requesting " << span.full_method_name() << '@' << remote_side
os << " Requesting " << WebEscape(span.full_method_name()) << '@' << remote_side
<< ' ' << protocol_name << ' ' << LOG_ID_STR << '=';
if (FLAGS_rpcz_hex_log_id) {
os << Hex(span.log_id());
Expand Down Expand Up @@ -346,7 +346,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span,
os, span.start_callback_real_us(),
&last_time, extr, ARRAY_SIZE(extr))) {
entered_user_method = true;
os << " Enter " << span.full_method_name() << std::endl;
os << " Enter " << WebEscape(span.full_method_name()) << std::endl;
}

const int nclient = span.client_spans_size();
Expand All @@ -359,7 +359,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span,
os, span.start_send_real_us(),
&last_time, extr, ARRAY_SIZE(extr))) {
if (entered_user_method) {
os << " Leave " << span.full_method_name() << std::endl;
os << " Leave " << WebEscape(span.full_method_name()) << std::endl;
} else {
os << " Responding" << std::endl;
}
Expand Down Expand Up @@ -665,7 +665,7 @@ void RpczService::default_method(::google::protobuf::RpcController* cntl_base,
} else {
os << span.log_id();
}
os << ' ' << span.full_method_name() << '(' << span.request_size()
os << ' ' << WebEscape(span.full_method_name()) << '(' << span.request_size()
<< ")=" << span.response_size();

if (span.error_code() == 0) {
Expand Down
6 changes: 6 additions & 0 deletions src/brpc/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,12 @@ void WebEscape(const std::string& source, std::string* output) {
}
}

std::string WebEscape(const std::string& source) {
std::string output;
WebEscape(source, &output);
return output;
}

void Controller::reset_sampled_request(SampledRequest* req) {
delete _sampled_request;
_sampled_request = req;
Expand Down
1 change: 1 addition & 0 deletions src/brpc/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ google::protobuf::Closure* DoNothing();

// Convert non-web symbols to web equivalence.
void WebEscape(const std::string& source, std::string* output);
std::string WebEscape(const std::string& source);

// True if Ctrl-C is ever pressed.
bool IsAskedToQuit();
Expand Down

0 comments on commit 39804c3

Please sign in to comment.