Address code review comments
diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc
index eac29f3..5bb87e5 100644
--- a/test/cpp/util/metrics_server.cc
+++ b/test/cpp/util/metrics_server.cc
@@ -61,8 +61,8 @@
std::lock_guard<std::mutex> lock(mu_);
for (auto it = gauges_.begin(); it != gauges_.end(); it++) {
GaugeResponse resp;
- resp.set_name(it->first); // Gauge name
- resp.set_value(it->second->Get()); // Gauge value
+ resp.set_name(it->first); // Gauge name
+ resp.set_long_value(it->second->Get()); // Gauge value
writer->Write(resp);
}
@@ -77,14 +77,14 @@
auto it = gauges_.find(request->name());
if (it != gauges_.end()) {
response->set_name(it->first);
- response->set_value(it->second->Get());
+ response->set_long_value(it->second->Get());
}
return Status::OK;
}
-std::shared_ptr<Gauge> MetricsServiceImpl::CreateGauge(string name,
- bool& already_present) {
+std::shared_ptr<Gauge> MetricsServiceImpl::CreateGauge(const grpc::string& name,
+ bool* already_present) {
std::lock_guard<std::mutex> lock(mu_);
std::shared_ptr<Gauge> gauge(new Gauge(0));
@@ -92,7 +92,7 @@
// p.first is an iterator pointing to <name, shared_ptr<Gauge>> pair. p.second
// is a boolean indicating if the Gauge is already present in the map
- already_present = !p.second;
+ *already_present = !p.second;
return p.first->second;
}
diff --git a/test/cpp/util/metrics_server.h b/test/cpp/util/metrics_server.h
index 19c3a0c..3652909 100644
--- a/test/cpp/util/metrics_server.h
+++ b/test/cpp/util/metrics_server.h
@@ -36,7 +36,6 @@
#include <atomic>
#include <map>
#include <mutex>
-#include <vector>
#include "test/proto/metrics.grpc.pb.h"
#include "test/proto/metrics.pb.h"
@@ -61,9 +60,8 @@
namespace grpc {
namespace testing {
-using std::map;
-using std::vector;
-
+// TODO(sreek): Add support for other types of Gauges like Double, String in
+// future
class Gauge {
public:
Gauge(long initial_val);
@@ -86,7 +84,8 @@
// is already present in the map.
// NOTE: CreateGauge can be called anytime (i.e before or after calling
// StartServer).
- std::shared_ptr<Gauge> CreateGauge(string name, bool& is_present);
+ std::shared_ptr<Gauge> CreateGauge(const grpc::string& name,
+ bool* already_present);
std::unique_ptr<grpc::Server> StartServer(int port);