Skip to content
Snippets Groups Projects
Commit ad57b266 authored by Sree Kuchibhotla's avatar Sree Kuchibhotla
Browse files

Fix metrics client logging

parent a9df5d10
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,9 @@ using grpc::testing::GaugeResponse; ...@@ -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, ...@@ -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, ...@@ -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()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment