Internal changes

PiperOrigin-RevId: 686569259
This commit is contained in:
Francis Tsui
2024-10-16 11:03:45 -07:00
committed by Copybara-Service
parent ccdcd15e83
commit 42bedd6c8a
6 changed files with 71 additions and 3 deletions
+5 -1
View File
@@ -32,7 +32,7 @@ option objc_class_prefix = "GNSHP";
// in NearbyClearcutLogger (for android, or clearcut_event_logger as the
// equivalence for Windows) for all events (may exclude settings), and
// session_id for a pair of events (start and end of a session).
// Next id: 69
// Next id: 70
enum EventType {
UNKNOWN_EVENT_TYPE = 0;
@@ -300,6 +300,9 @@ enum EventType {
// High quality event setup
HIGH_QUALITY_MEDIUM_SETUP = 68;
// RPC call status
RPC_CALL_STATUS = 69;
// LINT.ThenChange(//depot/google3/location/nearby/proto/nearby_event_codes.proto:SharingEventCode)
}
@@ -310,6 +313,7 @@ enum EventCategory {
SENDING_EVENT = 1;
RECEIVING_EVENT = 2;
SETTINGS_EVENT = 3;
RPC_EVENT = 4;
}
// Status of nearby sharing.
+3 -1
View File
@@ -34,6 +34,8 @@ cc_library(
"//sharing/proto:enums_cc_proto",
"//sharing/proto/analytics:sharing_log_cc_proto",
"@com_google_absl//absl/random",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/time",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:protobuf_lite",
],
@@ -55,8 +57,8 @@ cc_test(
"//sharing/proto/analytics:sharing_log_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:protobuf_lite",
],
)
+18
View File
@@ -21,6 +21,8 @@
#include "google/protobuf/duration.pb.h"
#include "absl/random/random.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/analytics/analytics_device_settings.h"
#include "sharing/analytics/analytics_information.h"
@@ -826,6 +828,22 @@ void AnalyticsRecorder::NewVerifyAPKStatus(
LogEvent(*sharing_log);
}
void AnalyticsRecorder::NewRpcCallStatus(
absl::string_view rpc_name,
SharingLog::RpcCallStatus::RpcDirection direction,
int error_code, absl::Duration latency) {
std::unique_ptr<SharingLog> sharing_log =
CreateSharingLog(EventCategory::RPC_EVENT, EventType::RPC_CALL_STATUS);
auto* rpc_call_status = sharing_log->mutable_rpc_call_status();
rpc_call_status->set_rpc_name(std::string(rpc_name));
rpc_call_status->set_direction(direction);
rpc_call_status->set_error_code(error_code);
rpc_call_status->set_latency_millis(absl::ToInt64Milliseconds(latency));
LogEvent(*sharing_log);
}
// Start private methods.
std::unique_ptr<SharingLog> AnalyticsRecorder::CreateSharingLog(
+8
View File
@@ -20,6 +20,8 @@
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/analytics/event_logger.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/analytics/analytics_device_settings.h"
@@ -194,6 +196,12 @@ class AnalyticsRecorder {
location::nearby::proto::sharing::VerifyAPKStatus status,
location::nearby::proto::sharing::ApkSource source);
void NewRpcCallStatus(
absl::string_view rpc_name,
nearby::sharing::analytics::proto::SharingLog::RpcCallStatus::RpcDirection
direction,
int error_code, absl::Duration latency);
// Generates a random number for session ID or flow ID.
int64_t GenerateNextId();
@@ -24,6 +24,7 @@
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/analytics/mock_event_logger.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/analytics/analytics_device_settings.h"
@@ -887,6 +888,23 @@ TEST_F(AnalyticsRecorderTest, NewVerifyAPKStatus) {
::location::nearby::proto::sharing::ApkSource::APK_FROM_SD_CARD);
}
TEST_F(AnalyticsRecorderTest, NewRpcCallStatus) {
EXPECT_CALL(event_logger(), Log(An<const SharingLog&>()))
.WillOnce([](const SharingLog& log) {
EXPECT_EQ(log.event_type(), EventType::RPC_CALL_STATUS);
EXPECT_EQ(log.event_category(), EventCategory::RPC_EVENT);
EXPECT_EQ(log.rpc_call_status().rpc_name(), "service.rpc_name");
EXPECT_EQ(log.rpc_call_status().direction(),
SharingLog::RpcCallStatus::OUTGOING);
EXPECT_EQ(log.rpc_call_status().error_code(), 123);
EXPECT_EQ(log.rpc_call_status().latency_millis(), 456);
});
analytics_recoder().NewRpcCallStatus(
"service.rpc_name", SharingLog::RpcCallStatus::OUTGOING, 123,
absl::Milliseconds(456));
}
TEST_F(AnalyticsRecorderTest, GenerateID) {
int64_t id = analytics_recoder().GenerateNextId();
EXPECT_GT(id, 0);
@@ -31,7 +31,7 @@ option objc_class_prefix = "GNCP";
// Top-level log proto for all NearbySharing logging.
// Each log contains a key (event_type), value (a verb-noun event) pair.
// Next Tag: 78
// Next Tag: 79
// LINT.IfChange
message SharingLog {
/* collection_basis = {
@@ -212,6 +212,8 @@ message SharingLog {
optional HighQualityMediumSetup high_quality_medium_setup = 77;
optional RpcCallStatus rpc_call_status = 78;
// Used only for Nearby Share Windows app now.
message AppInfo {
// e.g. "1.0.408"
@@ -904,5 +906,21 @@ message SharingLog {
optional int64 duration_millis = 3;
optional bool is_timeout = 4;
}
message RpcCallStatus {
enum RpcDirection {
UNKNOWN_RPC_DIRECTION = 0;
INCOMING = 1;
OUTGOING = 2;
}
optional RpcDirection direction = 1;
// Name of RPC in <ServiceName>.<MethodName> format.
optional string rpc_name = 2;
// Canonical error code of RPC.
optional int32 error_code = 3;
// Latency of RPC call in milliseconds.
optional int64 latency_millis = 4;
}
}
// LINT.ThenChange(//depot/google3/logs/proto/location/nearby/nearby_client_log.proto)