Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analytics: Add adv_dis_result to analytics_recorder for onStartAdvertising and onStartDiscovery #3038

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions connections/implementation/analytics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cc_test(
shard_count = 16,
deps = [
":analytics",
"//connections:core_types",
"//internal/analytics:mock_event_logger",
"//internal/platform:base",
"//internal/platform:error_code_recorder",
Expand Down
428 changes: 362 additions & 66 deletions connections/implementation/analytics/analytics_recorder.cc

Large diffs are not rendered by default.

112 changes: 100 additions & 12 deletions connections/implementation/analytics/analytics_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace analytics {
class AnalyticsRecorder {
public:
explicit AnalyticsRecorder(::nearby::analytics::EventLogger *event_logger);
// For testing only.
AnalyticsRecorder(::nearby::analytics::EventLogger *event_logger,
bool no_record_time_millis);
virtual ~AnalyticsRecorder();

// TODO(edwinwu): Implement to pass real values for AdvertisingMetadata and
Expand All @@ -52,6 +55,9 @@ class AnalyticsRecorder {
void OnStartAdvertising(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium> &mediums,
const std::vector<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>
&operation_result_with_medium,
bool is_extended_advertisement_supported = false,
int connected_ap_frequency = 0, bool is_nfc_available = false)
ABSL_LOCKS_EXCLUDED(mutex_);
Expand All @@ -66,6 +72,9 @@ class AnalyticsRecorder {
void OnStartDiscovery(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium> &mediums,
const std::vector<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>
&operation_result_with_medium,
bool is_extended_advertisement_supported = false,
int connected_ap_frequency = 0, bool is_nfc_available = false)
ABSL_LOCKS_EXCLUDED(mutex_);
Expand All @@ -92,13 +101,17 @@ class AnalyticsRecorder {
ABSL_LOCKS_EXCLUDED(mutex_);

// Connection attempt
// Records an attempt with meta data at establishing an incoming physical
// connection.
void OnIncomingConnectionAttempt(
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string &connection_token,
ConnectionAttemptMetadataParams *connection_attempt_metadata_params)
ABSL_LOCKS_EXCLUDED(mutex_);
// Records an attempt with meta data at establishing an outgoing physical
// connection.
void OnOutgoingConnectionAttempt(
const std::string &remote_endpoint_id,
location::nearby::proto::connections::ConnectionAttemptType type,
Expand All @@ -117,7 +130,13 @@ class AnalyticsRecorder {
int try_count, const std::string &network_operator = {},
const std::string &country_code = {}, bool is_tdls_used = false,
bool wifi_hotspot_enabled = false, int max_wifi_tx_speed = 0,
int max_wifi_rx_speed = 0, int channel_width = -1);
int max_wifi_rx_speed = 0, int channel_width = -1,
location::nearby::proto::connections::OperationResultCode
operation_result_code = location::nearby::proto::connections::
OperationResultCode::DETAIL_UNKNOWN);
static location::nearby::proto::connections::OperationResultCode
GetChannelIoErrorResultCodeFromMedium(
location::nearby::proto::connections::Medium medium);

// Connection establishedSafeDisconnectionResult
void OnConnectionEstablished(
Expand All @@ -144,8 +163,9 @@ class AnalyticsRecorder {
ABSL_LOCKS_EXCLUDED(mutex_);
void OnIncomingPayloadDone(
const std::string &endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status)
ABSL_LOCKS_EXCLUDED(mutex_);
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadStarted(const std::vector<std::string> &endpoint_ids,
std::int64_t payload_id,
connections::PayloadType type,
Expand All @@ -157,8 +177,9 @@ class AnalyticsRecorder {
ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadDone(
const std::string &endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status)
ABSL_LOCKS_EXCLUDED(mutex_);
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_);

// BandwidthUpgrade
void OnBandwidthUpgradeStarted(
Expand All @@ -172,15 +193,17 @@ class AnalyticsRecorder {
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage) ABSL_LOCKS_EXCLUDED(mutex_);
error_stage,
location::nearby::proto::connections::OperationResultCode
operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_);
void OnBandwidthUpgradeSuccess(const std::string &endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);

// Error Code
void OnErrorCode(const ErrorCodeParams &params);

// Log the start client session event with start client session logging
// resouces setup (e.g. client_session_, started_client_session_time_)
// resources setup (e.g. client_session_, started_client_session_time_)
void LogStartSession() ABSL_LOCKS_EXCLUDED(mutex_);

// Invokes event_logger_.Log() at the end of life of client. Log action is
Expand All @@ -199,12 +222,21 @@ class AnalyticsRecorder {
class PendingPayload {
public:
PendingPayload(location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes)
std::int64_t total_size_bytes, bool no_record_time_millis)
: PendingPayload(type, total_size_bytes, no_record_time_millis,
location::nearby::proto::connections::
OperationResultCode::DETAIL_UNKNOWN) {}
PendingPayload(location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes, bool no_record_time_millis,
location::nearby::proto::connections::OperationResultCode
operation_result_code)
: start_time_(SystemClock::ElapsedRealtime()),
type_(type),
total_size_bytes_(total_size_bytes),
num_bytes_transferred_(0),
num_chunks_(0) {}
num_chunks_(0),
operation_result_code_(operation_result_code),
no_record_time_millis_(no_record_time_millis) {}
~PendingPayload() = default;

void AddChunk(std::int64_t chunk_size_bytes);
Expand All @@ -218,19 +250,31 @@ class AnalyticsRecorder {

std::int64_t total_size_bytes() const { return total_size_bytes_; }

void SetOperationResultCode(
location::nearby::proto::connections::OperationResultCode
operation_result_code) {
operation_result_code_ = operation_result_code;
}

private:
absl::Time start_time_;
location::nearby::proto::connections::PayloadType type_;
std::int64_t total_size_bytes_;
std::int64_t num_bytes_transferred_;
int num_chunks_;
location::nearby::proto::connections::OperationResultCode
operation_result_code_ = location::nearby::proto::connections::
OperationResultCode::DETAIL_UNKNOWN;
// For testing only.
bool no_record_time_millis_ = false;
};

class LogicalConnection {
public:
LogicalConnection(
location::nearby::proto::connections::Medium initial_medium,
const std::string &connection_token) {
const std::string &connection_token, bool no_record_time_millis)
: no_record_time_millis_(no_record_time_millis) {
PhysicalConnectionEstablished(initial_medium, connection_token);
}
LogicalConnection(const LogicalConnection &) = delete;
Expand Down Expand Up @@ -260,15 +304,19 @@ class AnalyticsRecorder {
void ChunkReceived(std::int64_t payload_id, std::int64_t size_bytes);
void IncomingPayloadDone(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status);
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code);
void OutgoingPayloadStarted(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes);
void ChunkSent(std::int64_t payload_id, std::int64_t size_bytes);
void OutgoingPayloadDone(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status);
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code);

std::vector<location::nearby::analytics::proto::ConnectionsLog::
EstablishedConnection>
Expand All @@ -286,6 +334,9 @@ class AnalyticsRecorder {
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
&pending_payloads,
location::nearby::proto::connections::DisconnectionReason reason);
location::nearby::proto::connections::OperationResultCode
GetPendingPayloadResultCodeFromReason(
location::nearby::proto::connections::DisconnectionReason reason);

location::nearby::proto::connections::Medium current_medium_ =
location::nearby::proto::connections::UNKNOWN_MEDIUM;
Expand All @@ -297,6 +348,8 @@ class AnalyticsRecorder {
incoming_payloads_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
outgoing_payloads_;
// For testing only.
bool no_record_time_millis_ = false;
};

bool CanRecordAnalyticsLocked(absl::string_view method_name)
Expand Down Expand Up @@ -338,11 +391,43 @@ class AnalyticsRecorder {
void MarkConnectionRequestIgnoredLocked(
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest
*request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void OnIncomingConnectionAttemptLocked(
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string &connection_token,
ConnectionAttemptMetadataParams *connection_attempt_metadata_params)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void OnOutgoingConnectionAttemptLocked(
const std::string &remote_endpoint_id,
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string &connection_token,
ConnectionAttemptMetadataParams *connection_attempt_metadata_params)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool ConnectionAttemptResultCodeExistedLocked(
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptDirection
direction,
const std::string &connection_token,
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::OperationResultCode
operation_result_code) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool EraseIfBandwidthUpgradeRecordExistedLocked(
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage,
location::nearby::proto::connections::OperationResultCode
operation_result_code) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishUpgradeAttemptLocked(
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage,
location::nearby::proto::connections::OperationResultCode
operation_result_code,
bool erase_item = true) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishStrategySessionLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);

Expand All @@ -364,6 +449,9 @@ class AnalyticsRecorder {
// Protects all sub-protos reading and writing in ConnectionLog.
Mutex mutex_;

// For testing only.
bool no_record_time_millis_ = false;

// ClientSession
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::ClientSession>
Expand Down
Loading
Loading