Skip to content

Commit

Permalink
Send delta metrics for intermediate reports. (envoyproxy#219)
Browse files Browse the repository at this point in the history
* Send delta metrics for intermediate reports.

* Move last_request_bytes/last_response_bytes to RequestContext.

* Handle final report.

* Address comment.
  • Loading branch information
chowchow316 authored Apr 7, 2017
1 parent 1ef1b4a commit 1bcfab4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions contrib/endpoints/src/api_manager/context/request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ RequestContext::RequestContext(std::shared_ptr<ServiceContext> service_context,
std::unique_ptr<Request> request)
: service_context_(service_context),
request_(std::move(request)),
is_first_report_(true) {
is_first_report_(true),
last_request_bytes_(0),
last_response_bytes_(0) {
start_time_ = std::chrono::system_clock::now();
last_report_time_ = std::chrono::steady_clock::now();
operation_id_ = GenerateUUID();
Expand Down Expand Up @@ -267,13 +269,23 @@ void RequestContext::FillReportRequestInfo(
info->auth_audience = auth_audience_;

if (!info->is_final_report) {
info->request_bytes = request_->GetGrpcRequestBytes();
info->response_bytes = request_->GetGrpcResponseBytes();
// Make sure we send delta metrics for intermediate reports.
info->request_bytes = request_->GetGrpcRequestBytes() - last_request_bytes_;
info->response_bytes =
request_->GetGrpcResponseBytes() - last_response_bytes_;
last_request_bytes_ += info->request_bytes;
last_response_bytes_ += info->response_bytes;
} else {
info->request_size = response->GetRequestSize();
info->response_size = response->GetResponseSize();
info->request_bytes = info->request_size;
info->response_bytes = info->response_size;
info->request_bytes = info->request_size - last_request_bytes_;
if (info->request_bytes < 0) {
info->request_bytes = 0;
}
info->response_bytes = info->response_size - last_response_bytes_;
if (info->response_bytes < 0) {
info->response_bytes = 0;
}

info->streaming_request_message_counts =
request_->GetGrpcRequestMessageCounts();
Expand Down
4 changes: 4 additions & 0 deletions contrib/endpoints/src/api_manager/context/request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ class RequestContext {

// The time point of last intermediate report
std::chrono::steady_clock::time_point last_report_time_;

// The accumulated data sent till last intermediate report
int64_t last_request_bytes_;
int64_t last_response_bytes_;
};

} // namespace context
Expand Down

0 comments on commit 1bcfab4

Please sign in to comment.