Просмотр исходного кода

Restoring authorship annotation for <radix@yandex-team.ru>. Commit 2 of 2.

radix 3 лет назад
Родитель
Сommit
bfd0aa05ca

+ 2 - 2
library/cpp/http/misc/parsed_request.cpp

@@ -16,11 +16,11 @@ static inline TStringBuf StripLeft(const TStringBuf& s) noexcept {
 TParsedHttpRequest::TParsedHttpRequest(const TStringBuf& str) {
     TStringBuf tmp;
 
-    if (!StripLeft(str).TrySplit(' ', Method, tmp)) { 
+    if (!StripLeft(str).TrySplit(' ', Method, tmp)) {
         ythrow yexception() << "bad request(" << ToString(str).Quote() << ")";
     }
 
-    if (!StripLeft(tmp).TrySplit(' ', Request, Proto)) { 
+    if (!StripLeft(tmp).TrySplit(' ', Request, Proto)) {
         ythrow yexception() << "bad request(" << ToString(str).Quote() << ")";
     }
 

+ 1 - 1
util/folder/pathsplit.cpp

@@ -36,7 +36,7 @@ void TPathSplitTraitsUnix::DoParsePart(const TStringBuf part0) {
     TStringBuf next(part0);
     TStringBuf part;
 
-    while (TStringBuf(next).TrySplit('/', part, next)) { 
+    while (TStringBuf(next).TrySplit('/', part, next)) {
         AppendComponent(part);
     }
 

+ 47 - 47
util/generic/strbuf.h

@@ -171,63 +171,63 @@ public:
         return data() != nullptr;
     }
 
-public: 
-    /** 
-     * Tries to split string in two parts using given delimiter character. 
-     * Searches for the delimiter, scanning string from the beginning. 
-     * The delimiter is excluded from the result. Both out parameters are 
-     * left unmodified if there was no delimiter character in string. 
-     * 
-     * @param[in] delim                 Delimiter character. 
-     * @param[out] l                    The first part of split result. 
-     * @param[out] r                    The second part of split result. 
-     * @returns                         Whether the split was actually performed. 
-     */ 
+public:
+    /**
+     * Tries to split string in two parts using given delimiter character.
+     * Searches for the delimiter, scanning string from the beginning.
+     * The delimiter is excluded from the result. Both out parameters are
+     * left unmodified if there was no delimiter character in string.
+     *
+     * @param[in] delim                 Delimiter character.
+     * @param[out] l                    The first part of split result.
+     * @param[out] r                    The second part of split result.
+     * @returns                         Whether the split was actually performed.
+     */
     inline bool TrySplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
         return TrySplitOn(TBase::find(delim), l, r);
     }
 
-    /** 
-     * Tries to split string in two parts using given delimiter character. 
-     * Searches for the delimiter, scanning string from the end. 
-     * The delimiter is excluded from the result. Both out parameters are 
-     * left unmodified if there was no delimiter character in string. 
-     * 
-     * @param[in] delim                 Delimiter character. 
-     * @param[out] l                    The first part of split result. 
-     * @param[out] r                    The second part of split result. 
-     * @returns                         Whether the split was actually performed. 
-     */ 
+    /**
+     * Tries to split string in two parts using given delimiter character.
+     * Searches for the delimiter, scanning string from the end.
+     * The delimiter is excluded from the result. Both out parameters are
+     * left unmodified if there was no delimiter character in string.
+     *
+     * @param[in] delim                 Delimiter character.
+     * @param[out] l                    The first part of split result.
+     * @param[out] r                    The second part of split result.
+     * @returns                         Whether the split was actually performed.
+     */
     inline bool TryRSplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
         return TrySplitOn(TBase::rfind(delim), l, r);
     }
 
-    /** 
-     * Tries to split string in two parts using given delimiter sequence. 
-     * Searches for the delimiter, scanning string from the beginning. 
-     * The delimiter sequence is excluded from the result. Both out parameters 
-     * are left unmodified if there was no delimiter character in string. 
-     * 
-     * @param[in] delim                 Delimiter sequence. 
-     * @param[out] l                    The first part of split result. 
-     * @param[out] r                    The second part of split result. 
-     * @returns                         Whether the split was actually performed. 
-     */ 
+    /**
+     * Tries to split string in two parts using given delimiter sequence.
+     * Searches for the delimiter, scanning string from the beginning.
+     * The delimiter sequence is excluded from the result. Both out parameters
+     * are left unmodified if there was no delimiter character in string.
+     *
+     * @param[in] delim                 Delimiter sequence.
+     * @param[out] l                    The first part of split result.
+     * @param[out] r                    The second part of split result.
+     * @returns                         Whether the split was actually performed.
+     */
     inline bool TrySplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept {
         return TrySplitOn(TBase::find(delim), l, r, delim.size());
     }
 
-    /** 
-     * Tries to split string in two parts using given delimiter sequence. 
-     * Searches for the delimiter, scanning string from the end. 
-     * The delimiter sequence is excluded from the result. Both out parameters 
-     * are left unmodified if there was no delimiter character in string. 
-     * 
-     * @param[in] delim                 Delimiter sequence. 
-     * @param[out] l                    The first part of split result. 
-     * @param[out] r                    The second part of split result. 
-     * @returns                         Whether the split was actually performed. 
-     */ 
+    /**
+     * Tries to split string in two parts using given delimiter sequence.
+     * Searches for the delimiter, scanning string from the end.
+     * The delimiter sequence is excluded from the result. Both out parameters
+     * are left unmodified if there was no delimiter character in string.
+     *
+     * @param[in] delim                 Delimiter sequence.
+     * @param[out] l                    The first part of split result.
+     * @param[out] r                    The second part of split result.
+     * @returns                         Whether the split was actually performed.
+     */
     inline bool TryRSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept {
         return TrySplitOn(TBase::rfind(delim), l, r, delim.size());
     }
@@ -521,7 +521,7 @@ private:
 
     template <typename TDelimiterType>
     inline void SplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept {
-        if (!TrySplit(delim, l, r)) { 
+        if (!TrySplit(delim, l, r)) {
             l = *this;
             r = TdSelf();
         }
@@ -529,7 +529,7 @@ private:
 
     template <typename TDelimiterType>
     inline void RSplitTemplate(TDelimiterType delim, TdSelf& l, TdSelf& r) const noexcept {
-        if (!TryRSplit(delim, l, r)) { 
+        if (!TryRSplit(delim, l, r)) {
             r = *this;
             l = TdSelf();
         }

+ 5 - 5
ydb/core/base/appdata.h

@@ -131,13 +131,13 @@ struct TAppData {
 
     THolder<NKikimrBlobStorage::TNodeWardenServiceSet> StaticBlobStorageConfig;
     THolder<NKikimrCms::TCmsConfig> DefaultCmsConfig;
- 
+
     NKikimrStream::TStreamingConfig StreamingConfig;
     NKikimrPQ::TPQConfig PQConfig;
-    NKikimrPQ::TPQClusterDiscoveryConfig PQClusterDiscoveryConfig; 
-    NKikimrNetClassifier::TNetClassifierConfig NetClassifierConfig; 
-    NKikimrNetClassifier::TNetClassifierDistributableConfig NetClassifierDistributableConfig; 
-    NKikimrConfig::TSqsConfig SqsConfig; 
+    NKikimrPQ::TPQClusterDiscoveryConfig PQClusterDiscoveryConfig;
+    NKikimrNetClassifier::TNetClassifierConfig NetClassifierConfig;
+    NKikimrNetClassifier::TNetClassifierDistributableConfig NetClassifierDistributableConfig;
+    NKikimrConfig::TSqsConfig SqsConfig;
     NKikimrProto::TAuthConfig AuthConfig;
     NKikimrProto::TKeyConfig KeyConfig;
     NKikimrProto::TKeyConfig PDiskKeyConfig;

+ 2 - 2
ydb/core/base/events.h

@@ -109,8 +109,8 @@ struct TKikimrEvents : TEvents {
         ES_GRPC_REQUEST_PROXY,
         ES_EXPORT_SERVICE,
         ES_TX_ALLOCATOR_CLIENT,
-        ES_PQ_CLUSTER_TRACKER, 
-        ES_NET_CLASSIFIER, 
+        ES_PQ_CLUSTER_TRACKER,
+        ES_NET_CLASSIFIER,
         ES_SYSTEM_VIEW,
         ES_TENANT_NODE_ENUMERATOR,
         ES_SERVICE_ACCOUNT_SERVICE,

+ 15 - 15
ydb/core/cms/console/console.cpp

@@ -3,8 +3,8 @@
 #include "console_tenants_manager.h"
 #include "http.h"
 
-#include "net_classifier_updater.h" 
- 
+#include "net_classifier_updater.h"
+
 #include <ydb/core/base/counters.h>
 #include <ydb/core/cms/console/validators/registry.h>
 
@@ -33,10 +33,10 @@ void TConsole::OnActivateExecutor(const TActorContext &ctx)
                                          AppData()->FeatureFlags);
     ctx.RegisterWithSameMailbox(TenantsManager);
 
-    if (AppData(ctx)->NetClassifierConfig.GetUpdaterConfig().GetNetDataSourceUrl()) { 
-        NetClassifierUpdaterId = ctx.Register(NNetClassifierUpdater::MakeNetClassifierUpdaterActor(SelfId())); 
-    } 
- 
+    if (AppData(ctx)->NetClassifierConfig.GetUpdaterConfig().GetNetDataSourceUrl()) {
+        NetClassifierUpdaterId = ctx.Register(NNetClassifierUpdater::MakeNetClassifierUpdaterActor(SelfId()));
+    }
+
     TxProcessor->ProcessTx(CreateTxInitScheme(), ctx);
 }
 
@@ -109,11 +109,11 @@ void TConsole::Cleanup(const TActorContext &ctx)
         TenantsManager = nullptr;
     }
 
-    if (NetClassifierUpdaterId) { 
-        Send(NetClassifierUpdaterId, new TEvents::TEvPoisonPill); 
-        NetClassifierUpdaterId = {}; 
-    } 
- 
+    if (NetClassifierUpdaterId) {
+        Send(NetClassifierUpdaterId, new TEvents::TEvPoisonPill);
+        NetClassifierUpdaterId = {};
+    }
+
     TxProcessor->Clear();
 }
 
@@ -145,12 +145,12 @@ void TConsole::ProcessEnqueuedEvents(const TActorContext &ctx)
 void TConsole::ClearState()
 {
     Config.Clear();
-    if (ConfigsManager) { 
+    if (ConfigsManager) {
         ConfigsManager->ClearState();
-    } 
-    if (TenantsManager) { 
+    }
+    if (TenantsManager) {
         TenantsManager->ClearState();
-    } 
+    }
 
     Counters->ResetCounters();
 }

+ 3 - 3
ydb/core/cms/console/console_impl.h

@@ -162,9 +162,9 @@ private:
     TTxProcessor::TPtr TxProcessor;
     TDynamicCounterPtr Counters;
 
-    TConfigsManager* ConfigsManager; 
-    TTenantsManager* TenantsManager; 
- 
+    TConfigsManager* ConfigsManager;
+    TTenantsManager* TenantsManager;
+
     TActorId NetClassifierUpdaterId;
 };
 

+ 256 - 256
ydb/core/cms/console/net_classifier_updater.cpp

@@ -1,15 +1,15 @@
-#include "net_classifier_updater.h" 
- 
+#include "net_classifier_updater.h"
+
 #include <ydb/core/base/appdata.h>
 #include <ydb/core/base/tablet_pipe.h>
- 
+
 #include <library/cpp/actors/core/hfunc.h>
 #include <library/cpp/actors/http/http_proxy.h>
 #include <library/cpp/actors/interconnect/interconnect.h>
 #include <library/cpp/json/json_reader.h>
- 
-#include <util/stream/zlib.h> 
- 
+
+#include <util/stream/zlib.h>
+
 #if defined BLOG_D || defined BLOG_I || defined BLOG_ERROR || defined BLOG_NOTICE
 #error log macro definition clash
 #endif
@@ -20,159 +20,159 @@
 #define BLOG_ERROR(stream) LOG_ERROR_S(*TlsActivationContext, NKikimrServices::CMS_CONFIGS, stream)
 
 
-namespace NKikimr::NNetClassifierUpdater { 
- 
-using namespace NConsole; 
- 
-// helps to find a particular config item. DO NOT CHANGE this constant 
-static const TString COOKIE = "NetClassifierPackedNetDataFromExternalSource"; 
- 
-// prevents duplicates in config list. DO NOT CHANGE this constant 
-static constexpr ui32 CONFIG_ORDER = 10; 
- 
-static TString PackNetData(const TString& netData, size_t level = 6) { 
-    TString result; 
-    result.reserve(std::size(netData)); 
-    TStringOutput stream(result); 
-    TZLibCompress(&stream, ZLib::GZip, level).Write(netData); 
-    return result; 
-} 
- 
-/* 
-    ***NetClassifier Updater algorithm*** 
- 
-    The main idea is to keep only one special config item to periodically modify it. 
-    All discovery nodes are subscribed to config dispatcher to get updates. 
- 
-    Initing stage (requires WakeUp event to start): 
-        1) Look for the config item via cookie 
-            if has distributable config item: 
-                GOTO Working stage 
-            else: 
-                Add distributable empty config item with cookie and order 
-                GOTO Working stage if added successfully 
-    Working stage (also requires WakeUp event to start): 
-        1) Get Networks Data from an external http(s) resource 
-        2) Find current config id and generation through GetConfigItem 
-        3) Send ModifyEvent using step 2 information. 
-        4) Schedule WakeUp event on success 
- 
-    In case of any error algorithm falls back to Initing stage and schedules WakeUp. 
-*/ 
- 
-class NetClassifierUpdater : public TActorBootstrapped<NetClassifierUpdater> { 
-private: 
-    using TBase = TActorBootstrapped<NetClassifierUpdater>; 
- 
-public: 
+namespace NKikimr::NNetClassifierUpdater {
+
+using namespace NConsole;
+
+// helps to find a particular config item. DO NOT CHANGE this constant
+static const TString COOKIE = "NetClassifierPackedNetDataFromExternalSource";
+
+// prevents duplicates in config list. DO NOT CHANGE this constant
+static constexpr ui32 CONFIG_ORDER = 10;
+
+static TString PackNetData(const TString& netData, size_t level = 6) {
+    TString result;
+    result.reserve(std::size(netData));
+    TStringOutput stream(result);
+    TZLibCompress(&stream, ZLib::GZip, level).Write(netData);
+    return result;
+}
+
+/*
+    ***NetClassifier Updater algorithm***
+
+    The main idea is to keep only one special config item to periodically modify it.
+    All discovery nodes are subscribed to config dispatcher to get updates.
+
+    Initing stage (requires WakeUp event to start):
+        1) Look for the config item via cookie
+            if has distributable config item:
+                GOTO Working stage
+            else:
+                Add distributable empty config item with cookie and order
+                GOTO Working stage if added successfully
+    Working stage (also requires WakeUp event to start):
+        1) Get Networks Data from an external http(s) resource
+        2) Find current config id and generation through GetConfigItem
+        3) Send ModifyEvent using step 2 information.
+        4) Schedule WakeUp event on success
+
+    In case of any error algorithm falls back to Initing stage and schedules WakeUp.
+*/
+
+class NetClassifierUpdater : public TActorBootstrapped<NetClassifierUpdater> {
+private:
+    using TBase = TActorBootstrapped<NetClassifierUpdater>;
+
+public:
     NetClassifierUpdater(TActorId localConsole)
-        : LocalConsole(localConsole) 
-    { 
-    } 
- 
-    static constexpr NKikimrServices::TActivity::EType ActorActivityType() { 
-        return NKikimrServices::TActivity::NET_CLASSIFIER_UPDATER; 
-    } 
- 
+        : LocalConsole(localConsole)
+    {
+    }
+
+    static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
+        return NKikimrServices::TActivity::NET_CLASSIFIER_UPDATER;
+    }
+
     void Bootstrap() {
-        Become(&TThis::Initing); 
+        Become(&TThis::Initing);
         Send(SelfId(), new TEvents::TEvWakeup);
-    } 
- 
-private: 
-    const auto& UpdaterConfig() const { 
+    }
+
+private:
+    const auto& UpdaterConfig() const {
         return AppData()->NetClassifierConfig.GetUpdaterConfig();
-    } 
- 
-    void HandleWhileIniting(TEvents::TEvWakeup::TPtr&) { 
-        // start the config check 
-        RequestCurrentConfigViaCookie(); 
-    } 
- 
-    void RequestCurrentConfigViaCookie() { 
+    }
+
+    void HandleWhileIniting(TEvents::TEvWakeup::TPtr&) {
+        // start the config check
+        RequestCurrentConfigViaCookie();
+    }
+
+    void RequestCurrentConfigViaCookie() {
         BLOG_D("NetClassifierUpdater requested distributable config item via cookie");
- 
-        auto event = MakeHolder<TEvConsole::TEvGetConfigItemsRequest>(); 
- 
-        event->Record.AddItemKinds(static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem)); 
-        event->Record.MutableCookieFilter()->AddCookies(COOKIE); 
- 
-        Send(LocalConsole, event.Release()); 
-    } 
- 
-    void InitDefaultConfiguration() { 
+
+        auto event = MakeHolder<TEvConsole::TEvGetConfigItemsRequest>();
+
+        event->Record.AddItemKinds(static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem));
+        event->Record.MutableCookieFilter()->AddCookies(COOKIE);
+
+        Send(LocalConsole, event.Release());
+    }
+
+    void InitDefaultConfiguration() {
         LOG_INFO_S(*TlsActivationContext, NKikimrServices::CMS_CONFIGS,
-                        "NetClassifierUpdate is adding distributable config item with cookie"); 
- 
-        auto event = MakeHolder<TEvConsole::TEvConfigureRequest>(); 
- 
-        auto& configItem = *event->Record.AddActions()->MutableAddConfigItem()->MutableConfigItem(); 
-        configItem.MutableConfig()->MutableNetClassifierDistributableConfig(); // just initialize the field 
- 
-        configItem.SetKind(static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem)); 
- 
-        configItem.SetOrder(CONFIG_ORDER); // prevents config item duplicates 
-        configItem.SetCookie(COOKIE); 
- 
-        Send(LocalConsole, event.Release()); 
-    } 
- 
-    void HandleWhileIniting(TEvConsole::TEvConfigureResponse::TPtr& ev) { 
-        const auto& record = ev->Get()->Record; 
-        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) { 
+                        "NetClassifierUpdate is adding distributable config item with cookie");
+
+        auto event = MakeHolder<TEvConsole::TEvConfigureRequest>();
+
+        auto& configItem = *event->Record.AddActions()->MutableAddConfigItem()->MutableConfigItem();
+        configItem.MutableConfig()->MutableNetClassifierDistributableConfig(); // just initialize the field
+
+        configItem.SetKind(static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem));
+
+        configItem.SetOrder(CONFIG_ORDER); // prevents config item duplicates
+        configItem.SetCookie(COOKIE);
+
+        Send(LocalConsole, event.Release());
+    }
+
+    void HandleWhileIniting(TEvConsole::TEvConfigureResponse::TPtr& ev) {
+        const auto& record = ev->Get()->Record;
+        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) {
             BLOG_D("NetClassifierUpdater created a new distributable config item");
-            CompleteInitialization(); 
-        } else { 
+            CompleteInitialization();
+        } else {
             BLOG_ERROR("NetClassifierUpdater failed to add config item: " << record.ShortDebugString());
-            InitializeAgain(); 
-        } 
-    } 
- 
-    void HandleWhileIniting(TEvConsole::TEvGetConfigItemsResponse::TPtr& ev) { 
-        const auto& record = ev->Get()->Record; 
-        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) { 
-            if (record.ConfigItemsSize() == 0) { 
-                // cookied config item is missing, add it 
-                InitDefaultConfiguration(); 
-            } else { 
-                Y_VERIFY(record.ConfigItemsSize() == 1); // only one config item should have the cookie 
- 
+            InitializeAgain();
+        }
+    }
+
+    void HandleWhileIniting(TEvConsole::TEvGetConfigItemsResponse::TPtr& ev) {
+        const auto& record = ev->Get()->Record;
+        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) {
+            if (record.ConfigItemsSize() == 0) {
+                // cookied config item is missing, add it
+                InitDefaultConfiguration();
+            } else {
+                Y_VERIFY(record.ConfigItemsSize() == 1); // only one config item should have the cookie
+
                 BLOG_D("NetClassifierUpdater found the distributable config via cookie");
- 
-                CompleteInitialization(); 
-            } 
-        } else { 
+
+                CompleteInitialization();
+            }
+        } else {
             BLOG_ERROR("NetClassifierUpdater failed get current distributable config version: " << record.ShortDebugString());
-            InitializeAgain(); 
-        } 
-    } 
- 
-    STATEFN(Initing) { 
-        switch (ev->GetTypeRewrite()) { 
-            hFunc(TEvConsole::TEvConfigureResponse, HandleWhileIniting); 
-            hFunc(TEvConsole::TEvGetConfigItemsResponse, HandleWhileIniting); 
-            hFunc(TEvents::TEvWakeup, HandleWhileIniting); 
-            hFunc(TEvents::TEvPoisonPill, HandlePoison); 
-        } 
-    } 
- 
-    void CompleteInitialization() { 
+            InitializeAgain();
+        }
+    }
+
+    STATEFN(Initing) {
+        switch (ev->GetTypeRewrite()) {
+            hFunc(TEvConsole::TEvConfigureResponse, HandleWhileIniting);
+            hFunc(TEvConsole::TEvGetConfigItemsResponse, HandleWhileIniting);
+            hFunc(TEvents::TEvWakeup, HandleWhileIniting);
+            hFunc(TEvents::TEvPoisonPill, HandlePoison);
+        }
+    }
+
+    void CompleteInitialization() {
         BLOG_D("NetClassifierUpdater has been initialized");
- 
-        Become(&TThis::Working); 
+
+        Become(&TThis::Working);
         Send(SelfId(), new TEvents::TEvWakeup);
-    } 
- 
-    STATEFN(Working) { 
-        switch (ev->GetTypeRewrite()) { 
-            hFunc(NHttp::TEvHttpProxy::TEvHttpIncomingResponse, HandleWhileWorking); 
-            hFunc(TEvConsole::TEvConfigureResponse, HandleWhileWorking); 
-            hFunc(TEvConsole::TEvGetConfigItemsResponse, HandleWhileWorking); 
-            hFunc(TEvents::TEvWakeup, HandleWhileWorking); 
-            hFunc(TEvents::TEvPoisonPill, HandlePoison); 
-        } 
-    } 
- 
+    }
+
+    STATEFN(Working) {
+        switch (ev->GetTypeRewrite()) {
+            hFunc(NHttp::TEvHttpProxy::TEvHttpIncomingResponse, HandleWhileWorking);
+            hFunc(TEvConsole::TEvConfigureResponse, HandleWhileWorking);
+            hFunc(TEvConsole::TEvGetConfigItemsResponse, HandleWhileWorking);
+            hFunc(TEvents::TEvWakeup, HandleWhileWorking);
+            hFunc(TEvents::TEvPoisonPill, HandlePoison);
+        }
+    }
+
     auto FormNetDataFromJson(TStringBuf jsonData) const {
         NKikimrNetClassifier::TNetData netData;
         TVector<TString> tagsToFilter(UpdaterConfig().GetNetBoxTags().begin(), UpdaterConfig().GetNetBoxTags().end());
@@ -212,35 +212,35 @@ private:
         return netData;
     }
 
-    auto FormNetData(TStringBuf tsvData) const { 
-        NKikimrNetClassifier::TNetData netData; 
- 
-        while (auto record = tsvData.NextTok('\n')) { 
-            auto& subnet = *netData.AddSubnets(); 
-            subnet.SetMask(TString(record.NextTok('\t'))); 
-            subnet.SetLabel(TString(record.NextTok('\t'))); 
-        } 
- 
-        return netData; 
-    } 
- 
-    void ScheduleNextUpdate() { 
-        const TDuration interval = TDuration::Seconds(UpdaterConfig().GetNetDataUpdateIntervalSeconds()); 
-        Schedule(interval, new TEvents::TEvWakeup); 
-    } 
- 
-    void InitializeAgain() { 
-        PackedNetData = {}; 
-        LastUpdateTimestamp = {}; 
-        LastUpdateDatetimeUTC = {}; 
- 
-        Become(&TThis::Initing); 
- 
-        const TDuration interval = TDuration::Seconds(UpdaterConfig().GetRetryIntervalSeconds()); 
-        Schedule(interval, new TEvents::TEvWakeup); 
-    } 
- 
-    void HandleWhileWorking(NHttp::TEvHttpProxy::TEvHttpIncomingResponse::TPtr& ev) { 
+    auto FormNetData(TStringBuf tsvData) const {
+        NKikimrNetClassifier::TNetData netData;
+
+        while (auto record = tsvData.NextTok('\n')) {
+            auto& subnet = *netData.AddSubnets();
+            subnet.SetMask(TString(record.NextTok('\t')));
+            subnet.SetLabel(TString(record.NextTok('\t')));
+        }
+
+        return netData;
+    }
+
+    void ScheduleNextUpdate() {
+        const TDuration interval = TDuration::Seconds(UpdaterConfig().GetNetDataUpdateIntervalSeconds());
+        Schedule(interval, new TEvents::TEvWakeup);
+    }
+
+    void InitializeAgain() {
+        PackedNetData = {};
+        LastUpdateTimestamp = {};
+        LastUpdateDatetimeUTC = {};
+
+        Become(&TThis::Initing);
+
+        const TDuration interval = TDuration::Seconds(UpdaterConfig().GetRetryIntervalSeconds());
+        Schedule(interval, new TEvents::TEvWakeup);
+    }
+
+    void HandleWhileWorking(NHttp::TEvHttpProxy::TEvHttpIncomingResponse::TPtr& ev) {
         if (ev->Get()->Error.empty()) {
             if (ev->Get()->Response->Status == "200") {
                 const auto netData = UpdaterConfig().GetFormat() == NKikimrNetClassifier::TNetClassifierUpdaterConfig::TSV
@@ -248,10 +248,10 @@ private:
                                                     : FormNetDataFromJson(ev->Get()->Response->Body);
                 if (netData.SubnetsSize() != 0) {
                     PackedNetData = PackAcquiredSubnets(netData);
- 
+
                     LastUpdateTimestamp = TActivationContext::Now();
                     LastUpdateDatetimeUTC = LastUpdateTimestamp.ToRfc822String(); // for viewer
- 
+
                     // To modify the config it's essential to find the current id and generation
                     RequestCurrentConfigViaCookie();
                     return;
@@ -263,89 +263,89 @@ private:
             }
         } else {
             BLOG_ERROR("NetClassifierUpdater failed to get subnets: " << ev->Get()->Error);
-        } 
+        }
         InitializeAgain();
-    } 
- 
-    void HandleWhileWorking(TEvConsole::TEvConfigureResponse::TPtr& ev) { 
-        const auto& record = ev->Get()->Record; 
-        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) { 
-            // hurray! the update is finished 
-            ScheduleNextUpdate(); 
-        } else { 
+    }
+
+    void HandleWhileWorking(TEvConsole::TEvConfigureResponse::TPtr& ev) {
+        const auto& record = ev->Get()->Record;
+        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) {
+            // hurray! the update is finished
+            ScheduleNextUpdate();
+        } else {
             BLOG_ERROR("NetClassifierUpdater failed to update distributable config: " << record.ShortDebugString());
-            InitializeAgain(); 
-        } 
-    } 
- 
-    void HandleWhileWorking(TEvConsole::TEvGetConfigItemsResponse::TPtr& ev) { 
-        const auto& record = ev->Get()->Record; 
-        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) { 
-            Y_VERIFY(record.ConfigItemsSize() == 1); // only one config item should have the cookie 
- 
-            auto event = MakeHolder<TEvConsole::TEvConfigureRequest>(); 
- 
-            auto& configItem = *event->Record.AddActions()->MutableModifyConfigItem()->MutableConfigItem(); 
- 
-            // copy id, generation and cookie 
-            configItem.CopyFrom(ev->Get()->Record.GetConfigItems(0)); 
- 
-            auto& distributableConfig = *configItem.MutableConfig()->MutableNetClassifierDistributableConfig(); 
-            distributableConfig.SetPackedNetData(PackedNetData); 
-            distributableConfig.SetLastUpdateDatetimeUTC(LastUpdateDatetimeUTC); 
-            distributableConfig.SetLastUpdateTimestamp(LastUpdateTimestamp.MicroSeconds()); 
- 
-            Send(LocalConsole, event.Release()); 
-        } else { 
+            InitializeAgain();
+        }
+    }
+
+    void HandleWhileWorking(TEvConsole::TEvGetConfigItemsResponse::TPtr& ev) {
+        const auto& record = ev->Get()->Record;
+        if (record.GetStatus().GetCode() == Ydb::StatusIds::SUCCESS) {
+            Y_VERIFY(record.ConfigItemsSize() == 1); // only one config item should have the cookie
+
+            auto event = MakeHolder<TEvConsole::TEvConfigureRequest>();
+
+            auto& configItem = *event->Record.AddActions()->MutableModifyConfigItem()->MutableConfigItem();
+
+            // copy id, generation and cookie
+            configItem.CopyFrom(ev->Get()->Record.GetConfigItems(0));
+
+            auto& distributableConfig = *configItem.MutableConfig()->MutableNetClassifierDistributableConfig();
+            distributableConfig.SetPackedNetData(PackedNetData);
+            distributableConfig.SetLastUpdateDatetimeUTC(LastUpdateDatetimeUTC);
+            distributableConfig.SetLastUpdateTimestamp(LastUpdateTimestamp.MicroSeconds());
+
+            Send(LocalConsole, event.Release());
+        } else {
             BLOG_ERROR("NetClassifierUpdater failed to get current distributable config version: " << record.ShortDebugString());
-            InitializeAgain(); 
-        } 
-    } 
- 
-    TString PackAcquiredSubnets(const NKikimrNetClassifier::TNetData& netData) const { 
-        TString serializedProto; 
+            InitializeAgain();
+        }
+    }
+
+    TString PackAcquiredSubnets(const NKikimrNetClassifier::TNetData& netData) const {
+        TString serializedProto;
         Y_PROTOBUF_SUPPRESS_NODISCARD netData.SerializeToString(&serializedProto);
- 
-        return PackNetData(serializedProto); 
-    } 
- 
-    void HandleWhileWorking(TEvents::TEvWakeup::TPtr&) { 
-        // it's high time to update the networks data! 
-        if (!HttpProxyId) { 
-            HttpProxyId = Register(NHttp::CreateHttpProxy(HttpSensors)); 
-        } 
- 
-        NHttp::THttpOutgoingRequestPtr httpRequest = 
-            NHttp::THttpOutgoingRequest::CreateRequestGet(UpdaterConfig().GetNetDataSourceUrl()); 
- 
-        Send(HttpProxyId, new NHttp::TEvHttpProxy::TEvHttpOutgoingRequest(httpRequest)); 
-    } 
- 
-    void HandlePoison(TEvents::TEvPoisonPill::TPtr&) { 
-        PassAway(); 
-    } 
- 
-private: 
+
+        return PackNetData(serializedProto);
+    }
+
+    void HandleWhileWorking(TEvents::TEvWakeup::TPtr&) {
+        // it's high time to update the networks data!
+        if (!HttpProxyId) {
+            HttpProxyId = Register(NHttp::CreateHttpProxy(HttpSensors));
+        }
+
+        NHttp::THttpOutgoingRequestPtr httpRequest =
+            NHttp::THttpOutgoingRequest::CreateRequestGet(UpdaterConfig().GetNetDataSourceUrl());
+
+        Send(HttpProxyId, new NHttp::TEvHttpProxy::TEvHttpOutgoingRequest(httpRequest));
+    }
+
+    void HandlePoison(TEvents::TEvPoisonPill::TPtr&) {
+        PassAway();
+    }
+
+private:
     TActorId LocalConsole;
     TActorId HttpProxyId;
     NMonitoring::TMetricRegistry HttpSensors;
- 
-    TString PackedNetData; 
-    TString LastUpdateDatetimeUTC; 
-    TInstant LastUpdateTimestamp; 
-}; 
- 
+
+    TString PackedNetData;
+    TString LastUpdateDatetimeUTC;
+    TInstant LastUpdateTimestamp;
+};
+
 IActor* MakeNetClassifierUpdaterActor(TActorId localConsole) {
-    return new NetClassifierUpdater(localConsole); 
-} 
- 
-TString UnpackNetData(const TString& packedNetData) { 
-    TStringInput stream(packedNetData); 
-    try { 
-        return TZLibDecompress(&stream, ZLib::GZip).ReadAll(); 
-    } catch (const yexception& e) { 
-        return {}; 
-    } 
-} 
- 
-} // namespace NKikimr::NNetClassifierUpdater 
+    return new NetClassifierUpdater(localConsole);
+}
+
+TString UnpackNetData(const TString& packedNetData) {
+    TStringInput stream(packedNetData);
+    try {
+        return TZLibDecompress(&stream, ZLib::GZip).ReadAll();
+    } catch (const yexception& e) {
+        return {};
+    }
+}
+
+} // namespace NKikimr::NNetClassifierUpdater

+ 11 - 11
ydb/core/cms/console/net_classifier_updater.h

@@ -1,12 +1,12 @@
-#pragma once 
- 
-#include "defs.h" 
-#include "console.h" 
- 
-namespace NKikimr::NNetClassifierUpdater { 
- 
+#pragma once
+
+#include "defs.h"
+#include "console.h"
+
+namespace NKikimr::NNetClassifierUpdater {
+
 IActor* MakeNetClassifierUpdaterActor(TActorId localConsole);
- 
-TString UnpackNetData(const TString& packedNetData); 
- 
-} // namespace NKikimr::NNetClassifierUpdater 
+
+TString UnpackNetData(const TString& packedNetData);
+
+} // namespace NKikimr::NNetClassifierUpdater

+ 117 - 117
ydb/core/cms/console/net_classifier_updater_ut.cpp

@@ -3,89 +3,89 @@
 #include <ydb/core/cms/console/console.h>
 #include <ydb/core/cms/console/net_classifier_updater.h>
 #include <ydb/core/testlib/test_client.h>
- 
+
 #include <library/cpp/actors/http/http_proxy.cpp>
- 
+
 #include <library/cpp/protobuf/util/is_equal.h>
- 
+
 #include <library/cpp/testing/unittest/tests_data.h>
 #include <library/cpp/testing/unittest/registar.h>
 #include <library/cpp/json/json_writer.h>
- 
-#include <util/string/builder.h> 
- 
-namespace NKikimr::NNetClassifierUpdaterTests { 
- 
-using namespace NConsole; 
-using namespace Tests; 
- 
+
+#include <util/string/builder.h>
+
+namespace NKikimr::NNetClassifierUpdaterTests {
+
+using namespace NConsole;
+using namespace Tests;
+
 using TNetClassifierUpdaterConfig = NKikimrNetClassifier::TNetClassifierUpdaterConfig;
 const TString NETWORKS_URI = "/fancy_path/networks.tsv";
 
-static NHttp::TEvHttpProxy::TEvHttpOutgoingResponse* MakeHttpResponse(NHttp::TEvHttpProxy::TEvHttpIncomingRequest* request, const TString& netData) { 
-    const TString content = TStringBuilder() << "HTTP/1.1 200 OK\r\nConnection: Close\r\nContent-Type: application/octet-stream\r\nContent-Length: " 
-                                             << netData.size() << "\r\n\r\n" << netData; 
-    NHttp::THttpOutgoingResponsePtr httpResponse = request->Request->CreateResponseString(content); 
- 
-    return new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(httpResponse); 
-} 
- 
-template<typename TDistributableConfProto> 
-bool CheckDistributableConfig(const TDistributableConfProto& config, const NKikimrNetClassifier::TNetData& expectedNetData) { 
-    if (config.GetPackedNetData()) { 
-        UNIT_ASSERT(config.GetLastUpdateDatetimeUTC()); 
-        UNIT_ASSERT(config.GetLastUpdateTimestamp()); 
- 
-        UNIT_ASSERT_STRINGS_EQUAL( 
-            TInstant::MicroSeconds(config.GetLastUpdateTimestamp()).ToRfc822String(), 
-            config.GetLastUpdateDatetimeUTC() 
-        ); 
- 
-        const TString serializedNetData = NNetClassifierUpdater::UnpackNetData(config.GetPackedNetData()); 
-        UNIT_ASSERT(serializedNetData); 
- 
-        NKikimrNetClassifier::TNetData netData; 
-        UNIT_ASSERT(netData.ParseFromString(serializedNetData)); 
- 
-        UNIT_ASSERT(NProtoBuf::IsEqual(netData, expectedNetData)); 
- 
-        return true; 
-    } 
- 
-    return false; 
-} 
- 
-static NKikimrNetClassifier::TNetData FormNetData() { 
-    NKikimrNetClassifier::TNetData netData; 
- 
-    { 
-        auto& subnet = *netData.AddSubnets(); 
-        subnet.SetMask("2a02:6b8:fc0a::/48"); 
-        subnet.SetLabel("SAS"); 
-    } 
-    { 
-        auto& subnet = *netData.AddSubnets(); 
-        subnet.SetMask("87.250.239.224/31"); 
-        subnet.SetLabel("VLA"); 
-    } 
- 
-    return netData; 
-} 
- 
-static TString ConvertToTsv(const NKikimrNetClassifier::TNetData& netData) { 
-    TStringBuilder builder; 
- 
-    for (size_t i = 0; i < netData.SubnetsSize(); ++i) { 
-        const auto& subnet = netData.GetSubnets(i); 
-        if (i) { 
-            builder << "\n"; 
-        } 
-        builder << subnet.GetMask() << "\t" << subnet.GetLabel(); 
-    } 
- 
-    return builder; 
-} 
- 
+static NHttp::TEvHttpProxy::TEvHttpOutgoingResponse* MakeHttpResponse(NHttp::TEvHttpProxy::TEvHttpIncomingRequest* request, const TString& netData) {
+    const TString content = TStringBuilder() << "HTTP/1.1 200 OK\r\nConnection: Close\r\nContent-Type: application/octet-stream\r\nContent-Length: "
+                                             << netData.size() << "\r\n\r\n" << netData;
+    NHttp::THttpOutgoingResponsePtr httpResponse = request->Request->CreateResponseString(content);
+
+    return new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(httpResponse);
+}
+
+template<typename TDistributableConfProto>
+bool CheckDistributableConfig(const TDistributableConfProto& config, const NKikimrNetClassifier::TNetData& expectedNetData) {
+    if (config.GetPackedNetData()) {
+        UNIT_ASSERT(config.GetLastUpdateDatetimeUTC());
+        UNIT_ASSERT(config.GetLastUpdateTimestamp());
+
+        UNIT_ASSERT_STRINGS_EQUAL(
+            TInstant::MicroSeconds(config.GetLastUpdateTimestamp()).ToRfc822String(),
+            config.GetLastUpdateDatetimeUTC()
+        );
+
+        const TString serializedNetData = NNetClassifierUpdater::UnpackNetData(config.GetPackedNetData());
+        UNIT_ASSERT(serializedNetData);
+
+        NKikimrNetClassifier::TNetData netData;
+        UNIT_ASSERT(netData.ParseFromString(serializedNetData));
+
+        UNIT_ASSERT(NProtoBuf::IsEqual(netData, expectedNetData));
+
+        return true;
+    }
+
+    return false;
+}
+
+static NKikimrNetClassifier::TNetData FormNetData() {
+    NKikimrNetClassifier::TNetData netData;
+
+    {
+        auto& subnet = *netData.AddSubnets();
+        subnet.SetMask("2a02:6b8:fc0a::/48");
+        subnet.SetLabel("SAS");
+    }
+    {
+        auto& subnet = *netData.AddSubnets();
+        subnet.SetMask("87.250.239.224/31");
+        subnet.SetLabel("VLA");
+    }
+
+    return netData;
+}
+
+static TString ConvertToTsv(const NKikimrNetClassifier::TNetData& netData) {
+    TStringBuilder builder;
+
+    for (size_t i = 0; i < netData.SubnetsSize(); ++i) {
+        const auto& subnet = netData.GetSubnets(i);
+        if (i) {
+            builder << "\n";
+        }
+        builder << subnet.GetMask() << "\t" << subnet.GetLabel();
+    }
+
+    return builder;
+}
+
 
 static TString ConvertToJson(const NKikimrNetClassifier::TNetData& netData) {
 
@@ -126,7 +126,7 @@ NKikimrNetClassifier::TNetClassifierUpdaterConfig CreateUpdaterConfig(
     return updaterConfig;
 }
 
-Y_UNIT_TEST_SUITE(TNetClassifierUpdaterTest) { 
+Y_UNIT_TEST_SUITE(TNetClassifierUpdaterTest) {
     void TestGetUpdatesFromHttpServer(
         const TString& sourceResponce,
         const NKikimrNetClassifier::TNetData& expectedNetData,
@@ -134,54 +134,54 @@ Y_UNIT_TEST_SUITE(TNetClassifierUpdaterTest) {
         const TVector<TString>& netBoxTags = {}
     ) {
         NMonitoring::TMetricRegistry sensors;
- 
-        TPortManager pm; 
-        const ui16 port = pm.GetPort(2134); 
-        const ui64 netDataSourcePort = pm.GetPort(13334); 
-        TServerSettings settings(port); 
-        auto& updaterConfig = *settings.NetClassifierConfig.MutableUpdaterConfig(); 
+
+        TPortManager pm;
+        const ui16 port = pm.GetPort(2134);
+        const ui64 netDataSourcePort = pm.GetPort(13334);
+        TServerSettings settings(port);
+        auto& updaterConfig = *settings.NetClassifierConfig.MutableUpdaterConfig();
         updaterConfig =  CreateUpdaterConfig(netDataSourcePort, format, netBoxTags);
-        TServer cleverServer = TServer(settings); 
-        auto& actorSystem = *cleverServer.GetRuntime(); 
- 
-        NActors::IActor* proxy = NHttp::CreateHttpProxy(sensors); 
+        TServer cleverServer = TServer(settings);
+        auto& actorSystem = *cleverServer.GetRuntime();
+
+        NActors::IActor* proxy = NHttp::CreateHttpProxy(sensors);
         NActors::TActorId proxyId = actorSystem.Register(proxy);
- 
-        actorSystem.Send( 
+
+        actorSystem.Send(
             new NActors::IEventHandle(proxyId, TActorId(), new NHttp::TEvHttpProxy::TEvAddListeningPort(netDataSourcePort)), 0, true
-        ); 
- 
+        );
+
         NActors::TActorId serverId = actorSystem.AllocateEdgeActor();
- 
+
         actorSystem.Send(new NActors::IEventHandle(proxyId, serverId, new NHttp::TEvHttpProxy::TEvRegisterHandler(NETWORKS_URI, serverId)), 0, true);
 
-        TAutoPtr<NActors::IEventHandle> handle; 
-        NHttp::TEvHttpProxy::TEvHttpIncomingRequest* request = actorSystem.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpIncomingRequest>(handle); 
+        TAutoPtr<NActors::IEventHandle> handle;
+        NHttp::TEvHttpProxy::TEvHttpIncomingRequest* request = actorSystem.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpIncomingRequest>(handle);
         UNIT_ASSERT_EQUAL(request->Request->URL, NETWORKS_URI);
- 
+
         actorSystem.Send(new NActors::IEventHandle(handle->Sender, serverId, MakeHttpResponse(request, sourceResponce)), 0, true);
         const TActorId sender = actorSystem.AllocateEdgeActor();
- 
-        size_t iterations = 0; 
-        while (true) { 
-            UNIT_ASSERT(++iterations < 60); 
- 
-            const auto kind = static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem); 
-            actorSystem.Send( 
-                new IEventHandle(MakeConfigsDispatcherID(sender.NodeId()), sender, 
-                    new TEvConfigsDispatcher::TEvGetConfigRequest(kind) 
-                )); 
- 
-            const auto event = cleverServer.GetRuntime()->GrabEdgeEvent<TEvConfigsDispatcher::TEvGetConfigResponse>(handle); 
- 
+
+        size_t iterations = 0;
+        while (true) {
+            UNIT_ASSERT(++iterations < 60);
+
+            const auto kind = static_cast<ui32>(NKikimrConsole::TConfigItem::NetClassifierDistributableConfigItem);
+            actorSystem.Send(
+                new IEventHandle(MakeConfigsDispatcherID(sender.NodeId()), sender,
+                    new TEvConfigsDispatcher::TEvGetConfigRequest(kind)
+                ));
+
+            const auto event = cleverServer.GetRuntime()->GrabEdgeEvent<TEvConfigsDispatcher::TEvGetConfigResponse>(handle);
+
             if (CheckDistributableConfig(event->Config->GetNetClassifierDistributableConfig(), expectedNetData)) {
-                break; 
-            } 
- 
-            // wait for the proper update 
-            Sleep(TDuration::Seconds(1)); 
-        } 
-    } 
+                break;
+            }
+
+            // wait for the proper update
+            Sleep(TDuration::Seconds(1));
+        }
+    }
 
     Y_UNIT_TEST(TestGetUpdatesFromHttpServer) {
         auto netData = FormNetData();
@@ -252,6 +252,6 @@ Y_UNIT_TEST_SUITE(TNetClassifierUpdaterTest) {
             TestGetUpdatesFromHttpServer(netboxResponce, data, TNetClassifierUpdaterConfig::NETBOX, {"qwerty"});
         }
     }
-} 
- 
-} // namespace NKikimr::NNetClassifierUpdaterTests 
+}
+
+} // namespace NKikimr::NNetClassifierUpdaterTests

Некоторые файлы не были показаны из-за большого количества измененных файлов