Creates a new license request latency metric
Previously, we did not have a license request latency metric. This is a notable limitation in our metrics. This adds a metric that captures the timing between a GenerateKeyRequest and an AddKey operation. Bug: 72994956 Test: New unit tests. Google Play Change-Id: If99c187399c02f9b5d4c355732af7588bbbefb11
This commit is contained in:
@@ -199,6 +199,12 @@ class CdmSession {
|
||||
|
||||
bool UpdateUsageInfo();
|
||||
|
||||
CdmResponseType GenerateKeyRequestInternal(
|
||||
const InitializationData& init_data, CdmLicenseType license_type,
|
||||
const CdmAppParameterMap& app_parameters, CdmKeyRequest* key_request);
|
||||
virtual CdmResponseType AddKeyInternal(const CdmKeyResponse& key_response);
|
||||
void UpdateRequestLatencyTiming(CdmResponseType sts);
|
||||
|
||||
// These setters are for testing only. Takes ownership of the pointers.
|
||||
void set_license_parser(CdmLicense* license_parser);
|
||||
void set_crypto_session(CryptoSession* crypto_session);
|
||||
@@ -209,6 +215,8 @@ class CdmSession {
|
||||
metrics::SessionMetrics* metrics_;
|
||||
metrics::CryptoMetrics* crypto_metrics_;
|
||||
metrics::TimerMetric life_span_;
|
||||
metrics::TimerMetric license_request_latency_;
|
||||
CdmKeyRequestType key_request_type_;
|
||||
|
||||
bool initialized_;
|
||||
bool closed_; // Session closed, but final shared_ptr has not been released.
|
||||
|
||||
@@ -324,7 +324,23 @@ CdmResponseType CdmSession::RestoreUsageSession(
|
||||
return KEY_ADDED;
|
||||
}
|
||||
|
||||
// This is a thin wrapper that initiates the latency metric.
|
||||
CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
const InitializationData& init_data, CdmLicenseType license_type,
|
||||
const CdmAppParameterMap& app_parameters, CdmKeyRequest* key_request) {
|
||||
CdmResponseType result = GenerateKeyRequestInternal(
|
||||
init_data, license_type, app_parameters, key_request);
|
||||
// Note that GenerateReleaseRequest and GenerateRenewalRequest will initialize
|
||||
// the timer themselves. This is duplicate because there are duplicate paths
|
||||
// for calling GenerateReleaseRequest and GenerateRenewalRequest.
|
||||
if (result == KEY_MESSAGE) {
|
||||
key_request_type_ = key_request->type;
|
||||
license_request_latency_.Start(); // Start or restart timer.
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CdmResponseType CdmSession::GenerateKeyRequestInternal(
|
||||
const InitializationData& init_data, CdmLicenseType license_type,
|
||||
const CdmAppParameterMap& app_parameters,
|
||||
CdmKeyRequest* key_request) {
|
||||
@@ -410,8 +426,15 @@ CdmResponseType CdmSession::GenerateKeyRequest(
|
||||
}
|
||||
}
|
||||
|
||||
// AddKey() - Accept license response and extract key info.
|
||||
// This thin wrapper allows us to update metrics.
|
||||
CdmResponseType CdmSession::AddKey(const CdmKeyResponse& key_response) {
|
||||
CdmResponseType sts = AddKeyInternal(key_response);
|
||||
UpdateRequestLatencyTiming(sts);
|
||||
return sts;
|
||||
}
|
||||
|
||||
// AddKeyInternal() - Accept license response and extract key info.
|
||||
CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
|
||||
if (!initialized_) {
|
||||
LOGE("CdmSession::AddKey: not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
@@ -602,6 +625,8 @@ CdmResponseType CdmSession::GenerateRenewalRequest(
|
||||
if (is_offline_) {
|
||||
offline_key_renewal_request_ = key_request->message;
|
||||
}
|
||||
key_request_type_ = key_request->type;
|
||||
license_request_latency_.Start(); // Start or restart timer.
|
||||
return KEY_MESSAGE;
|
||||
}
|
||||
|
||||
@@ -613,6 +638,10 @@ CdmResponseType CdmSession::RenewKey(const CdmKeyResponse& key_response) {
|
||||
}
|
||||
CdmResponseType sts =
|
||||
license_parser_->HandleKeyUpdateResponse(true, key_response);
|
||||
|
||||
// Record the timing on success.
|
||||
UpdateRequestLatencyTiming(sts);
|
||||
|
||||
if (sts != KEY_ADDED) return (sts == KEY_ERROR) ? RENEW_KEY_ERROR_1 : sts;
|
||||
|
||||
if (is_offline_) {
|
||||
@@ -630,6 +659,7 @@ CdmResponseType CdmSession::GenerateReleaseRequest(
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
is_release_ = true;
|
||||
license_request_latency_.Clear();
|
||||
CdmResponseType status = license_parser_->PrepareKeyUpdateRequest(
|
||||
false, app_parameters_, usage_table_header_ == NULL ? NULL : this,
|
||||
&key_request->message, &key_request->url);
|
||||
@@ -658,6 +688,10 @@ CdmResponseType CdmSession::GenerateReleaseRequest(
|
||||
return RELEASE_USAGE_INFO_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
key_request_type_ = key_request->type;
|
||||
license_request_latency_.Start(); // Start or restart timer.
|
||||
|
||||
return KEY_MESSAGE;
|
||||
}
|
||||
|
||||
@@ -669,6 +703,9 @@ CdmResponseType CdmSession::ReleaseKey(const CdmKeyResponse& key_response) {
|
||||
}
|
||||
CdmResponseType sts =
|
||||
license_parser_->HandleKeyUpdateResponse(false, key_response);
|
||||
// Record the timing on success.
|
||||
UpdateRequestLatencyTiming(sts);
|
||||
|
||||
if (sts != KEY_ADDED) return (sts == KEY_ERROR) ? RELEASE_KEY_ERROR : sts;
|
||||
|
||||
if (is_offline_ || has_provider_session_token()) {
|
||||
@@ -1046,6 +1083,14 @@ bool CdmSession::UpdateUsageInfo() {
|
||||
usage_data);
|
||||
}
|
||||
|
||||
void CdmSession::UpdateRequestLatencyTiming(CdmResponseType sts) {
|
||||
if (sts == KEY_ADDED && license_request_latency_.IsStarted()) {
|
||||
metrics_->cdm_session_license_request_latency_ms_.Record(
|
||||
license_request_latency_.AsMs(), key_request_type_);
|
||||
}
|
||||
license_request_latency_.Clear();
|
||||
}
|
||||
|
||||
// For testing only - takes ownership of pointers
|
||||
|
||||
void CdmSession::set_license_parser(CdmLicense* license_parser) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "file_store.h"
|
||||
#include "license_request.h"
|
||||
#include "log.h"
|
||||
#include "metrics.pb.h"
|
||||
#include "OEMCryptoCENC.h"
|
||||
#include "properties.h"
|
||||
#include "scoped_ptr.h"
|
||||
@@ -26,6 +27,9 @@
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
using drm_metrics::WvCdmMetrics;
|
||||
using drm_metrics::DistributionMetric;
|
||||
|
||||
namespace {
|
||||
|
||||
// Http OK response code.
|
||||
@@ -460,12 +464,43 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
|
||||
CdmKeySetId key_set_id;
|
||||
EXPECT_EQ(KEY_ADDED,
|
||||
cdm_engine_.AddKey(session_id_, resp, &key_set_id));
|
||||
VerifyLicenseRequestLatency(CdmKeyRequestType::kKeyRequestTypeInitial,
|
||||
*cdm_engine_.GetMetrics());
|
||||
}
|
||||
|
||||
void VerifyRenewalKeyResponse(const std::string& server_url,
|
||||
const std::string& client_auth) {
|
||||
std::string resp = GetKeyRequestResponse(server_url, client_auth);
|
||||
EXPECT_EQ(KEY_ADDED, cdm_engine_.RenewKey(session_id_, resp));
|
||||
VerifyLicenseRequestLatency(CdmKeyRequestType::kKeyRequestTypeRenewal,
|
||||
*cdm_engine_.GetMetrics());
|
||||
}
|
||||
|
||||
void VerifyLicenseRequestLatency(
|
||||
CdmKeyRequestType key_request_type,
|
||||
const metrics::EngineMetrics& engine_metrics) {
|
||||
WvCdmMetrics metrics_proto;
|
||||
engine_metrics.Serialize(&metrics_proto);
|
||||
bool has_request_type = false;
|
||||
for (int i = 0; i < metrics_proto.session_metrics_size(); i++) {
|
||||
WvCdmMetrics::SessionMetrics session_metrics =
|
||||
metrics_proto.session_metrics(i);
|
||||
for (int j = 0;
|
||||
j < session_metrics.cdm_session_license_request_latency_ms_size();
|
||||
j++) {
|
||||
DistributionMetric latency_distribution =
|
||||
session_metrics.cdm_session_license_request_latency_ms(j);
|
||||
if (latency_distribution.attributes().key_request_type()
|
||||
== key_request_type && latency_distribution.operation_count() > 0) {
|
||||
has_request_type = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string serialized_metrics;
|
||||
ASSERT_TRUE(metrics_proto.SerializeToString(&serialized_metrics));
|
||||
EXPECT_TRUE(has_request_type)
|
||||
<< "Expected request type " << key_request_type << " was not found. "
|
||||
<< "metrics: " << wvcdm::b2a_hex(serialized_metrics);
|
||||
}
|
||||
|
||||
std::string server_url_;
|
||||
|
||||
Reference in New Issue
Block a user