diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-11 23:22:24 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-11 23:22:24 +0300 |
commit | 3eef01c816b09f7a0ec64a381d835a53cc19631d (patch) | |
tree | d391ccd7d06754e515a9a5f8b4ebce0a78955297 /library | |
parent | 9873e45097a3e13e6dc4e8d05b283c7955eac126 (diff) | |
download | ydb-3eef01c816b09f7a0ec64a381d835a53cc19631d.tar.gz |
intermediate changes
ref:e232f8229b291f860c929fd7fb596842bff9452c
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/actors/core/mon.h | 69 | ||||
-rw-r--r-- | library/cpp/actors/core/mon_ut.cpp | 29 | ||||
-rw-r--r-- | library/cpp/actors/core/ut/ya.make | 1 | ||||
-rw-r--r-- | library/cpp/actors/protos/actors.proto | 20 |
4 files changed, 101 insertions, 18 deletions
diff --git a/library/cpp/actors/core/mon.h b/library/cpp/actors/core/mon.h index c450f2338e..ca2001e5f6 100644 --- a/library/cpp/actors/core/mon.h +++ b/library/cpp/actors/core/mon.h @@ -80,31 +80,54 @@ namespace NActors { }; struct TEvRemoteHttpInfo: public NActors::TEventBase<TEvRemoteHttpInfo, RemoteHttpInfo> { - TEvRemoteHttpInfo() { - } + TEvRemoteHttpInfo() = default; - TEvRemoteHttpInfo(const TString& query) + TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method = HTTP_METHOD_UNDEFINED) : Query(query) + , Method(method) { } - TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method) - : Query(query) - , Method(method) - { + TEvRemoteHttpInfo(NActorsProto::TRemoteHttpInfo info) + : Query(MakeSerializedQuery(info)) + , ExtendedQuery(std::move(info)) + {} + + static TString MakeSerializedQuery(const NActorsProto::TRemoteHttpInfo& info) { + TString s(1, '\0'); + const bool success = info.AppendToString(&s); + Y_VERIFY(success); + return s; } TString Query; - HTTP_METHOD Method; + HTTP_METHOD Method = HTTP_METHOD_UNDEFINED; + std::optional<NActorsProto::TRemoteHttpInfo> ExtendedQuery; TString PathInfo() const { - const size_t pos = Query.find('?'); - return (pos == TString::npos) ? TString() : Query.substr(0, pos); + if (ExtendedQuery) { + return ExtendedQuery->GetPath(); + } else { + const size_t pos = Query.find('?'); + return (pos == TString::npos) ? TString() : Query.substr(0, pos); + } } TCgiParameters Cgi() const { - const size_t pos = Query.find('?'); - return TCgiParameters((pos == TString::npos) ? TString() : Query.substr(pos + 1)); + if (ExtendedQuery) { + TCgiParameters params; + for (const auto& kv : ExtendedQuery->GetQueryParams()) { + params.emplace(kv.GetKey(), kv.GetValue()); + } + return params; + } else { + const size_t pos = Query.find('?'); + return TCgiParameters((pos == TString::npos) ? TString() : Query.substr(pos + 1)); + } + } + + HTTP_METHOD GetMethod() const { + return ExtendedQuery ? static_cast<HTTP_METHOD>(ExtendedQuery->GetMethod()) : Method; } TString ToStringHeader() const override { @@ -124,12 +147,22 @@ namespace NActors { } static IEventBase* Load(TEventSerializedData* bufs) { - return new TEvRemoteHttpInfo(bufs->GetString()); - } - - HTTP_METHOD GetMethod() const - { - return Method; + TString s = bufs->GetString(); + if (s.size() && s[0] == '\0') { + TRope::TConstIterator iter = bufs->GetBeginIter(); + ui64 size = bufs->GetSize(); + iter += 1, --size; // skip '\0' + TRopeStream stream(iter, size); + + auto res = std::make_unique<TEvRemoteHttpInfo>(); + res->Query = s; + res->ExtendedQuery.emplace(); + const bool success = res->ExtendedQuery->ParseFromZeroCopyStream(&stream); + Y_VERIFY(success); + return res.release(); + } else { + return new TEvRemoteHttpInfo(s); + } } }; diff --git a/library/cpp/actors/core/mon_ut.cpp b/library/cpp/actors/core/mon_ut.cpp new file mode 100644 index 0000000000..d70b2c4a89 --- /dev/null +++ b/library/cpp/actors/core/mon_ut.cpp @@ -0,0 +1,29 @@ +#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/actors/core/mon.h> + +using namespace NActors; +using namespace NMon; + +Y_UNIT_TEST_SUITE(ActorSystemMon) { + Y_UNIT_TEST(SerializeEv) { + NActorsProto::TRemoteHttpInfo info; + info.SetPath("hello"); + + auto ev = std::make_unique<TEvRemoteHttpInfo>(info); + UNIT_ASSERT(ev->ExtendedQuery); + UNIT_ASSERT_VALUES_EQUAL(ev->ExtendedQuery->GetPath(), info.GetPath()); + UNIT_ASSERT_VALUES_EQUAL(ev->PathInfo(), info.GetPath()); + + TAllocChunkSerializer ser; + const bool success = ev->SerializeToArcadiaStream(&ser); + Y_VERIFY(success); + auto buffer = ser.Release(false); + std::unique_ptr<TEvRemoteHttpInfo> restored(dynamic_cast<TEvRemoteHttpInfo*>(TEvRemoteHttpInfo::Load(buffer.Get()))); + UNIT_ASSERT(restored->Query == ev->Query); + UNIT_ASSERT(restored->Query.size()); + UNIT_ASSERT(restored->Query[0] == '\0'); + UNIT_ASSERT(restored->ExtendedQuery); + UNIT_ASSERT_VALUES_EQUAL(restored->ExtendedQuery->GetPath(), ev->ExtendedQuery->GetPath()); + UNIT_ASSERT_VALUES_EQUAL(restored->PathInfo(), ev->PathInfo()); + } +} diff --git a/library/cpp/actors/core/ut/ya.make b/library/cpp/actors/core/ut/ya.make index 3ee28d5850..f1d2d11c50 100644 --- a/library/cpp/actors/core/ut/ya.make +++ b/library/cpp/actors/core/ut/ya.make @@ -40,6 +40,7 @@ SRCS( executor_pool_united_ut.cpp log_ut.cpp memory_tracker_ut.cpp + mon_ut.cpp scheduler_actor_ut.cpp ) diff --git a/library/cpp/actors/protos/actors.proto b/library/cpp/actors/protos/actors.proto index 5fbd6d44ee..072040600d 100644 --- a/library/cpp/actors/protos/actors.proto +++ b/library/cpp/actors/protos/actors.proto @@ -11,3 +11,23 @@ message TCallbackException { required TActorId ActorId = 1; required string ExceptionMessage = 2; } + +message TRemoteHttpInfo { + message TQueryParam { + optional string Key = 1; + optional string Value = 2; + } + + message THeader { + optional string Name = 1; + optional string Value = 2; + } + + optional uint32 Method = 1; // HTTP_METHOD enum + optional string Path = 2; + repeated TQueryParam QueryParams = 3; + repeated TQueryParam PostParams = 4; + repeated bytes PostContent = 5; + optional THeader Headers = 6; + optional string RemoteAddr = 7; +} |