Remove EventLogger.

PiperOrigin-RevId: 925032163
This commit is contained in:
Francis Tsui
2026-06-01 18:45:11 -07:00
committed by Copybara-Service
parent 1e9af15efb
commit 0e96ed9795
25 changed files with 50 additions and 4904 deletions
+2 -2
View File
@@ -53,7 +53,6 @@ cc_library(
"//connections:core_types",
"//connections/implementation/analytics:analytics_recorder_impl",
"//connections/implementation/flags:connections_flags",
"//internal/analytics:event_logger",
"//internal/flags:flag_reader",
"//internal/flags:nearby_flags",
"//internal/platform:base",
@@ -61,7 +60,8 @@ cc_library(
"//internal/platform:logging",
"//internal/platform:mac_address",
"//internal/platform:types",
"//internal/proto/analytics:connections_log_cc_proto",
"//location/nearby/analytics/cpp/logging:event_logger",
"//location/nearby/analytics/cpp/proto:connections_log_cc_proto",
"//sharing/proto/analytics:sharing_log_cc_proto",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/container:flat_hash_map",
+9 -2
View File
@@ -25,6 +25,10 @@
#include <utility>
#include <vector>
#if !defined(NC_OSS_BUILD)
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "location/nearby/analytics/cpp/proto/connections_log.pb.h"
#endif // !defined(NC_OSS_BUILD)
#include "absl/base/no_destructor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
@@ -45,7 +49,6 @@
#include "connections/payload.h"
#include "connections/status.h"
#include "connections/strategy.h"
#include "internal/analytics/event_logger.h"
#include "internal/flags/flag.h"
#include "internal/flags/flag_reader.h"
#include "internal/flags/nearby_flags.h"
@@ -53,7 +56,6 @@
#include "internal/platform/file.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
#include "internal/proto/analytics/connections_log.pb.h"
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
#if TARGET_OS_IOS
#include "internal/platform/implementation/apple/nearby_logger.h"
@@ -122,6 +124,7 @@ class FlagReaderWrapper : public nearby::flags::FlagReader {
NC_PHENOTYPE_FLAG_READER phenotype_flag_reader_;
};
#if !defined(NC_OSS_BUILD)
// This is a bridging class between the C API and the C++ EventLogger interface.
class NcEventLogger : public ::nearby::analytics::EventLogger {
public:
@@ -149,6 +152,10 @@ class NcEventLogger : public ::nearby::analytics::EventLogger {
private:
const NC_EVENT_LOGGER* event_logger_;
};
#else // !defined(NC_OSS_BUILD)
class NcEventLogger;
#endif // !defined(NC_OSS_BUILD)
} // namespace
typedef struct NcContext {
-2
View File
@@ -468,7 +468,6 @@ cc_test(
"//connections/implementation/analytics:mock_analytics_recorder",
"//connections/implementation/flags:connections_flags",
"//connections/v3:v3_types",
"//internal/analytics:mock_event_logger",
"//internal/flags:nearby_flags",
"//internal/interop:device",
"//internal/platform:base",
@@ -478,7 +477,6 @@ cc_test(
"//internal/platform/implementation/g3", # build_cleaner: keep
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
+4 -6
View File
@@ -54,12 +54,12 @@ cc_library(
deps = [
":analytics",
"//connections:core_types",
"//internal/analytics:event_logger",
"//internal/platform:error_code_recorder",
"//internal/platform:logging",
"//internal/platform:types",
"//internal/platform/implementation:types",
"//internal/proto/analytics:connections_log_cc_proto",
"//location/nearby/analytics/cpp/logging:event_logger",
"//location/nearby/analytics/cpp/proto:connections_log_cc_proto",
"//proto:connections_enums_cc_proto",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
@@ -99,15 +99,13 @@ cc_test(
":analytics",
":analytics_recorder_impl",
"//connections:core_types",
"//internal/analytics:mock_event_logger",
"//internal/platform:base",
"//internal/platform:error_code_recorder",
"//internal/platform:logging",
"//internal/platform:test_util",
"//internal/platform:types",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//internal/proto/analytics:connections_log_cc_proto",
"//internal/test",
"//location/nearby/analytics/cpp/logging:mock_event_logger",
"//location/nearby/analytics/cpp/proto:connections_log_cc_proto",
"//net/proto2/contrib/parse_proto:parse_text_proto",
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
File diff suppressed because it is too large Load Diff
@@ -1,459 +0,0 @@
// Copyright 2022-2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
#define ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/container/btree_map.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "connections/implementation/analytics/advertising_metadata_params.h"
#include "connections/implementation/analytics/analytics_recorder.h"
#include "connections/implementation/analytics/connection_attempt_metadata_params.h"
#include "connections/implementation/analytics/discovery_metadata_params.h"
#include "connections/payload_type.h"
#include "connections/strategy.h"
#include "internal/analytics/event_logger.h"
#include "internal/platform/error_code_params.h"
#include "internal/platform/implementation/system_clock.h"
#include "internal/platform/mutex.h"
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace nearby::analytics {
class AnalyticsRecorderImpl : public AnalyticsRecorder {
public:
explicit AnalyticsRecorderImpl(
::nearby::analytics::EventLogger* event_logger);
~AnalyticsRecorderImpl() override;
// Advertising phase
void OnStartAdvertising(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>& mediums,
AdvertisingMetadataParams* advertising_metadata_params) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnStopAdvertising() override ABSL_LOCKS_EXCLUDED(mutex_);
int GetNextAdvertisingUpdateIndex() override ABSL_LOCKS_EXCLUDED(mutex_);
// Connection listening
void OnStartedIncomingConnectionListening(
connections::Strategy strategy) override ABSL_LOCKS_EXCLUDED(mutex_);
void OnStoppedIncomingConnectionListening() override
ABSL_LOCKS_EXCLUDED(mutex_);
// Discovery phase
void OnStartDiscovery(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>& mediums,
DiscoveryMetadataParams* discovery_metadata_params) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnStopDiscovery() override ABSL_LOCKS_EXCLUDED(mutex_);
int GetNextDiscoveryUpdateIndex() override ABSL_LOCKS_EXCLUDED(mutex_);
void OnEndpointFound(location::nearby::proto::connections::Medium medium)
override ABSL_LOCKS_EXCLUDED(mutex_);
// Connection request
void OnRequestConnection(const connections::Strategy& strategy,
const std::string& endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnConnectionRequestReceived(const std::string& remote_endpoint_id)
override ABSL_LOCKS_EXCLUDED(mutex_);
void OnConnectionRequestSent(const std::string& remote_endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnRemoteEndpointAccepted(const std::string& remote_endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnLocalEndpointAccepted(const std::string& remote_endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnRemoteEndpointRejected(const std::string& remote_endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnLocalEndpointRejected(const std::string& remote_endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
// Connection attempt
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)
override ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingConnectionAttempt(
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)
override ABSL_LOCKS_EXCLUDED(mutex_);
// Connection established
void OnConnectionEstablished(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
const std::string& connection_token) override ABSL_LOCKS_EXCLUDED(mutex_);
void OnConnectionClosed(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::DisconnectionReason reason,
SafeDisconnectionResult result) override ABSL_LOCKS_EXCLUDED(mutex_);
// Payload
void OnIncomingPayloadStarted(const std::string& endpoint_id,
std::int64_t payload_id,
connections::PayloadType type,
std::int64_t total_size_bytes) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnPayloadChunkReceived(const std::string& endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnIncomingPayloadDone(
const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) override ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadStarted(const std::vector<std::string>& endpoint_ids,
std::int64_t payload_id,
connections::PayloadType type,
std::int64_t total_size_bytes) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnPayloadChunkSent(const std::string& endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadDone(
const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) override ABSL_LOCKS_EXCLUDED(mutex_);
// BandwidthUpgrade
void OnBandwidthUpgradeStarted(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium from_medium,
location::nearby::proto::connections::Medium to_medium,
location::nearby::proto::connections::ConnectionAttemptDirection
direction,
const std::string& connection_token) override ABSL_LOCKS_EXCLUDED(mutex_);
void UpdateBwUpgradeNetworkInfo(const std::string& endpoint_id,
int num_interfaces,
int num_ipv6_only_interfaces) override
ABSL_LOCKS_EXCLUDED(mutex_);
void OnBandwidthUpgradeError(
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) override ABSL_LOCKS_EXCLUDED(mutex_);
void OnBandwidthUpgradeSuccess(const std::string& endpoint_id) override
ABSL_LOCKS_EXCLUDED(mutex_);
// Error Code
void OnErrorCode(const ErrorCodeParams& params) override;
void LogStartSession() override ABSL_LOCKS_EXCLUDED(mutex_);
void LogSession() override ABSL_LOCKS_EXCLUDED(mutex_);
bool IsSessionLogged() override;
location::nearby::proto::connections::OperationResultCategory
GetOperationResultCategory(
location::nearby::proto::connections::OperationResultCode result_code)
override;
void Sync() override;
private:
// Tracks the chunks and duration of a Payload on a particular medium.
class PendingPayload {
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),
operation_result_code_(operation_result_code) {}
~PendingPayload() = default;
void AddChunk(std::int64_t chunk_size_bytes);
location::nearby::analytics::proto::ConnectionsLog::Payload GetProtoPayload(
location::nearby::proto::connections::PayloadStatus status);
location::nearby::proto::connections::PayloadType type() const {
return type_;
}
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 {
public:
LogicalConnection(
location::nearby::proto::connections::Medium initial_medium,
const std::string& connection_token) {
PhysicalConnectionEstablished(initial_medium, connection_token);
}
LogicalConnection(const LogicalConnection&) = delete;
LogicalConnection(LogicalConnection&& other)
: current_medium_(std::move(other.current_medium_)),
physical_connections_(std::move(other.physical_connections_)),
incoming_payloads_(std::move(other.incoming_payloads_)),
outgoing_payloads_(std::move(other.outgoing_payloads_)) {}
LogicalConnection& operator=(const LogicalConnection&) = delete;
LogicalConnection&& operator=(LogicalConnection&&) = delete;
~LogicalConnection() = default;
void PhysicalConnectionEstablished(
location::nearby::proto::connections::Medium medium,
const std::string& connection_token);
void PhysicalConnectionClosed(
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::DisconnectionReason reason,
SafeDisconnectionResult result);
void CloseAllPhysicalConnections();
void IncomingPayloadStarted(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes);
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::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::OperationResultCode
operation_result_code);
std::vector<location::nearby::analytics::proto::ConnectionsLog::
EstablishedConnection>
GetEstablisedConnections();
private:
void FinishPhysicalConnection(
location::nearby::analytics::proto::ConnectionsLog::
EstablishedConnection* established_connection,
location::nearby::proto::connections::DisconnectionReason reason,
SafeDisconnectionResult result);
std::vector<location::nearby::analytics::proto::ConnectionsLog::Payload>
ResolvePendingPayloads(
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;
absl::btree_map<location::nearby::proto::connections::Medium,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::EstablishedConnection>>
physical_connections_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
incoming_payloads_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
outgoing_payloads_;
};
bool CanRecordAnalyticsLocked(absl::string_view method_name)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
// Callbacks the ConnectionsLog proto byte array data to the EventLogger with
// ClientSession sub-proto.
void LogClientSessionLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Callbacks the ConnectionsLog proto byte array data to the EventLogger.
void LogEvent(location::nearby::proto::connections::EventType event_type);
void UpdateStrategySessionLocked(
connections::Strategy strategy,
location::nearby::proto::connections::SessionRole role)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RecordAdvertisingPhaseDurationAndReasonLocked(bool on_stop) const
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishAdvertisingPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RecordDiscoveryPhaseDurationAndReasonLocked(bool on_stop) const
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishDiscoveryPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool UpdateAdvertiserConnectionRequestLocked(
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest*
request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool UpdateDiscovererConnectionRequestLocked(
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest*
request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool BothEndpointsRespondedLocked(
location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest*
request) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void LocalEndpointRespondedLocked(
const std::string& remote_endpoint_id,
location::nearby::proto::connections::ConnectionRequestResponse response)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RemoteEndpointRespondedLocked(
const std::string& remote_endpoint_id,
location::nearby::proto::connections::ConnectionRequestResponse response)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
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_);
int GetLatestUpdateIndexLocked(
const std::vector<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>& list)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
location::nearby::proto::connections::ConnectionsStrategy
StrategyToConnectionStrategy(connections::Strategy strategy);
location::nearby::proto::connections::PayloadType
PayloadTypeToProtoPayloadType(connections::PayloadType type);
// Not owned by AnalyticsRecorderImpl. Pointer must refer to a valid object
// that outlives the one constructed.
::nearby::analytics::EventLogger* event_logger_;
// Protects all sub-protos reading and writing in ConnectionLog.
Mutex mutex_;
// ClientSession
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::ClientSession>
client_session_;
absl::Time started_client_session_time_;
bool session_was_logged_ ABSL_GUARDED_BY(mutex_) = false;
bool start_client_session_was_logged_ ABSL_GUARDED_BY(mutex_) = false;
// Current StrategySession
connections::Strategy current_strategy_ ABSL_GUARDED_BY(mutex_) =
connections::Strategy::kNone;
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::StrategySession>
current_strategy_session_ ABSL_GUARDED_BY(mutex_);
absl::Time started_strategy_session_time_ ABSL_GUARDED_BY(mutex_);
// Current AdvertisingPhase
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::AdvertisingPhase>
current_advertising_phase_;
absl::Time started_advertising_phase_time_ = absl::InfinitePast();
// Current DiscoveryPhase
std::unique_ptr<
location::nearby::analytics::proto::ConnectionsLog::DiscoveryPhase>
current_discovery_phase_;
absl::Time started_discovery_phase_time_ = absl::InfinitePast();
absl::btree_map<std::string,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::ConnectionRequest>>
incoming_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::ConnectionRequest>>
outgoing_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string, std::unique_ptr<LogicalConnection>>
active_connections_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string,
std::unique_ptr<location::nearby::analytics::proto::
ConnectionsLog::BandwidthUpgradeAttempt>>
bandwidth_upgrade_attempts_ ABSL_GUARDED_BY(mutex_);
};
} // namespace nearby::analytics
#endif // ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
File diff suppressed because it is too large Load Diff
-50
View File
@@ -1,50 +0,0 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
licenses(["notice"])
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cc_library(
name = "event_logger",
hdrs = [
"event_logger.h",
],
visibility = [
"//connections:__subpackages__",
"//location/nearby/analytics/cpp:__subpackages__",
"//location/nearby/cpp/experiments:__subpackages__",
"//location/nearby/sharing/lib:__subpackages__",
"//sharing:__subpackages__",
],
deps = [
"//internal/proto/analytics:connections_log_cc_proto",
"//sharing/proto/analytics:sharing_log_cc_proto",
],
)
cc_library(
name = "mock_event_logger",
testonly = True,
hdrs = [
"mock_event_logger.h",
"sharing_log_matchers.h",
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//visibility:public"],
deps = [
":event_logger",
"@com_google_googletest//:gtest_for_library_testonly",
"@com_google_protobuf//:protobuf_lite",
],
)
-41
View File
@@ -1,41 +0,0 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NEARBY_ANALYTICS_EVENT_LOGGER_H_
#define NEARBY_ANALYTICS_EVENT_LOGGER_H_
#include "internal/proto/analytics/connections_log.pb.h"
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
namespace nearby {
namespace analytics {
// Allows callers to log the proto collected at the client (e.g. Nearby
// Connections, Nearby Sharing, etc). Callers need to implement the API
// if they want to collect this log.
class EventLogger {
public:
virtual ~EventLogger() = default;
// Logs the proto details. Might block to do I/O, e.g. upload
// synchronously to some metrics server.
virtual void Log(
const location::nearby::analytics::proto::ConnectionsLog& message) = 0;
virtual void Log(const sharing::analytics::proto::SharingLog& message) = 0;
};
} // namespace analytics
} // namespace nearby
#endif // NEARBY_ANALYTICS_EVENT_LOGGER_H_
-38
View File
@@ -1,38 +0,0 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
#define THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
#include "gmock/gmock.h"
#include "internal/analytics/event_logger.h"
namespace nearby::analytics {
class MockEventLogger : public ::nearby::analytics::EventLogger {
public:
MockEventLogger() = default;
~MockEventLogger() override = default;
MOCK_METHOD(
void, Log,
(const location::nearby::analytics::proto::ConnectionsLog& message),
(override));
MOCK_METHOD(void, Log, (const sharing::analytics::proto::SharingLog& message),
(override));
};
} // namespace nearby::analytics
#endif // THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
-64
View File
@@ -1,64 +0,0 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
#define THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
#include "gmock/gmock.h"
namespace nearby::analytics {
MATCHER_P(HasCategory, category, "has category") {
return arg.event_category() == category;
}
MATCHER_P(HasEventType, event_type, "has event type") {
return arg.event_type() == event_type;
}
MATCHER_P(HasAction, action, "has action") {
return arg.action() == action;
}
MATCHER_P(HasSessionId, session_id, "has session id") {
return arg.session_id() == session_id;
}
MATCHER_P(HasDurationMillis, duration_millis, "has duration millis") {
return arg.duration_millis() == duration_millis;
}
MATCHER_P(SharingLogHasStatus, status, "has status") {
return arg.status() == status;
}
MATCHER_P(HasRpcName, rpc_name, "has rpc_name") {
return arg.rpc_name() == rpc_name;
}
MATCHER_P(HasDirection, direction, "has direction") {
return arg.direction() == direction;
}
MATCHER_P(HasErrorCode, error_code, "has error_code") {
return arg.error_code() == error_code;
}
MATCHER_P(HasLatencyMillis, latency_millis, "has latency_millis") {
return arg.latency_millis() == latency_millis;
}
} // namespace nearby::analytics
#endif // THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_SHARING_LOG_MATCHERS_H_
+2
View File
@@ -182,6 +182,8 @@ cc_library(
tags = ["keep_dep"], # Prevent build_cleaner from removing the dependency.
visibility = [
"//:__subpackages__",
"//location/nearby/analytics/cpp:__subpackages__",
"//location/nearby/cpp:__subpackages__",
"//location/nearby/sharing/lib:__subpackages__",
],
deps = [
@@ -196,7 +196,6 @@ cc_library(
"//internal/preferences:__subpackages__",
"//internal/proto/analytics:__subpackages__",
"//internal/weave:__subpackages__",
"//location/nearby/cpp:__subpackages__",
"//location/nearby/sharing/sdk:__subpackages__",
"//sharing:__subpackages__",
"//third_party/nearby/presence:__subpackages__",
+16
View File
@@ -13,7 +13,9 @@
# limitations under the License.
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@com_google_protobuf//rust:defs.bzl", "rust_proto_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
licenses(["notice"])
@@ -25,14 +27,17 @@ proto_library(
srcs = [
"connections_log.proto",
],
compatible_with = ["//buildenv/target:non_prod"],
deps = [
"//proto:connections_enums_proto",
"//proto/errorcode:error_code_enums_proto",
"//storage/datapol/annotations/proto:datapol_annotations",
],
)
cc_proto_library(
name = "connections_log_cc_proto",
compatible_with = ["//buildenv/target:non_prod"],
visibility = [
"//connections:__subpackages__",
"//internal/analytics:__pkg__",
@@ -52,9 +57,20 @@ cc_test(
":connections_log_cc_proto",
"//internal/platform:logging",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//logs/proto/location/nearby:nearby_client_log_cc_proto",
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf",
],
)
rust_proto_library(
name = "connections_log_rust_proto",
deps = [":connections_log_proto"],
)
java_lite_proto_library(
name = "connections_log_java_proto_lite",
deps = [":connections_log_proto"],
)
+5 -5
View File
@@ -390,7 +390,6 @@ cc_library(
"//connections:core_types",
"//connections/implementation:internal",
"//connections/implementation/analytics:analytics_recorder_impl",
"//internal/analytics:event_logger",
"//internal/base",
"//internal/base:file_path",
"//internal/flags:nearby_flags",
@@ -401,6 +400,7 @@ cc_library(
"//internal/platform:mac_address",
"//internal/platform:types",
"//internal/platform/implementation:types",
"//location/nearby/analytics/cpp/logging:event_logger",
"//location/nearby/sharing/lib/account:account_manager",
"//location/nearby/sharing/lib/rpc:grpc_async_client_factory",
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
@@ -653,12 +653,12 @@ cc_test(
":transfer_metadata",
":transfer_metadata_matchers",
":types",
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/base:files",
"//internal/flags:nearby_flags",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//location/nearby/analytics/cpp/logging:mock_event_logger",
"//location/nearby/sharing/lib/account:fake_account_manager",
"//location/nearby/sharing/lib/account:mock_account_manager",
"//location/nearby/sharing/lib/account:signin_attempt",
@@ -873,9 +873,9 @@ cc_test(
":transfer_metadata",
":transfer_metadata_matchers",
":types",
"//internal/analytics:mock_event_logger",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//location/nearby/analytics/cpp/logging:mock_event_logger",
"//location/nearby/sharing/lib/analytics",
"//sharing/certificates:test_support",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -924,12 +924,12 @@ cc_test(
":transfer_metadata",
":transfer_metadata_matchers",
":types",
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/base:files",
"//internal/network:url",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//location/nearby/analytics/cpp/logging:mock_event_logger",
"//location/nearby/sharing/lib/analytics",
"//net/proto2/contrib/parse_proto:parse_text_proto",
"//sharing/certificates:test_support",
@@ -957,10 +957,10 @@ cc_test(
":transfer_metadata",
":transfer_metadata_matchers",
":types",
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//location/nearby/analytics/cpp/logging:mock_event_logger",
"//location/nearby/sharing/lib/analytics",
"//proto:sharing_enums_cc_proto",
"//sharing/internal/public:logging",
+2 -2
View File
@@ -24,14 +24,14 @@
#include <utility>
#include <vector>
#include "location/nearby/analytics/cpp/logging/mock_event_logger.h"
#include "location/nearby/analytics/cpp/logging/sharing_log_matchers.h"
#include "location/nearby/sharing/lib/analytics/analytics_recorder_impl.h"
#include "gmock/gmock.h"
#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 "internal/analytics/sharing_log_matchers.h"
#include "internal/base/file_path.h"
#include "internal/test/fake_clock.h"
#include "internal/test/fake_device_info.h"
@@ -16,7 +16,7 @@
#include <memory>
#include "internal/analytics/event_logger.h"
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "internal/platform/implementation/device_info.h"
#include "internal/platform/task_runner.h"
#include "sharing/internal/public/context.h"
+1 -1
View File
@@ -17,7 +17,7 @@
#include <memory>
#include "internal/analytics/event_logger.h"
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "internal/platform/implementation/device_info.h"
#include "internal/platform/task_runner.h"
#include "sharing/internal/public/context.h"
+1 -1
View File
@@ -23,6 +23,7 @@
#include <utility>
#include <vector>
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
@@ -40,7 +41,6 @@
#include "connections/payload_type.h"
#include "connections/status.h"
#include "connections/strategy.h"
#include "internal/analytics/event_logger.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/logging.h"
#include "internal/platform/mac_address.h"
+1 -1
View File
@@ -22,10 +22,10 @@
#include <string>
#include <vector>
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "internal/analytics/event_logger.h"
#include "sharing/internal/public/connectivity_manager.h"
#include "sharing/nearby_connections_service.h"
#include "sharing/nearby_connections_types.h"
+1 -1
View File
@@ -17,8 +17,8 @@
#include <memory>
#include <utility>
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "location/nearby/sharing/lib/rpc/grpc_async_client_factory.h"
#include "internal/analytics/event_logger.h"
#include "internal/platform/task_runner.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/internal/api/sharing_platform.h"
+1 -1
View File
@@ -17,9 +17,9 @@
#include <memory>
#include "location/nearby/analytics/cpp/logging/event_logger.h"
#include "location/nearby/sharing/lib/rpc/grpc_async_client_factory.h"
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "internal/analytics/event_logger.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/public/context.h"
+1 -1
View File
@@ -30,6 +30,7 @@
#include <utility>
#include <vector>
#include "location/nearby/analytics/cpp/logging/mock_event_logger.h"
#include "location/nearby/sharing/lib/account/fake_account_manager.h"
#include "location/nearby/sharing/lib/account/mock_account_observer.h"
#include "location/nearby/sharing/lib/account/signin_attempt.h"
@@ -48,7 +49,6 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/base/file_path.h"
#include "internal/base/files.h"
#include "internal/flags/nearby_flags.h"
+2 -2
View File
@@ -22,6 +22,8 @@
#include <utility>
#include <vector>
#include "location/nearby/analytics/cpp/logging/mock_event_logger.h"
#include "location/nearby/analytics/cpp/logging/sharing_log_matchers.h"
#include "location/nearby/sharing/lib/analytics/analytics_recorder_impl.h"
#include "net/proto2/contrib/parse_proto/parse_text_proto.h"
#include "gmock/gmock.h"
@@ -29,8 +31,6 @@
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/analytics/sharing_log_matchers.h"
#include "internal/base/file_path.h"
#include "internal/base/files.h"
#include "internal/network/url.h"
+1 -1
View File
@@ -21,6 +21,7 @@
#include <utility>
#include <vector>
#include "location/nearby/analytics/cpp/logging/mock_event_logger.h"
#include "location/nearby/sharing/lib/analytics/analytics_recorder_impl.h"
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
@@ -29,7 +30,6 @@
#include "absl/synchronization/notification.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/test/fake_clock.h"
#include "internal/test/fake_device_info.h"
#include "internal/test/fake_task_runner.h"