Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
Signed-off-by: tianqian.zyf <[email protected]>
  • Loading branch information
zyfjeff committed Sep 5, 2018
1 parent 8d16553 commit 8646d64
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace Extensions {
namespace StatSinks {
namespace MetricsService {

namespace {
// TODO(#4160): use TimeSource::systemTime() rather than directly reading the system-clock.
int64_t getUnixMicrosForNow() {
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
}
} // namespace

GrpcMetricsStreamerImpl::GrpcMetricsStreamerImpl(Grpc::AsyncClientFactoryPtr&& factory,
ThreadLocal::SlotAllocator& tls,
const LocalInfo::LocalInfo& local_info)
Expand Down Expand Up @@ -69,9 +78,7 @@ void MetricsServiceSink::flushCounter(const Stats::Counter& counter) {
metrics_family->set_type(io::prometheus::client::MetricType::COUNTER);
metrics_family->set_name(counter.name());
auto* metric = metrics_family->add_metric();
metric->set_timestamp_ms(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
metric->set_timestamp_ms(getUnixMicrosForNow());
auto* counter_metric = metric->mutable_counter();
counter_metric->set_value(counter.value());
}
Expand All @@ -81,9 +88,7 @@ void MetricsServiceSink::flushGauge(const Stats::Gauge& gauge) {
metrics_family->set_type(io::prometheus::client::MetricType::GAUGE);
metrics_family->set_name(gauge.name());
auto* metric = metrics_family->add_metric();
metric->set_timestamp_ms(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
metric->set_timestamp_ms(getUnixMicrosForNow());
auto* gauage_metric = metric->mutable_gauge();
gauage_metric->set_value(gauge.value());
}
Expand All @@ -92,9 +97,7 @@ void MetricsServiceSink::flushHistogram(const Stats::ParentHistogram& histogram)
metrics_family->set_type(io::prometheus::client::MetricType::SUMMARY);
metrics_family->set_name(histogram.name());
auto* metric = metrics_family->add_metric();
metric->set_timestamp_ms(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
metric->set_timestamp_ms(getUnixMicrosForNow());
auto* summary_metric = metric->mutable_summary();
const Stats::HistogramStatistics& hist_stats = histogram.intervalStatistics();
for (size_t i = 0; i < hist_stats.supportedQuantiles().size(); i++) {
Expand Down

0 comments on commit 8646d64

Please sign in to comment.