Fix metrics client logging

pull/7100/head
Sree Kuchibhotla 9 years ago
parent a9df5d1029
commit ad57b266c7
  1. 27
      test/cpp/interop/metrics_client.cc

@ -56,6 +56,9 @@ using grpc::testing::GaugeResponse;
using grpc::testing::MetricsService; using grpc::testing::MetricsService;
using grpc::testing::MetricsServiceImpl; using grpc::testing::MetricsServiceImpl;
// Do not log anything
void BlackholeLogger(gpr_log_func_args* args) {}
// Prints the values of all Gauges (unless total_only is set to 'true' in which // Prints the values of all Gauges (unless total_only is set to 'true' in which
// case this only prints the sum of all gauge values). // case this only prints the sum of all gauge values).
bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only, bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only,
@ -76,21 +79,21 @@ bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only,
while (reader->Read(&gauge_response)) { while (reader->Read(&gauge_response)) {
if (gauge_response.value_case() == GaugeResponse::kLongValue) { if (gauge_response.value_case() == GaugeResponse::kLongValue) {
if (!total_only) { if (!total_only) {
gpr_log(GPR_INFO, "%s: %lld", gauge_response.name().c_str(), std::cout << gauge_response.name() << ": "
gauge_response.long_value()); << gauge_response.long_value() << std::endl;
} }
overall_qps += gauge_response.long_value(); overall_qps += gauge_response.long_value();
} else { } else {
gpr_log(GPR_INFO, "Gauge %s is not a long value", std::cout << "Gauge %s is not a long value" << gauge_response.name()
gauge_response.name().c_str()); << std::endl;
} }
} }
gpr_log(GPR_INFO, "%ld", overall_qps); std::cout << overall_qps << std::endl;
const grpc::Status status = reader->Finish(); const grpc::Status status = reader->Finish();
if (!status.ok()) { if (!status.ok()) {
gpr_log(GPR_ERROR, "Error in getting metrics from the client"); std::cout << "Error in getting metrics from the client" << std::endl;
} }
return status.ok(); return status.ok();
@ -99,14 +102,10 @@ bool PrintMetrics(std::unique_ptr<MetricsService::Stub> stub, bool total_only,
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
// Make sure server_addresses flag is not empty // The output of metrics client is in some cases programatically parsed (for
if (FLAGS_metrics_server_address.empty()) { // example by the stress test framework). So, we do not want any of the log
gpr_log( // from the grpc library appearing on stdout.
GPR_ERROR, gpr_set_log_function(BlackholeLogger);
"Cannot connect to the Metrics server. Please pass the address of the"
"metrics server to connect to via the 'metrics_server_address' flag");
return 1;
}
std::shared_ptr<grpc::Channel> channel(grpc::CreateChannel( std::shared_ptr<grpc::Channel> channel(grpc::CreateChannel(
FLAGS_metrics_server_address, grpc::InsecureChannelCredentials())); FLAGS_metrics_server_address, grpc::InsecureChannelCredentials()));

Loading…
Cancel
Save