Skip to content
Merged
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
54 changes: 39 additions & 15 deletions aether/aether_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,62 @@ void AetherAppContext::TelemetryInit() {
if (!TELE_SINK::Instance().trap()) {
# if AE_TELE_LOG_CONSOLE && AE_TELE_LOG_TO_STATISTICS
// telemetry to both console and statistics
tele_statistics_trap_is_set = true;
auto trap = std::make_shared<
ae::tele::ProxyTrap<ae::tele::IoStreamTrap,
ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>>>(
ae::tele::ProxyTrap<ae::tele::IoStreamTrap, ae::TeleStatisticsTrap>>(
std::make_shared<ae::tele::IoStreamTrap>(std::cout),
std::make_shared<ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>>());
std::make_shared<ae::TeleStatisticsTrap>());

# elif AE_TELE_LOG_CONSOLE
// telemetry to console only
auto trap = std::make_shared<ae::tele::IoStreamTrap>(std::cout);
# elif AE_TELE_LOG_TO_STATISTICS
// telemetry to statistics only
auto trap =
std::make_shared<ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>>();
tele_statistics_trap_is_set = true;
auto trap = std::make_shared<ae::TeleStatisticsTrap>();
# else
// NONE trap is enabled
return;
# endif
TELE_SINK::Instance().SetTrap(trap);
}
# if AE_TELE_LOG_TO_STATISTICS
else {
// TODO: is it possible to fix?
// IF AE_TELE_LOG_TO_STATISTICS is defined user are not allowed to set
// custom trap, because it's static_casts in TeleStatistics object
std::cerr
<< "Custom trap are not allowed with AE_TELE_LOG_TO_STATISTICS==1\n";
std::abort();
}
# endif

AE_TELE_ENV(CompileOptions());
AE_TELE_INFO(AetherStarted);
Registry::GetRegistry().Log();
#endif
}

void AetherAppContext::TeleStatisticsInit(
TeleStatistics::ptr const& tele_statistics) const {
#if AE_TELE_ENABLED
# if AE_TELE_LOG_TO_STATISTICS
if (!tele_statistics_trap_is_set) {
return;
}

auto& sink = TELE_SINK::Instance();
auto trap = sink.trap();
// !NOTICE it's error if AE_TELE_LOG_TO_STATISTICS is defined to 1 but actual
// trap is set to something different
# if AE_TELE_LOG_CONSOLE && AE_TELE_LOG_TO_STATISTICS
// if proxy trap is used
auto proxy = std::static_pointer_cast<
ae::tele::ProxyTrap<ae::tele::IoStreamTrap, ae::TeleStatisticsTrap>>(
trap);
auto const& current_statistics = proxy->second;
tele_statistics->trap()->MergeStatistics(*current_statistics);
proxy->second = tele_statistics->trap();
# elif AE_TELE_LOG_TO_STATISTICS
auto current_statistics =
std::static_pointer_cast<ae::TeleStatisticsTrap>(trap);
tele_statistics->trap()->MergeStatistics(*current_statistics);
sink.SetTrap(tele_statistics->trap());
# endif
# endif
#endif
}

static Aether::ptr AetherFactory(AetherAppContext const& context) {
/**
* If it's production or filtration mode, declare and load Aether.
Expand Down Expand Up @@ -349,6 +370,9 @@ std::unique_ptr<AetherApp> AetherApp::Construct(AetherAppContext context) {
app->aether_.Save();
#endif // AE_DISTILLATION

// reinit telemetry with tele_statistics object
context.TeleStatisticsInit(app->aether_->tele_statistics);

// save domain from context to the app
app->domain_facility_ =
std::move(std::move(context).domain_storage_.Resolve());
Expand Down
8 changes: 7 additions & 1 deletion aether/aether_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
#include "aether/domain_storage/domain_storage_factory.h"

namespace ae {
using TeleStatisticsTrap = ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>;

class AetherAppContext {
friend class AetherApp;
static void TelemetryInit();

public:
explicit AetherAppContext()
Expand Down Expand Up @@ -126,6 +127,9 @@ class AetherAppContext {
#endif // AE_DISTILLATION

private:
void TelemetryInit();
void TeleStatisticsInit(TeleStatistics::ptr const& tele_statistics) const;

void InitComponentContext();

ComponentFactory<std::unique_ptr<IDomainStorage>> domain_storage_;
Expand All @@ -139,6 +143,8 @@ class AetherAppContext {
ComponentFactory<AetherAppContext, DnsResolver::ptr> dns_resolver_;
ComponentFactory<AetherAppContext, Client::ptr> client_prefab_;
ComponentFactory<AetherAppContext, TeleStatistics::ptr> tele_statistics_;

bool tele_statistics_trap_is_set{false};
};

/**
Expand Down
3 changes: 3 additions & 0 deletions aether/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ CloudServerConnections& Client::cloud_connection() {
// also create telemetry
telemetry_ = std::make_unique<Telemetry>(*aether_, *cloud_connection_);
#endif

client_cloud_manager_.WithLoaded(
[&](auto const& ccm) { ccm->StartListenForCloudUpdate(); });
}

return *cloud_connection_;
Expand Down
47 changes: 19 additions & 28 deletions aether/connection_manager/client_cloud_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,14 @@ ClientCloudManager::ClientCloudManager(ObjProp prop, ObjPtr<Aether> aether,
[[maybe_unused]] auto const cache_initialized =
client_.WithLoaded([&](auto const& obj) {
cloud_cache_.emplace(obj->uid(),
client_cloud_manager_internal::CloudCache{
.version_confirmed = true,
.subject_uid = obj->uid(),
.version = 0,
.cloud = obj->cloud(),
});
client_cloud_manager_internal::CloudCache{
.version_confirmed = true,
.subject_uid = obj->uid(),
.version = 0,
.cloud = obj->cloud(),
});
});
assert(cache_initialized && "Client did not load");

// init the rest
Init();
}

ClientCloudManager::CloudUpdateEvent::Subscriber
Expand All @@ -175,10 +172,11 @@ ClientCloudManager::cloud_update_event() {
GetCloudAction& ClientCloudManager::GetCloud(Uid client_uid) {
AE_TELED_DEBUG("Ask cloud for uid: {}", client_uid);

auto aether = Aether::ptr{aether_}.Load();
auto aether = aether_.Load();
assert(aether && "Aether did not loaded");

assert(cloud_actions_ && "Cloud actions did not initiated");
if (!cloud_actions_) {
cloud_actions_.emplace(*aether);
}

auto cached = cloud_cache_.find(client_uid);
if ((cached != cloud_cache_.end()) && cached->second.cloud.is_valid()) {
Expand All @@ -192,7 +190,7 @@ GetCloudAction& ClientCloudManager::GetCloud(Uid client_uid) {
}

// get from aethernet
auto client = Client::ptr{client_}.Load();
auto client = client_.Load();
assert(client);

auto* action = cloud_actions_->Create<GetCloudFromAether>(
Expand All @@ -201,19 +199,13 @@ GetCloudAction& ClientCloudManager::GetCloud(Uid client_uid) {
return *action;
}

void ClientCloudManager::Init() {
auto aether = Aether::ptr{aether_}.Load();
void ClientCloudManager::StartListenForCloudUpdate() {
auto aether = aether_.Load();
assert(aether && "Aether must be loaded");

cloud_actions_.emplace(*aether);
get_servers_pool_.emplace(*aether);

ListenForCloudUpdate();
}

void ClientCloudManager::ListenForCloudUpdate() {
auto client = Client::ptr{client_}.Load();
assert(client != nullptr && "Client does not loaded");
auto client = client_.Load();
assert(client && "Client does not loaded");

cloud_update_sub_ = CloudEventListener{
ApiEventSubscriber{[this](ClientApiSafe& client_api,
Expand All @@ -227,12 +219,11 @@ void ClientCloudManager::ListenForCloudUpdate() {
auto ClientCloudManager::MakeServersSender(std::vector<ServerId> const& sids) {
using namespace client_cloud_manager_internal; // NOLINT(*using-namespace)

auto aether = Aether::ptr{aether_};
auto client = Client::ptr{client_};
assert(get_servers_pool_.has_value() && "Get servers pool did not initiated");

return SplitMissingLoaded(aether, sids) |
LoadMissing(aether, client, *get_servers_pool_) | SortNewServers(sids);
return SplitMissingLoaded(aether_, sids) |
LoadMissing(aether_, client_, *get_servers_pool_) |
SortNewServers(sids);
}

void ClientCloudManager::CloudConfigs(std::vector<CloudConfig> const& configs) {
Expand Down Expand Up @@ -275,7 +266,7 @@ void ClientCloudManager::CloudConfigs(std::vector<CloudConfig> const& configs) {
}

void ClientCloudManager::FinalizeCloudConfig(CloudConfig const& conf) {
auto aether = Aether::ptr{aether_}.Load();
auto aether = aether_.Load();

AE_TELED_DEBUG("Finalize servers for new cloud config [{}]", conf.cloud.sids);
// make async waiter for building the new cloud
Expand Down
9 changes: 2 additions & 7 deletions aether/connection_manager/client_cloud_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@ class ClientCloudManager : public Obj {
GetCloudAction& GetCloud(Uid client_uid);

AE_OBJECT_REFLECT(AE_MMBRS(aether_, client_, cloud_cache_))
template <typename Dnv>
void Load(CurrentVersion, Dnv& dnv) {
dnv(base_, aether_, client_, cloud_cache_);
Init();
}

void StartListenForCloudUpdate();

private:
void Init();
void ListenForCloudUpdate();
void CloudConfigs(std::vector<CloudConfig> const& configs);
void FinalizeCloudConfig(CloudConfig const& conf);
auto MakeServersSender(std::vector<ServerId> const& sids);
Expand Down
Loading
Loading