| 306 | }; |
| 307 | |
| 308 | void VarsService::default_method(::google::protobuf::RpcController* cntl_base, |
| 309 | const ::brpc::VarsRequest*, |
| 310 | ::brpc::VarsResponse*, |
| 311 | ::google::protobuf::Closure* done) { |
| 312 | ClosureGuard done_guard(done); |
| 313 | Controller *cntl = static_cast<Controller*>(cntl_base); |
| 314 | if (cntl->http_request().uri().GetQuery("series") != NULL) { |
| 315 | butil::IOBufBuilder os; |
| 316 | bvar::SeriesOptions series_options; |
| 317 | const int rc = bvar::Variable::describe_series_exposed( |
| 318 | cntl->http_request().unresolved_path(), os, series_options); |
| 319 | if (rc == 0) { |
| 320 | cntl->http_response().set_content_type("application/json"); |
| 321 | os.move_to(cntl->response_attachment()); |
| 322 | } else if (rc < 0) { |
| 323 | cntl->SetFailed(ENOMETHOD, "Fail to find any bvar by `%s'", |
| 324 | cntl->http_request().unresolved_path().c_str()); |
| 325 | } else { |
| 326 | cntl->SetFailed(ENODATA, "`%s' does not have value series", |
| 327 | cntl->http_request().unresolved_path().c_str()); |
| 328 | } |
| 329 | return; |
| 330 | } |
| 331 | const bool use_html = UseHTML(cntl->http_request()); |
| 332 | bool with_tabs = false; |
| 333 | if (use_html && cntl->http_request().uri().GetQuery("dataonly") == NULL) { |
| 334 | with_tabs = true; |
| 335 | } |
| 336 | cntl->http_response().set_content_type( |
| 337 | use_html ? "text/html" : "text/plain"); |
| 338 | |
| 339 | butil::IOBufBuilder os; |
| 340 | if (with_tabs) { |
| 341 | os << "<!DOCTYPE html><html><head>\n" |
| 342 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"; |
| 343 | PutVarsHeading(os, cntl->http_request().uri().GetQuery("expand")); |
| 344 | os << "<script type=\"text/javascript\">\n" |
| 345 | "const delayTime = 200;\n" |
| 346 | "var searching = false;\n" |
| 347 | "function toURL(text) {\n" |
| 348 | " if (text == '') {\n" |
| 349 | " return '/vars';\n" |
| 350 | " }\n" |
| 351 | // Normalize ;,\s\* to space, trim beginning/ending spaces and |
| 352 | // replace all spaces with *;* and add beginning/ending * |
| 353 | // iobuf,bthread -> *iobuf*;*bthread* |
| 354 | // iobuf, -> *iobuf* |
| 355 | // ;,iobuf -> *iobuf* |
| 356 | // ,;*iobuf*, bthread;,; -> *iobuf*;*bthread* |
| 357 | " text = text.replace(/(;|,|\\s|\\*)+/g, ' ').trim()" |
| 358 | " .replace(/ /g, '*;*');\n" |
| 359 | " if (text == '') {\n" |
| 360 | " return '/vars';\n" |
| 361 | " }\n" |
| 362 | " return '/vars/*' + text + '*';\n" |
| 363 | "}\n" |
| 364 | "function onDataReceived(searchText, data) {\n" |
| 365 | " for (var var_name in enabled) {\n" |
nothing calls this directly
no test coverage detected