From 729d14ec443ca51dfc3bd2c74c18d2f6710e6915 Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Thu, 22 Dec 2016 13:43:38 -0800 Subject: [PATCH 1/2] Do not report latency for streaming requests. --- .../src/api_manager/service_control/proto.cc | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/endpoints/src/api_manager/service_control/proto.cc b/contrib/endpoints/src/api_manager/service_control/proto.cc index 17b921db076..25f8d116dc9 100644 --- a/contrib/endpoints/src/api_manager/service_control/proto.cc +++ b/contrib/endpoints/src/api_manager/service_control/proto.cc @@ -55,7 +55,7 @@ struct SupportedMetric { ::google::api::MetricDescriptor_ValueType value_type; enum Mark { PRODUCER = 0, CONSUMER = 1 }; - enum Tag { START = 0, INTERMEDIATE = 1, FINAL = 2 }; + enum Tag { START = 0, INTERMEDIATE = 1, FINAL = 2, NONSTREAMING = 3, }; Tag tag; Mark mark; Status (*set)(const SupportedMetric& m, const ReportRequestInfo& info, @@ -321,42 +321,42 @@ const SupportedMetric supported_metrics[] = { "serviceruntime.googleapis.com/api/consumer/total_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::CONSUMER, + SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, set_distribution_metric_to_request_time, }, { "serviceruntime.googleapis.com/api/producer/total_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::PRODUCER, + SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, set_distribution_metric_to_request_time, }, { "serviceruntime.googleapis.com/api/consumer/backend_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::CONSUMER, + SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, set_distribution_metric_to_backend_time, }, { "serviceruntime.googleapis.com/api/producer/backend_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::PRODUCER, + SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, set_distribution_metric_to_backend_time, }, { "serviceruntime.googleapis.com/api/consumer/request_overhead_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::CONSUMER, + SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, set_distribution_metric_to_overhead_time, }, { "serviceruntime.googleapis.com/api/producer/request_overhead_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::FINAL, SupportedMetric::PRODUCER, + SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, set_distribution_metric_to_overhead_time, }, { @@ -970,9 +970,13 @@ Status Proto::FillReportRequest(const ReportRequestInfo& info, if (send_consumer_metric || m->mark != SupportedMetric::CONSUMER) { if (m->set) { if ((info.is_first_report && m->tag == SupportedMetric::START) || - (info.is_final_report && + (info.is_final_report && info.streaming_durations > 0 && (m->tag == SupportedMetric::FINAL || m->tag == SupportedMetric::INTERMEDIATE)) || + (info.is_final_report && info.streaming_durations == 0 && + (m->tag == SupportedMetric::FINAL || + m->tag == SupportedMetric::NONSTREAMING || + m->tag == SupportedMetric::INTERMEDIATE)) || (!info.is_final_report && m->tag == SupportedMetric::INTERMEDIATE)) { status = (m->set)(*m, info, op); From ccb251d31f266d89181dcca5f7521c6ae5829399 Mon Sep 17 00:00:00 2001 From: Qian Sun Date: Wed, 28 Dec 2016 11:02:43 -0800 Subject: [PATCH 2/2] Do not set latency for streaming methods. --- .../api_manager/context/request_context.cc | 4 +++- .../src/api_manager/service_control/proto.cc | 20 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/contrib/endpoints/src/api_manager/context/request_context.cc b/contrib/endpoints/src/api_manager/context/request_context.cc index 57409c1ae58..d7ac9c93beb 100644 --- a/contrib/endpoints/src/api_manager/context/request_context.cc +++ b/contrib/endpoints/src/api_manager/context/request_context.cc @@ -264,7 +264,9 @@ void RequestContext::FillReportRequestInfo( // Must be after response_code and method are assigned. FillLogMessage(info); - response->GetLatencyInfo(&info->latency); + if(!method()->request_streaming() && !method()->response_streaming()) { + response->GetLatencyInfo(&info->latency); + } } } diff --git a/contrib/endpoints/src/api_manager/service_control/proto.cc b/contrib/endpoints/src/api_manager/service_control/proto.cc index 25f8d116dc9..17b921db076 100644 --- a/contrib/endpoints/src/api_manager/service_control/proto.cc +++ b/contrib/endpoints/src/api_manager/service_control/proto.cc @@ -55,7 +55,7 @@ struct SupportedMetric { ::google::api::MetricDescriptor_ValueType value_type; enum Mark { PRODUCER = 0, CONSUMER = 1 }; - enum Tag { START = 0, INTERMEDIATE = 1, FINAL = 2, NONSTREAMING = 3, }; + enum Tag { START = 0, INTERMEDIATE = 1, FINAL = 2 }; Tag tag; Mark mark; Status (*set)(const SupportedMetric& m, const ReportRequestInfo& info, @@ -321,42 +321,42 @@ const SupportedMetric supported_metrics[] = { "serviceruntime.googleapis.com/api/consumer/total_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, + SupportedMetric::FINAL, SupportedMetric::CONSUMER, set_distribution_metric_to_request_time, }, { "serviceruntime.googleapis.com/api/producer/total_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, + SupportedMetric::FINAL, SupportedMetric::PRODUCER, set_distribution_metric_to_request_time, }, { "serviceruntime.googleapis.com/api/consumer/backend_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, + SupportedMetric::FINAL, SupportedMetric::CONSUMER, set_distribution_metric_to_backend_time, }, { "serviceruntime.googleapis.com/api/producer/backend_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, + SupportedMetric::FINAL, SupportedMetric::PRODUCER, set_distribution_metric_to_backend_time, }, { "serviceruntime.googleapis.com/api/consumer/request_overhead_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::CONSUMER, + SupportedMetric::FINAL, SupportedMetric::CONSUMER, set_distribution_metric_to_overhead_time, }, { "serviceruntime.googleapis.com/api/producer/request_overhead_latencies", ::google::api::MetricDescriptor_MetricKind_DELTA, ::google::api::MetricDescriptor_ValueType_DISTRIBUTION, - SupportedMetric::NONSTREAMING, SupportedMetric::PRODUCER, + SupportedMetric::FINAL, SupportedMetric::PRODUCER, set_distribution_metric_to_overhead_time, }, { @@ -970,13 +970,9 @@ Status Proto::FillReportRequest(const ReportRequestInfo& info, if (send_consumer_metric || m->mark != SupportedMetric::CONSUMER) { if (m->set) { if ((info.is_first_report && m->tag == SupportedMetric::START) || - (info.is_final_report && info.streaming_durations > 0 && + (info.is_final_report && (m->tag == SupportedMetric::FINAL || m->tag == SupportedMetric::INTERMEDIATE)) || - (info.is_final_report && info.streaming_durations == 0 && - (m->tag == SupportedMetric::FINAL || - m->tag == SupportedMetric::NONSTREAMING || - m->tag == SupportedMetric::INTERMEDIATE)) || (!info.is_final_report && m->tag == SupportedMetric::INTERMEDIATE)) { status = (m->set)(*m, info, op);