Skip to content

Commit

Permalink
analytics: Add operation result code for Payload analytics, III
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 696124298
  • Loading branch information
edwinwugoog authored and copybara-github committed Nov 21, 2024
1 parent fcf48fc commit fc93e58
Show file tree
Hide file tree
Showing 33 changed files with 1,190 additions and 424 deletions.
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
301 changes: 271 additions & 30 deletions connections/implementation/analytics/analytics_recorder.cc

Large diffs are not rendered by default.

90 changes: 80 additions & 10 deletions connections/implementation/analytics/analytics_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,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 +121,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 +154,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 +168,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 +184,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 @@ -200,11 +214,19 @@ class AnalyticsRecorder {
public:
PendingPayload(location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes)
: PendingPayload(type, total_size_bytes,
location::nearby::proto::connections::
OperationResultCode::DETAIL_UNKNOWN) {}
PendingPayload(location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes,
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) {}
~PendingPayload() = default;

void AddChunk(std::int64_t chunk_size_bytes);
Expand All @@ -218,12 +240,21 @@ 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;
};

class LogicalConnection {
Expand Down Expand Up @@ -260,15 +291,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 +321,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 Down Expand Up @@ -338,11 +376,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 Down
Loading

0 comments on commit fc93e58

Please sign in to comment.