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
7 changes: 3 additions & 4 deletions aether/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ list(APPEND aether_srcs
"work_cloud.cpp"
"server.cpp"
"server_keys.cpp"
"socket_initializer.cpp")
"socket_initializer.cpp"
"tele_statistics.cpp")

list(APPEND aether_srcs
"aether_c/c_uid.cpp"
Expand Down Expand Up @@ -231,9 +232,7 @@ list(APPEND aether_srcs
"channels/modem_channel.cpp")

list(APPEND aether_srcs
"tele/tele_init.cpp"
"tele/traps/io_stream_traps.cpp"
"tele/traps/statistics_trap.cpp"
"tele/traps/tele_statistics.cpp")
"tele/traps/statistics_trap.cpp")

target_sources(${TARGET_NAME} PRIVATE ${aether_srcs})
6 changes: 3 additions & 3 deletions aether/access_points/modem_access_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#if AE_SUPPORT_MODEMS

# include "aether/aether.h"
# include "aether/server.h"
# include "aether/modems/imodem_driver.h"
# include "aether/server.h"

# include "aether/channels/modem_channel.h"
# include "aether/access_points/filter_endpoints.h"
# include "aether/channels/modem_channel.h"

# include "aether/tele/tele.h"
# include "aether/tele.h"

namespace ae {
ModemConnectAction::ModemConnectAction(AeContext const& ae_context,
Expand Down
15 changes: 8 additions & 7 deletions aether/access_points/wifi_access_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
#if AE_SUPPORT_WIFIS
# include <utility>

# include "aether/aether.h"
# include "aether/server.h"
# include "aether/poller/poller.h"
# include "aether/dns/dns_resolve.h"
# include "aether/access_points/filter_endpoints.h"
# include "aether/adapters/wifi_adapter.h"
# include "aether/aether.h"
# include "aether/channels/wifi_channel.h"
# include "aether/access_points/filter_endpoints.h"
# include "aether/dns/dns_resolve.h"
# include "aether/poller/poller.h"
# include "aether/server.h"

# include "aether/tele/tele.h"
# include "aether/tele.h"

namespace ae {

Expand All @@ -53,7 +53,8 @@ WifiConnectAction::connection_event() {

void WifiConnectAction::EnsureConnected() {
auto connected_to = driver_->connected_to();
AE_TELED_DEBUG("Driver connected to {}", connected_to.value_or("NOT CONNECTED"));
AE_TELED_DEBUG("Driver connected to {}",
connected_to.value_or("NOT CONNECTED"));
// if already connected
if (connected_to && (*connected_to == wifi_ap_.creds.ssid)) {
SetConnected(true);
Expand Down
2 changes: 1 addition & 1 deletion aether/adapters/adapter_tele.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef AETHER_ADAPTERS_ADAPTER_TELE_H_
#define AETHER_ADAPTERS_ADAPTER_TELE_H_

#include "aether/tele/tele.h"
#include "aether/tele.h"

AE_TELE_MODULE(kAdapter, 5, 101, 121);
AE_TAG(kEthernetAdapterCreate, kAdapter)
Expand Down
6 changes: 3 additions & 3 deletions aether/adapters/wifi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

#if AE_SUPPORT_WIFIS

# include <utility>
# include <cassert>
# include <utility>

# include "aether/aether.h"
# include "aether/poller/poller.h"
# include "aether/dns/dns_resolve.h"
# include "aether/poller/poller.h"
# include "aether/wifi/wifi_driver_factory.h"

# include "aether/tele/tele.h"
# include "aether/tele.h"

namespace ae {
# if defined AE_DISTILLATION
Expand Down
2 changes: 1 addition & 1 deletion aether/ae_actions/ae_actions_tele.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef AETHER_AE_ACTIONS_AE_ACTIONS_TELE_H_
#define AETHER_AE_ACTIONS_AE_ACTIONS_TELE_H_

#include "aether/tele/tele.h"
#include "aether/tele.h"

#if AE_SUPPORT_REGISTRATION
AE_TELE_MODULE(kRegister, 1000, 1000, 1050);
Expand Down
15 changes: 6 additions & 9 deletions aether/ae_actions/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

#if defined TELEMETRY_ENABLED

# include "aether/aether.h"
# include "aether-miscpp/format/format.h"
# include "aether/tele/tele.h"
# include "aether/tele/traps/tele_statistics.h"
# include "aether/aether.h"
# include "aether/tele_statistics.h"

# include "aether/mstream.h"
# include "aether/mstream_buffers.h"
Expand Down Expand Up @@ -79,11 +78,9 @@ void Telemetry::OnRequestTelemetry(std::size_t server_priority) {

std::optional<Telemetric> Telemetry::CollectTelemetry(
StreamInfo const& stream_info) {
auto& statistics_storage =
tele::TeleStatistics::ptr{ae_context_.aether().tele_statistics}
->trap()
->statistics_store;
auto& env_storage = statistics_storage.env_store();
auto const& statistics_trap =
TeleStatistics::ptr{ae_context_.aether().tele_statistics}->trap();
auto const& env_storage = statistics_trap->env_store();
Telemetric res{};
res.cpp.utm_id = env_storage.utm_id;
res.cpp.lib_version = env_storage.library_version;
Expand All @@ -99,7 +96,7 @@ std::optional<Telemetric> Telemetry::CollectTelemetry(
auto vector_writer =
LimitVectorWriter<>{res.cpp.blob, res.cpp.blob.capacity()};
auto os = omstream{vector_writer};
os << statistics_storage;
os << *statistics_trap;
// TODO: should we reset stored statistics?

return res;
Expand Down
6 changes: 3 additions & 3 deletions aether/ae_actions/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
#define AETHER_AE_ACTIONS_TELEMETRY_H_

#include "aether/config.h"
#if AE_TELE_ENABLED
#if AE_TELE_ENABLED && AE_TELE_LOG_TO_STATISTICS
# define TELEMETRY_ENABLED 1

# include <optional>

# include "aether/ae_context.h"
# include "aether/stream_api/istream.h"
# include "aether/cloud_connections/cloud_subscription.h"
# include "aether/cloud_connections/cloud_server_connections.h"
# include "aether/cloud_connections/cloud_subscription.h"
# include "aether/stream_api/istream.h"

# include "aether/work_cloud_api/telemetric.h"

Expand Down
11 changes: 4 additions & 7 deletions aether/aether.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "aether/obj/obj.h"
#include "aether/types/client_config.h"

#include "aether/ae_context.h"
#include "aether/ae_actions/select_client.h"
#include "aether/ae_context.h"

namespace ae {
class Server;
Expand All @@ -39,10 +39,7 @@ class AdapterRegistry;
class ActionProcessor;
class RegistrationCloud;
class RegistrationCloud;

namespace tele {
class TeleStatistics;
}

class Aether : public Obj {
AE_OBJECT(Aether, Obj, 0)
Expand All @@ -56,9 +53,9 @@ class Aether : public Obj {
~Aether() override;

AE_OBJECT_REFLECT(AE_MMBRS(client_prefab, registration_cloud, crypto,
clients_, servers_, tele_statistics, poller,
dns_resolver, adapter_registry,
select_client_actions_))
clients_, servers_, tele_statistics, poller,
dns_resolver, adapter_registry,
select_client_actions_))

template <typename Dnv>
void Load(CurrentVersion, Dnv& dnv) {
Expand Down
67 changes: 46 additions & 21 deletions aether/aether_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#include "aether/aether_app.h"

#include <cstdlib>
#include <iostream>

// IWYU pragma: begin_keeps
#include "aether/types/address_parser.h"
#include "aether/types/literal_array.h"
Expand All @@ -33,27 +36,52 @@

#include "aether/dns/dns_c_ares.h"
#include "aether/dns/esp32_dns_resolve.h"
// IWYU pragma: end_keeps

#include "aether/tele/tele_init.h"

#include "aether/aether_tele.h"
#include "aether/tele.h"
#include "aether/tele_compile_options.h"
// IWYU pragma: end_keeps

namespace ae {

AetherAppContext::TelemetryInit::TelemetryInit() {
tele::TeleInit::Init();
AE_TELE_ENV();
void AetherAppContext::TelemetryInit() {
#if AE_TELE_ENABLED
// Init telemetry sink
if (!TELE_SINK::Instance().trap()) {
# if AE_TELE_LOG_CONSOLE && AE_TELE_LOG_TO_STATISTICS
// telemetry to both console and statistics
auto trap = std::make_shared<
ae::tele::ProxyTrap<ae::tele::IoStreamTrap,
ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>>>(
std::make_shared<ae::tele::IoStreamTrap>(std::cout),
std::make_shared<ae::tele::StatisticsTrap<AE_STATISTICS_MAX_SIZE>>());
# 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>>();
# 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();
}

void AetherAppContext::TelemetryInit::operator()(
AetherAppContext const& context) const {
[[maybe_unused]] auto res =
context.tele_statistics_.Resolve(context).WithLoaded(
[](auto const& ts) { ae::tele::TeleInit::Init(ts); });
assert(res && "Failed to initialize telemetry");
#endif
}

static Aether::ptr AetherFactory(AetherAppContext const& context) {
Expand All @@ -80,15 +108,14 @@ static Aether::ptr AetherFactory(AetherAppContext const& context) {
#endif
}

static tele::TeleStatistics::ptr TeleStatisticsFactory(
static TeleStatistics::ptr TeleStatisticsFactory(
AetherAppContext const& context) {
auto tele_statistics =
tele::TeleStatistics::ptr{context.aether()->tele_statistics};
auto tele_statistics = TeleStatistics::ptr{context.aether()->tele_statistics};
if (tele_statistics.is_valid()) {
return tele_statistics;
}
#if AE_DISTILLATION || AE_FILTRATION
return tele::TeleStatistics::ptr::Create(
return TeleStatistics::ptr::Create(
CreateWith{context.domain()}.with_id(GlobalId::kTeleStatistics));
#else
assert(false && "Failed to load TeleStatistics");
Expand Down Expand Up @@ -300,8 +327,6 @@ RcPtr<AetherApp> AetherApp::Construct(AetherAppContext context) {
// init all the components in context
context.InitComponentContext();

context.init_tele_(context);

auto app = MakeRcPtr<AetherApp>();
app->aether_ = context.aether();
#if AE_DISTILLATION
Expand Down
44 changes: 17 additions & 27 deletions aether/aether_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,41 @@
#include <optional>
#include <type_traits>

#include "aether/config.h"
#include "aether/common.h"
#include "aether/config.h"
#include "aether/obj/domain.h"
#include "aether/ptr/ptr.h"
#include "aether/ptr/rc_ptr.h"
#include "aether/obj/domain.h"
#include "aether-miscpp/types/small_function.h"

#include "aether/events/events.h" // IWYU pragma: keep
#include "aether/actions/action.h" // IWYU pragma: keep
#include "aether/events/events.h" // IWYU pragma: keep

#include "aether/cloud.h"
#include "aether/adapter_registry.h"
#include "aether/ae_context.h"
#include "aether/aether.h"
#include "aether/crypto.h"
#include "aether/client.h"
#include "aether/ae_context.h"
#include "aether/poller/poller.h"
#include "aether/cloud.h"
#include "aether/crypto.h"
#include "aether/dns/dns_resolve.h"
#include "aether/adapter_registry.h"
#include "aether/obj/component_factory.h"
#include "aether/tele/traps/tele_statistics.h"
#include "aether/poller/poller.h"
#include "aether/tele_statistics.h"

#include "aether/domain_storage/domain_storage_factory.h"

namespace ae {
class AetherAppContext {
friend class AetherApp;
class TelemetryInit {
public:
TelemetryInit();
void operator()(AetherAppContext const& context) const;
};
static void TelemetryInit();

public:
explicit AetherAppContext()
: AetherAppContext(DomainStorageFactory::Create, TelemetryInit{}) {}

template <typename Func, typename TeleInit = TelemetryInit>
requires(std::is_invocable_r_v<std::unique_ptr<IDomainStorage>, Func> &&
std::is_invocable_r_v<void, TeleInit, AetherAppContext const&>)
explicit AetherAppContext(Func&& domain_storage_factory,
TeleInit const& tele_init = TelemetryInit{})
: init_tele_{tele_init} {
: AetherAppContext(DomainStorageFactory::Create) {}

template <typename Func>
requires(std::is_invocable_r_v<std::unique_ptr<IDomainStorage>, Func>)
explicit AetherAppContext(Func&& domain_storage_factory) {
TelemetryInit();
domain_storage_.Factory(std::forward<Func>(domain_storage_factory));
}

Expand Down Expand Up @@ -145,10 +138,7 @@ class AetherAppContext {
ComponentFactory<AetherAppContext, IPoller::ptr> poller_;
ComponentFactory<AetherAppContext, DnsResolver::ptr> dns_resolver_;
ComponentFactory<AetherAppContext, Client::ptr> client_prefab_;
ComponentFactory<AetherAppContext, tele::TeleStatistics::ptr>
tele_statistics_;

SmallFunction<void(AetherAppContext const&)> init_tele_;
ComponentFactory<AetherAppContext, TeleStatistics::ptr> tele_statistics_;
};

/**
Expand Down
Loading
Loading