YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/server/rpcz-path-handler.cc
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
#include "yb/server/rpcz-path-handler.h"
33
34
#include <functional>
35
#include <memory>
36
#include <string>
37
38
#include "yb/rpc/messenger.h"
39
#include "yb/rpc/rpc_introspection.pb.h"
40
#include "yb/server/webserver.h"
41
#include "yb/util/jsonwriter.h"
42
#include "yb/util/status_log.h"
43
44
namespace yb {
45
46
using yb::rpc::DumpRunningRpcsRequestPB;
47
using yb::rpc::DumpRunningRpcsResponsePB;
48
using yb::rpc::Messenger;
49
using std::shared_ptr;
50
using std::stringstream;
51
52
using namespace std::placeholders;
53
54
namespace {
55
56
template <class Map>
57
2
bool GetBool(const Map& map, const typename Map::key_type& key, bool default_value) {
58
2
  auto it = map.find(key);
59
2
  if (it == map.end()) {
60
2
    return default_value;
61
2
  }
62
63
0
  return ParseLeadingBoolValue(it->second, default_value);
64
0
}
65
66
void RpczPathHandler(Messenger* messenger,
67
1
                     const Webserver::WebRequest& req, Webserver::WebResponse* resp) {
68
1
  std::stringstream *output = &resp->output;
69
1
  DumpRunningRpcsRequestPB dump_req;
70
1
  DumpRunningRpcsResponsePB dump_resp;
71
72
1
  dump_req.set_include_traces(GetBool(req.parsed_args, "include_traces", false));
73
1
  dump_req.set_dump_timed_out(GetBool(req.parsed_args, "timed_out", false));
74
75
1
  WARN_NOT_OK(messenger->DumpRunningRpcs(dump_req, &dump_resp), "DumpRunningRpcs failed");
76
77
1
  JsonWriter writer(output, JsonWriter::PRETTY);
78
1
  writer.Protobuf(dump_resp);
79
1
}
80
81
} // anonymous namespace
82
83
17.1k
void AddRpczPathHandlers(Messenger* messenger, Webserver* webserver) {
84
17.1k
  webserver->RegisterPathHandler(
85
17.1k
      "/rpcz", "RPCs", std::bind(RpczPathHandler, messenger, _1, _2), false, false);
86
17.1k
}
87
88
} // namespace yb