diff options
author | uzhas <uzhas@ydb.tech> | 2022-10-06 20:39:19 +0300 |
---|---|---|
committer | uzhas <uzhas@ydb.tech> | 2022-10-06 20:39:19 +0300 |
commit | 7be9429fa6e226df17f1e04841dc2962e1d8c755 (patch) | |
tree | 79eb4a896ce89d729da9e692e24ab707be8697ad | |
parent | 8a0c721548ffb3053cb6a3e08c0a9027712e2894 (diff) | |
download | ydb-7be9429fa6e226df17f1e04841dc2962e1d8c755.tar.gz |
remove fq from viewer
47 files changed, 165 insertions, 1287 deletions
diff --git a/ydb/core/viewer/CMakeLists.txt b/ydb/core/viewer/CMakeLists.txt index 5225c9bd5c..5b63ef674b 100644 --- a/ydb/core/viewer/CMakeLists.txt +++ b/ydb/core/viewer/CMakeLists.txt @@ -21,13 +21,11 @@ target_link_libraries(ydb-core-viewer PUBLIC cpp-actors-core library-cpp-archive cpp-mime-types - cpp-protobuf-json ydb-core-base core-blobstorage-base blobstorage-vdisk-common core-client-server ydb-core-health_check - ydb-core-grpc_services ydb-core-node_whiteboard ydb-core-protos ydb-core-scheme @@ -36,16 +34,12 @@ target_link_libraries(ydb-core-viewer PUBLIC ydb-core-util core-viewer-json core-viewer-protos - yq-libs-result_formatter library-persqueue-topic_parser api-protos lib-deprecated-kicli public-lib-json_value ) target_sources(ydb-core-viewer PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/http_router.cpp - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/grpc_request_context_wrapper.cpp - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/json_handlers_fq.cpp ${CMAKE_SOURCE_DIR}/ydb/core/viewer/json_handlers_vdisk.cpp ${CMAKE_SOURCE_DIR}/ydb/core/viewer/json_handlers_viewer.cpp ${CMAKE_SOURCE_DIR}/ydb/core/viewer/viewer.cpp @@ -65,13 +59,11 @@ target_link_libraries(ydb-core-viewer.global PUBLIC cpp-actors-core library-cpp-archive cpp-mime-types - cpp-protobuf-json ydb-core-base core-blobstorage-base blobstorage-vdisk-common core-client-server ydb-core-health_check - ydb-core-grpc_services ydb-core-node_whiteboard ydb-core-protos ydb-core-scheme @@ -80,7 +72,6 @@ target_link_libraries(ydb-core-viewer.global PUBLIC ydb-core-util core-viewer-json core-viewer-protos - yq-libs-result_formatter library-persqueue-topic_parser api-protos lib-deprecated-kicli diff --git a/ydb/core/viewer/grpc_request_context_wrapper.cpp b/ydb/core/viewer/grpc_request_context_wrapper.cpp deleted file mode 100644 index 4d2886b365..0000000000 --- a/ydb/core/viewer/grpc_request_context_wrapper.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "grpc_request_context_wrapper.h" -#include "viewer.h" - -namespace NKikimr { -namespace NViewer { - - TGrpcRequestContextWrapper::TGrpcRequestContextWrapper(TActorSystem* actorSystem, IViewer* viewer, const NMon::TEvHttpInfo::TPtr& event, std::unique_ptr<NProtoBuf::Message> request, TReplySender replySender) - : ActorSystem(actorSystem) - , Viewer(viewer) - , Event(event) - , Request(std::move(request)) - , ReplySender(std::move(replySender)) - , AuthState(true) - , DeadlineAt(TInstant::Max()) - { - const auto& params(Event->Get()->Request.GetParams()); - JsonSettings.EnumAsNumbers = false; - JsonSettings.UI64AsString = !FromStringWithDefault<bool>(params.Get("ui64"), false); - JsonSettings.EmptyRepeated = true; - const TString& timeout = params.Get("timeout"); - if (timeout) { - DeadlineAt = TInstant::Now() + TDuration::MilliSeconds(FromStringWithDefault<ui32>(timeout, 10000)); - } - Y_UNUSED(ActorSystem); - Y_UNUSED(Viewer); - Y_VERIFY(ActorSystem); - Y_VERIFY(Event); - } - - const NProtoBuf::Message* TGrpcRequestContextWrapper::GetRequest() const { - return Request.get(); - } - - NGrpc::TAuthState& TGrpcRequestContextWrapper::GetAuthState() { - return AuthState; - } - - void TGrpcRequestContextWrapper::Reply(NProtoBuf::Message* resp, ui32 status) { - Y_UNUSED(resp); - Y_UNUSED(status); - Y_VERIFY(resp); - ReplySender(ActorSystem, Viewer, Event, JsonSettings, resp, status); - } - - void TGrpcRequestContextWrapper::Reply(grpc::ByteBuffer* resp, ui32 status) { - Y_UNUSED(resp); - Y_UNUSED(status); - Y_VERIFY(false, "TGrpcRequestContextWrapper::Reply"); - } - - void TGrpcRequestContextWrapper::ReplyUnauthenticated(const TString& in) { - Y_UNUSED(in); - ActorSystem->Send(Event->Sender, new NMon::TEvHttpInfoRes(HTTPUNAUTHORIZEDTEXT + in, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - } - - void TGrpcRequestContextWrapper::ReplyError(grpc::StatusCode code, const TString& msg, const TString& details) { - Y_UNUSED(code); - Y_UNUSED(msg); - ActorSystem->Send(Event->Sender, new NMon::TEvHttpInfoRes(TStringBuilder() << HTTPBADREQUEST_HEADERS << "code: " << (int)code << ", msg: " << msg << ", details: " << details, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - } - - TInstant TGrpcRequestContextWrapper::Deadline() const { - return DeadlineAt; - } - - TSet<TStringBuf> TGrpcRequestContextWrapper::GetPeerMetaKeys() const { - return {}; - } - - TVector<TStringBuf> TGrpcRequestContextWrapper::GetPeerMetaValues(TStringBuf key) const { - // todo: remap http public headers into internal grpc headers, e.g - // Authorization -> x-ydb-auth-ticket - // scope/project - if (key == "x-ydb-auth-ticket"sv) { - key = "authorization"sv; - } - const THttpHeaders& headers = Event->Get()->Request.GetHeaders(); - if (auto h = headers.FindHeader(key)) { - return { h->Value() }; - } - return {}; - } - - google::protobuf::Arena* TGrpcRequestContextWrapper::GetArena() { - return &Arena; - } -} -} diff --git a/ydb/core/viewer/grpc_request_context_wrapper.h b/ydb/core/viewer/grpc_request_context_wrapper.h deleted file mode 100644 index 27e5cc346f..0000000000 --- a/ydb/core/viewer/grpc_request_context_wrapper.h +++ /dev/null @@ -1,51 +0,0 @@ -#include <ydb/core/grpc_services/base/base.h> -#include <ydb/core/viewer/json/json.h> -#include <ydb/public/api/protos/yq.pb.h> - -namespace NKikimr { -namespace NViewer { - -class IViewer; - -typedef std::function<void(TActorSystem* actorSystem, IViewer* viewer, const NMon::TEvHttpInfo::TPtr& event, const TJsonSettings& jsonSettings, NProtoBuf::Message* resp, ui32 status)> TReplySender; - -class TGrpcRequestContextWrapper : public NGrpc::IRequestContextBase { -private: - TActorSystem* ActorSystem; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; - std::unique_ptr<NProtoBuf::Message> Request; - TReplySender ReplySender; - NGrpc::TAuthState AuthState; - google::protobuf::Arena Arena; - TJsonSettings JsonSettings; - TInstant DeadlineAt; - -public: - TGrpcRequestContextWrapper(TActorSystem* actorSystem, IViewer* viewer, const NMon::TEvHttpInfo::TPtr& event, std::unique_ptr<NProtoBuf::Message> request, TReplySender replySender); - virtual const NProtoBuf::Message* GetRequest() const; - virtual NGrpc::TAuthState& GetAuthState(); - virtual void Reply(NProtoBuf::Message* resp, ui32 status = 0); - virtual void Reply(grpc::ByteBuffer* resp, ui32 status = 0); - virtual void ReplyUnauthenticated(const TString& in); - virtual void ReplyError(grpc::StatusCode code, const TString& msg, const TString& details); - virtual TInstant Deadline() const; - virtual TSet<TStringBuf> GetPeerMetaKeys() const; - virtual TVector<TStringBuf> GetPeerMetaValues(TStringBuf key) const; - virtual grpc_compression_level GetCompressionLevel() const { return GRPC_COMPRESS_LEVEL_NONE; } - - virtual google::protobuf::Arena* GetArena(); - - virtual void AddTrailingMetadata(const TString&, const TString&) {} - - virtual void UseDatabase(const TString& ) {} - - virtual void SetNextReplyCallback(TOnNextReply&&) {} - virtual void FinishStreamingOk() {} - virtual TAsyncFinishResult GetFinishFuture() { return {}; } - virtual TString GetPeer() const { return {}; } - virtual bool SslServer() const { return false; } -}; - -} -} diff --git a/ydb/core/viewer/http_handler.h b/ydb/core/viewer/http_handler.h deleted file mode 100644 index 9b879d5028..0000000000 --- a/ydb/core/viewer/http_handler.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include <library/cpp/actors/core/mon.h> - -namespace NActors { -class IActor; -} - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; -class IViewer; - -struct TRequest { - NMon::TEvHttpInfo::TPtr Event; - std::map<TString, TString> PathParams; -}; - -class TJsonHandlerBase { -public: - typedef std::shared_ptr<TJsonHandlerBase> TPtr; - -public: - virtual ~TJsonHandlerBase() = default; - virtual IActor* CreateRequestActor(IViewer* viewer, const TRequest& request) = 0; - virtual TString GetResponseJsonSchema() = 0; - virtual TString GetTags() { return TString(); } - virtual TString GetRequestSummary() { return TString(); } - virtual TString GetRequestDescription() { return TString(); } - virtual TString GetRequestParameters() { return TString(); } -}; - -} -} diff --git a/ydb/core/viewer/http_router.cpp b/ydb/core/viewer/http_router.cpp deleted file mode 100644 index c40c48724d..0000000000 --- a/ydb/core/viewer/http_router.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "http_router.h" - -namespace NKikimr { -namespace NViewer { - -namespace { - bool MatchPath(TStringBuf pathPattern, TStringBuf path, std::map<TString, TString>& pathParams) { - const char delim = '/'; - pathPattern.SkipPrefix("/"sv); - path.SkipPrefix("/"sv); - - TStringBuf pathPatternComponent = pathPattern.NextTok(delim); - TStringBuf pathComponent = path.NextTok(delim); - while (pathPatternComponent && pathComponent) { - if (pathPatternComponent.StartsWith('{') && pathPatternComponent.EndsWith('}')) { - TStringBuf paramName = pathPatternComponent.SubString(1, pathPatternComponent.Size() - 2); - pathParams.emplace(paramName, pathComponent); - } else { - if (pathPatternComponent != pathComponent) { - return false; - } - } - pathPatternComponent = pathPattern.NextTok(delim); - pathComponent = path.NextTok(delim); - } - - return !pathPattern && !path && !pathPatternComponent && !pathComponent; - } -} - -void THttpRequestRouter::RegisterHandler(HTTP_METHOD method, const TString& pathPattern, TJsonHandlerBase::TPtr handler) { - Data.emplace(std::make_pair(method, pathPattern), std::move(handler)); -} - -std::optional<THandlerWithParams> THttpRequestRouter::ResolveHandler(HTTP_METHOD method, const TStringBuf& path) const { - auto it = Data.find(std::pair<HTTP_METHOD, TString>(method, path)); - if (it != Data.end()) { - return THandlerWithParams(it->second, {}); - } - - for (const auto& [k ,v] : Data) { - if (k.first != method) { - continue; - } - std::map<TString, TString> pathParams; - if (MatchPath(k.second, path, pathParams)) { - return THandlerWithParams(v, pathParams); - } - } - return {}; -} - -size_t THttpRequestRouter::GetSize() const { - return Data.size(); -} - -} -} diff --git a/ydb/core/viewer/http_router.h b/ydb/core/viewer/http_router.h deleted file mode 100644 index 6549dd2476..0000000000 --- a/ydb/core/viewer/http_router.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "http_handler.h" - -namespace NKikimr { -namespace NViewer { - -struct THandlerWithParams { - THandlerWithParams(TJsonHandlerBase::TPtr handler, std::map<TString, TString> pathParams) - : Handler(std::move(handler)) - , PathParams(std::move(pathParams)) - { - } - - THandlerWithParams() = default; - THandlerWithParams(THandlerWithParams&&) = default; - THandlerWithParams& operator=(const THandlerWithParams&) = default; - THandlerWithParams& operator=(const THandlerWithParams&&) = default; - - TJsonHandlerBase::TPtr Handler; - std::map<TString, TString> PathParams; -}; - -class THttpRequestRouter { -public: - void RegisterHandler(HTTP_METHOD method, const TString& pathPattern, TJsonHandlerBase::TPtr handler); - void RegisterGetHandler(const TString& pathPattern, TJsonHandlerBase::TPtr handler) { - RegisterHandler(HTTP_METHOD_GET, pathPattern, handler); - } - - std::optional<THandlerWithParams> ResolveHandler(HTTP_METHOD method, const TStringBuf& path) const; - size_t GetSize() const; - - template <typename F> - void ForEach(F f) const { - for (const auto& [p, handler] : Data) { - f(p.first, p.second, handler); - } - } - -private: - std::map<std::pair<HTTP_METHOD, TString>, TJsonHandlerBase::TPtr> Data; -}; - -} -} diff --git a/ydb/core/viewer/http_router_ut.cpp b/ydb/core/viewer/http_router_ut.cpp deleted file mode 100644 index 04e0a0c86e..0000000000 --- a/ydb/core/viewer/http_router_ut.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include <library/cpp/testing/unittest/registar.h> -#include "http_router.h" - -using namespace NKikimr; -using namespace NViewer; - -namespace { -class TTestHandler : public TJsonHandlerBase { - int Id; -public: - explicit TTestHandler(int id) - : Id(id) - { - } - - int GetId() const { return Id; } - virtual IActor* CreateRequestActor(IViewer* , const TRequest&) { return nullptr; } - virtual TString GetResponseJsonSchema() { return TString(); } -}; - -std::shared_ptr<TTestHandler> AsTestHandler(TJsonHandlerBase::TPtr h) { - return std::static_pointer_cast<TTestHandler>(h); -} - -} -Y_UNIT_TEST_SUITE(HttpRouter) { - Y_UNIT_TEST(Basic) { - THttpRequestRouter router; - router.RegisterHandler(HTTP_METHOD_GET, "/apix/v1/fq/query", std::make_shared<TTestHandler>(1)); - router.RegisterHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/{query_id}", std::make_shared<TTestHandler>(2)); - UNIT_ASSERT_VALUES_EQUAL(router.GetSize(), 2); - - std::optional<THandlerWithParams> resolve1 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq"sv); - UNIT_ASSERT(!resolve1); - - std::optional<THandlerWithParams> resolve2 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/1234/status"sv); - UNIT_ASSERT(!resolve2); - - std::optional<THandlerWithParams> resolve3 = router.ResolveHandler(HTTP_METHOD_POST, "/apix/v1/fq/query"sv); - UNIT_ASSERT(!resolve3); - - std::optional<THandlerWithParams> resolve4 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query"sv); - UNIT_ASSERT(resolve4); - UNIT_ASSERT(resolve4->Handler); - UNIT_ASSERT_VALUES_EQUAL(AsTestHandler(resolve4->Handler)->GetId(), 1); - UNIT_ASSERT_VALUES_EQUAL(resolve4->PathParams.size(), 0u); - - std::optional<THandlerWithParams> resolve5 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/1234"sv); - UNIT_ASSERT(resolve5); - UNIT_ASSERT(resolve5->Handler); - UNIT_ASSERT_VALUES_EQUAL(AsTestHandler(resolve5->Handler)->GetId(), 2); - UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.size(), 1u); - - UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.begin()->first, "query_id"); - UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.begin()->second, "1234"); - } -} diff --git a/ydb/core/viewer/json_acl.h b/ydb/core/viewer/json_acl.h index 360e6c8186..43034830fc 100644 --- a/ydb/core/viewer/json_acl.h +++ b/ydb/core/viewer/json_acl.h @@ -27,9 +27,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonACL(IViewer* viewer, const TRequest& request) + TJsonACL(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { diff --git a/ydb/core/viewer/json_browse.h b/ydb/core/viewer/json_browse.h index b14019893a..20e1c6e119 100644 --- a/ydb/core/viewer/json_browse.h +++ b/ydb/core/viewer/json_browse.h @@ -59,9 +59,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonBrowse(IViewer* viewer, const TRequest& request) + TJsonBrowse(IViewer *viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void ParsePath(const TString& path, const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_bscontrollerinfo.h b/ydb/core/viewer/json_bscontrollerinfo.h index e0360953db..1daafd2368 100644 --- a/ydb/core/viewer/json_bscontrollerinfo.h +++ b/ydb/core/viewer/json_bscontrollerinfo.h @@ -27,9 +27,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonBSControllerInfo(IViewer* viewer, const TRequest& request) + TJsonBSControllerInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_cluster.h b/ydb/core/viewer/json_cluster.h index 4aeacb4f57..c7d15c25de 100644 --- a/ydb/core/viewer/json_cluster.h +++ b/ydb/core/viewer/json_cluster.h @@ -40,12 +40,12 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonCluster(IViewer* viewer, const TRequest& request) + TJsonCluster(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) + , Initiator(ev->Sender) , Requested(0) , Received(0) - , Event(request.Event) + , Event(ev) { const auto& params(Event->Get()->Request.GetParams()); JsonSettings.EnumAsNumbers = !FromStringWithDefault<bool>(params.Get("enums"), true); diff --git a/ydb/core/viewer/json_compute.h b/ydb/core/viewer/json_compute.h index 1cc911265d..c8e69815ca 100644 --- a/ydb/core/viewer/json_compute.h +++ b/ydb/core/viewer/json_compute.h @@ -51,9 +51,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonCompute(IViewer* viewer, const TRequest& request) + TJsonCompute(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} TString GetDomainId(TPathId pathId) { diff --git a/ydb/core/viewer/json_config.h b/ydb/core/viewer/json_config.h index 3efc43b53d..d9c3348a59 100644 --- a/ydb/core/viewer/json_config.h +++ b/ydb/core/viewer/json_config.h @@ -22,9 +22,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonConfig(IViewer* viewer, const TRequest& request) + TJsonConfig(IViewer *viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_content.h b/ydb/core/viewer/json_content.h index 9ed057c788..79b230f128 100644 --- a/ydb/core/viewer/json_content.h +++ b/ydb/core/viewer/json_content.h @@ -29,10 +29,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonContent(IViewer* viewer, const TRequest& request) + TJsonContent(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(ev) {} STFUNC(StateWaitingBrowse) { diff --git a/ydb/core/viewer/json_counters.h b/ydb/core/viewer/json_counters.h index 7e69b505d9..c56719c77d 100644 --- a/ydb/core/viewer/json_counters.h +++ b/ydb/core/viewer/json_counters.h @@ -31,9 +31,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonCounters(IViewer* viewer, const TRequest& request) + TJsonCounters(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) , Requested(0) , Received(0) {} diff --git a/ydb/core/viewer/json_describe.h b/ydb/core/viewer/json_describe.h index 00abe2190a..3f6ec6b59c 100644 --- a/ydb/core/viewer/json_describe.h +++ b/ydb/core/viewer/json_describe.h @@ -28,9 +28,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonDescribe(IViewer* viewer, const TRequest& request) + TJsonDescribe(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { diff --git a/ydb/core/viewer/json_handlers.h b/ydb/core/viewer/json_handlers.h index 84d049be19..526c671d01 100644 --- a/ydb/core/viewer/json_handlers.h +++ b/ydb/core/viewer/json_handlers.h @@ -1,15 +1,25 @@ #pragma once -#include "http_router.h" #include "viewer.h" +#include <ydb/core/viewer/json/json.h> namespace NKikimr::NViewer { +class TJsonHandlerBase { +public: + virtual ~TJsonHandlerBase() = default; + virtual IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) = 0; + virtual TString GetResponseJsonSchema() = 0; + virtual TString GetRequestSummary() { return TString(); } + virtual TString GetRequestDescription() { return TString(); } + virtual TString GetRequestParameters() { return TString(); } +}; + template <typename ActorRequestType> class TJsonHandler : public TJsonHandlerBase { public: - IActor* CreateRequestActor(IViewer* viewer, const TRequest& request) override { - return new ActorRequestType(viewer, request); + IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override { + return new ActorRequestType(viewer, event); } TString GetResponseJsonSchema() override { @@ -35,95 +45,63 @@ public: template <typename TTagInfo> struct TJsonHandlers { - THttpRequestRouter Router; + THashMap<TString, TAutoPtr<TJsonHandlerBase>> JsonHandlers; void Init(); void Handle(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev, const TActorContext &ctx) { NMon::TEvHttpInfo* msg = ev->Get(); - auto handlerWithParamsO = Router.ResolveHandler(msg->Request.GetMethod(), msg->Request.GetPage()->Path + msg->Request.GetPathInfo()); - if (!handlerWithParamsO) { - // for legendary /viewer handlers - handlerWithParamsO = Router.ResolveHandler(msg->Request.GetMethod(), msg->Request.GetPathInfo()); - if (!handlerWithParamsO) { - ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(NMonitoring::HTTPNOTFOUND)); + auto itJson = JsonHandlers.find(msg->Request.GetPage()->Path + msg->Request.GetPathInfo()); + if (itJson == JsonHandlers.end()) { + itJson = JsonHandlers.find(msg->Request.GetPathInfo()); + } + if (itJson != JsonHandlers.end()) { + try { + ctx.ExecutorThread.RegisterActor(itJson->second->CreateRequestActor(viewer, ev)); + } + catch (const std::exception& e) { + ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(TString("HTTP/1.1 400 Bad Request\r\n\r\n") + e.what(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); return; } - } - try { - TRequest request; - request.Event = ev; - request.PathParams = handlerWithParamsO->PathParams; - ctx.ExecutorThread.RegisterActor(handlerWithParamsO->Handler->CreateRequestActor(viewer, request)); - } catch (const std::exception& e) { - ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(TString("HTTP/1.1 400 Bad Request\r\n\r\n") + e.what(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return; + } else { + ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(NMonitoring::HTTPNOTFOUND)); } } - void PrintForSwagger(TStringStream &json) const { - std::map<TString, std::map<HTTP_METHOD, TJsonHandlerBase*>> allHandlers; - - Router.ForEach([&](HTTP_METHOD method, const TString& pathPattern, TJsonHandlerBase::TPtr handler) { - allHandlers[pathPattern][method] = handler.get(); - }); - - char sep = ' '; - for (const auto& [path, method2handler] : allHandlers) { - json << sep; - sep = ','; - - json << '"' << path << '"' << ":{"; - char methodSep = ' '; - for (const auto& [method, handler] : method2handler) { - json << methodSep; - methodSep = ','; - - auto methodName = ResolveMethodName(method); - json << "\"" << methodName << "\":{"; - json << "\"tags\":[\"" << TTagInfo::TagName << "\"],"; - json << "\"produces\":[\"application/json\"],"; - TString summary = handler->GetRequestSummary(); - if (!summary.empty()) { - json << "\"summary\":" << summary << ','; - } - TString description = handler->GetRequestDescription(); - if (!description.empty()) { - json << "\"description\":" << description << ','; - } - TString parameters = handler->GetRequestParameters(); - if (!parameters.empty()) { - json << "\"parameters\":" << parameters << ','; - } - json << "\"responses\":{"; - json << "\"200\":{"; - TString schema = handler->GetResponseJsonSchema(); - if (!schema.empty()) { - json << "\"schema\":" << schema; - } - json << "}"; + void PrintForSwagger(TStringStream &json) { + for (auto itJson = JsonHandlers.begin(); itJson != JsonHandlers.end(); ++itJson) { + if (itJson != JsonHandlers.begin()) { + json << ','; + } + TString name = itJson->first; + json << "\"/" << name << '"' << ":{"; + json << "\"get\":{"; + json << "\"tags\":[\"" << TTagInfo::TagName << "\"],"; + json << "\"produces\":[\"application/json\"],"; + TString summary = itJson->second->GetRequestSummary(); + if (!summary.empty()) { + json << "\"summary\":" << summary << ','; + } + TString description = itJson->second->GetRequestDescription(); + if (!description.empty()) { + json << "\"description\":" << description << ','; + } + TString parameters = itJson->second->GetRequestParameters(); + if (!parameters.empty()) { + json << "\"parameters\":" << parameters << ','; + } + json << "\"responses\":{"; + json << "\"200\":{"; + TString schema = itJson->second->GetResponseJsonSchema(); + if (!schema.empty()) { + json << "\"schema\":" << schema; + } json << "}"; json << "}"; - } + json << "}"; json << "}"; } } - - static std::string_view ResolveMethodName(HTTP_METHOD method) { - switch (method) { - case HTTP_METHOD_GET: - return "get"sv; - case HTTP_METHOD_POST: - return "post"sv; - case HTTP_METHOD_PUT: - return "put"sv; - case HTTP_METHOD_DELETE: - return "delete"sv; - default: - return "unknown http method"sv; - } - } - }; struct TViewerTagInfo { @@ -132,12 +110,9 @@ struct TViewerTagInfo { struct TVDiskTagInfo { static constexpr auto TagName = "vdisk"; }; -struct FQTagInfo { - static constexpr auto TagName = "fq"; -}; using TViewerJsonHandlers = TJsonHandlers<TViewerTagInfo>; using TVDiskJsonHandlers = TJsonHandlers<TVDiskTagInfo>; -using TFQJsonHandlers = TJsonHandlers<FQTagInfo>; + } diff --git a/ydb/core/viewer/json_handlers_fq.cpp b/ydb/core/viewer/json_handlers_fq.cpp deleted file mode 100644 index d12bb378fe..0000000000 --- a/ydb/core/viewer/json_handlers_fq.cpp +++ /dev/null @@ -1,617 +0,0 @@ -#include "grpc_request_context_wrapper.h" -#include "http_router.h" -#include "json_handlers.h" -#include "viewer.h" - -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/mon.h> -#include <library/cpp/protobuf/json/json2proto.h> -#include <ydb/core/protos/services.pb.h> -#include <ydb/core/grpc_services/grpc_request_proxy.h> -#include <ydb/core/grpc_services/service_yq.h> -#include <ydb/core/viewer/protos/fq.pb.h> -#include <ydb/core/yq/libs/result_formatter/result_formatter.h> - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; - -using ::google::protobuf::Descriptor; -using ::google::protobuf::FieldDescriptor; -using ::google::protobuf::Reflection; -using ::google::protobuf::RepeatedField; -using ::google::protobuf::RepeatedPtrField; - -#define SIMPLE_COPY_FIELD(field) dst.set_##field(src.field()) -#define SIMPLE_COPY_RENAME_FIELD(srcField, dstField) dst.set_##dstField(src.srcField()) - -#define SIMPLE_COPY_MUTABLE_FIELD(field) *dst.mutable_##field() = src.field() -#define SIMPLE_COPY_MUTABLE_RENAME_FIELD(srcField, dstField) *dst.mutable_##dstField() = src.srcField() - -#define SIMPLE_COPY_REPEATABLE_FIELD(field) FqConvert(src.field(), *dst.mutable_##field()) -#define SIMPLE_COPY_REPEATABLE_RENAME_FIELD(srcField, dstField) FqConvert(src.srcField(), *dst.mutable_##dstField()) - -#define FQ_CONVERT_FIELD(field) FqConvert(src.field(), *dst.mutable_##field()) -#define FQ_CONVERT_RENAME_FIELD(srcField, dstField) FqConvert(src.srcField(), *dst.mutable_##dstField()) - -template <typename T> -void FqConvert(const T& src, T& dst) { - dst.CopyFrom(src); -} - -template <typename T> -void FqConvert(const T& src, ::google::protobuf::Empty& dst) { - Y_UNUSED(src); - Y_UNUSED(dst); -} - -template <typename T, typename U> -void FqConvert(const RepeatedPtrField<T>& src, RepeatedPtrField<U>& dst) { - dst.Reserve(src.size()); - for (auto& v : src) { - FqConvert(v, *dst.Add()); - } -} - -void FqConvert(const Ydb::Operations::Operation& src, FederatedQueryHttp::Error& dst) { - SIMPLE_COPY_FIELD(status); - SIMPLE_COPY_MUTABLE_FIELD(issues); -} - -#define FQ_CONVERT_QUERY_CONTENT(srcType, dstType) \ -void FqConvert(const srcType& src, dstType& dst) { \ - SIMPLE_COPY_FIELD(type); \ - SIMPLE_COPY_FIELD(name); \ - SIMPLE_COPY_FIELD(text); \ - SIMPLE_COPY_FIELD(description); \ -} - -FQ_CONVERT_QUERY_CONTENT(FederatedQueryHttp::CreateQueryRequest, YandexQuery::QueryContent); -FQ_CONVERT_QUERY_CONTENT(YandexQuery::QueryContent, FederatedQueryHttp::GetQueryResult); - -void FqConvert(const FederatedQueryHttp::CreateQueryRequest& src, YandexQuery::CreateQueryRequest& dst) { - FqConvert(src, *dst.mutable_content()); - - dst.set_execute_mode(YandexQuery::RUN); - - auto& content = *dst.mutable_content(); - if (content.type() == YandexQuery::QueryContent::QUERY_TYPE_UNSPECIFIED) { - content.set_type(YandexQuery::QueryContent::ANALYTICS); - } - - if (content.acl().visibility() == YandexQuery::Acl::VISIBILITY_UNSPECIFIED) { - content.mutable_acl()->set_visibility(YandexQuery::Acl::PRIVATE); - } - - content.set_automatic(true); -} - -void FqConvert(const YandexQuery::CreateQueryResult& src, FederatedQueryHttp::CreateQueryResult& dst) { - SIMPLE_COPY_RENAME_FIELD(query_id, id); -} - -void FqConvert(const YandexQuery::CommonMeta& src, FederatedQueryHttp::QueryMeta& dst) { - SIMPLE_COPY_MUTABLE_FIELD(created_at); -} - -void FqConvert(const YandexQuery::QueryMeta& src, FederatedQueryHttp::QueryMeta& dst) { - SIMPLE_COPY_MUTABLE_FIELD(submitted_at); - SIMPLE_COPY_MUTABLE_FIELD(finished_at); - FqConvert(src.common(), dst); -} - -FederatedQueryHttp::GetQueryResult::ComputeStatus RemapQueryStatus(YandexQuery::QueryMeta::ComputeStatus status) { - switch (status) { - case YandexQuery::QueryMeta::COMPLETED: - return FederatedQueryHttp::GetQueryResult::COMPLETED; - - case YandexQuery::QueryMeta::ABORTED_BY_USER: - [[fallthrough]]; - case YandexQuery::QueryMeta::ABORTED_BY_SYSTEM: - [[fallthrough]]; - case YandexQuery::QueryMeta::FAILED: - return FederatedQueryHttp::GetQueryResult::FAILED; - - default: - return FederatedQueryHttp::GetQueryResult::RUNNING; - } -} - -void FqConvert(const YandexQuery::ResultSetMeta& src, FederatedQueryHttp::ResultSetMeta& dst) { - SIMPLE_COPY_FIELD(rows_count); - SIMPLE_COPY_FIELD(truncated); -} - -void FqConvert(const YandexQuery::Query& src, FederatedQueryHttp::GetQueryResult& dst) { - FQ_CONVERT_FIELD(meta); - - FqConvert(src.content(), dst); - dst.set_id(src.meta().common().id()); - dst.set_status(RemapQueryStatus(src.meta().status())); - - for (const auto& result_meta : src.result_set_meta()) { - FqConvert(result_meta, *dst.mutable_result_sets()->Add()); - } - - SIMPLE_COPY_MUTABLE_RENAME_FIELD(issue, issues); - dst.mutable_issues()->MergeFrom(src.transient_issue()); -} - -void FqConvert(const FederatedQueryHttp::GetQueryRequest& src, YandexQuery::DescribeQueryRequest& dst) { - SIMPLE_COPY_FIELD(query_id); -} - -void FqConvert(const YandexQuery::DescribeQueryResult& src, FederatedQueryHttp::GetQueryResult& dst) { - FqConvert(src.query(), dst); -} - -void FqConvert(const FederatedQueryHttp::DeleteQueryRequest& src, YandexQuery::DeleteQueryRequest& dst) { - SIMPLE_COPY_FIELD(query_id); -} - -void FqConvert(const FederatedQueryHttp::GetQueryStatusRequest& src, YandexQuery::GetQueryStatusRequest& dst) { - SIMPLE_COPY_FIELD(query_id); -} - -void FqConvert(const YandexQuery::GetQueryStatusResult& src, FederatedQueryHttp::GetQueryStatusResult& dst) { - dst.set_status(RemapQueryStatus(src.status())); -} - -void FqConvert(const FederatedQueryHttp::StopQueryRequest& src, YandexQuery::ControlQueryRequest& dst) { - SIMPLE_COPY_FIELD(query_id); - dst.set_action(YandexQuery::ABORT); -} - -void FqConvert(const FederatedQueryHttp::GetResultDataRequest& src, YandexQuery::GetResultDataRequest& dst) { - SIMPLE_COPY_FIELD(query_id); - SIMPLE_COPY_FIELD(result_set_index); - SIMPLE_COPY_FIELD(offset); - SIMPLE_COPY_FIELD(limit); - - if (!dst.limit()) { - dst.set_limit(100); - } -} - -void FqConvert(const YandexQuery::GetResultDataResult& src, FederatedQueryHttp::GetResultDataResult& dst) { - SIMPLE_COPY_MUTABLE_FIELD(result_set); -} - -template <typename T> -void FqPackToJson(TStringStream& json, const T& httpResult, const TJsonSettings& jsonSettings) { - TProtoToJson::ProtoToJson(json, httpResult, jsonSettings); -} - -void FqPackToJson(TStringStream& json, const FederatedQueryHttp::GetResultDataResult& httpResult, const TJsonSettings&) { - auto resultSet = NYdb::TResultSet(httpResult.result_set()); - NJson::TJsonValue v; - NYq::FormatResultSet(v, resultSet, true, true); - NJson::TJsonWriterConfig jsonWriterConfig; - jsonWriterConfig.WriteNanAsString = true; - NJson::WriteJson(&json, &v, jsonWriterConfig); -} - -template <typename T> -void SetIdempotencyKey(T& dst, const TString& key) { - Y_UNUSED(dst); - Y_UNUSED(key); - - if constexpr ( - std::is_same<T, YandexQuery::CreateQueryRequest>::value || - std::is_same<T, YandexQuery::ControlQueryRequest>::value || - std::is_same<T, YandexQuery::DeleteQueryRequest>::value) - { - dst.set_idempotency_key(key); - } -} - -template <typename GrpcProtoRequestType, typename HttpProtoRequestType, typename GrpcProtoResultType, typename HttpProtoResultType, typename GrpcProtoResponseType> -class TGrpcCallWrapper : public TActorBootstrapped<TGrpcCallWrapper<GrpcProtoRequestType, HttpProtoRequestType, GrpcProtoResultType, HttpProtoResultType, GrpcProtoResponseType>> { - IViewer* const Viewer; - const TRequest Request; - - typedef std::function<std::unique_ptr<NGRpcService::TEvProxyRuntimeEvent>(TIntrusivePtr<NGrpc::IRequestContextBase> ctx)> TGrpcProxyEventFactory; - TGrpcProxyEventFactory EventFactory; - - NProtobufJson::TJson2ProtoConfig Json2ProtoConfig; - -public: - typedef GrpcProtoRequestType TGrpcProtoRequestType; - typedef HttpProtoRequestType THttpProtoRequestType; - typedef GrpcProtoResultType TGrpcProtoResultType; - typedef HttpProtoResultType THttpProtoResultType; - typedef GrpcProtoResponseType TGrpcProtoResponseType; - -public: - static constexpr NKikimrServices::TActivity::EType ActorActivityType() { - return NKikimrServices::TActivity::VIEWER_HANDLER; - } - - TGrpcCallWrapper(IViewer* viewer, const TRequest& request, TGrpcProxyEventFactory eventFactory) - : Viewer(viewer) - , Request(request) - , EventFactory(eventFactory) - { - Json2ProtoConfig = NProtobufJson::TJson2ProtoConfig() - .SetFieldNameMode(NProtobufJson::TJson2ProtoConfig::FieldNameCamelCase) - .SetMapAsObject(true); - } - - const NMon::TEvHttpInfo::TPtr& GetEvent() const { - return Request.Event; - } - - void Bootstrap(const TActorContext& ctx) { - auto grpcRequest = std::make_unique<TGrpcProtoRequestType>(); - if (Parse(ctx, *grpcRequest)) { - TIntrusivePtr<TGrpcRequestContextWrapper> requestContext = new TGrpcRequestContextWrapper(ctx.ActorSystem(), Viewer, GetEvent(), std::move(grpcRequest), &SendReply); - ctx.Send(NGRpcService::CreateGRpcRequestProxyId(), EventFactory(requestContext).release()); - } - - this->Die(ctx); - } - - bool Parse(const TActorContext& ctx, TGrpcProtoRequestType& grpcRequest) { - try { - THttpProtoRequestType request; - const auto& httpRequest = GetEvent()->Get()->Request; - // todo: check Headers to copy idempotency-key into protobuf - if (httpRequest.GetMethod() == HTTP_METHOD_POST && httpRequest.GetHeader("content-type") == "application/json"sv) { - // todo: fix Duration + Timestamp parsing - // todo: PostContent is empty for PUT in monlib - NProtobufJson::Json2Proto(httpRequest.GetPostContent(), request, Json2ProtoConfig); - } - - const auto& params = httpRequest.GetParams(); - for (const auto& [name, value] : params) { - SetProtoMessageField(request, name, value); - } - - // path params should overwrite query params in case of conflict - for (const auto& [name, value] : Request.PathParams) { - SetProtoMessageField(request, name, value); - } - FqConvert(request, grpcRequest); - SetIdempotencyKey(grpcRequest, TString(httpRequest.GetHeader("idempotency-key"))); - - return true; - } catch (const std::exception& e) { - ReplyError(ctx, TStringBuilder() << "Error in parsing: " << e.what() << ", original text: " << GetEvent()->Get()->Request.GetPostContent()); - return false; - } - } - - static void SetProtoMessageField(THttpProtoRequestType& request, const TString& name, const TString& value) { - const Reflection* reflection = request.GetReflection(); - const Descriptor* descriptor = request.GetDescriptor(); - auto field = descriptor->FindFieldByLowercaseName(name); - if (!field) { - return; - } - - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: - return reflection->SetInt32(&request, field, FromString<i32>(value)); - case FieldDescriptor::CPPTYPE_INT64: - return reflection->SetInt64(&request, field, FromString<i64>(value)); - case FieldDescriptor::CPPTYPE_UINT32: - return reflection->SetUInt32(&request, field, FromString<ui32>(value)); - case FieldDescriptor::CPPTYPE_UINT64: - return reflection->SetUInt64(&request, field, FromString<ui64>(value)); - case FieldDescriptor::CPPTYPE_STRING: - return reflection->SetString(&request, field, value); - default: - break; - } - } - - void ReplyError(const TActorContext& ctx, const TString& error) { - ctx.Send(GetEvent()->Sender, new NMon::TEvHttpInfoRes(TStringBuilder() << HTTPBADREQUESTJSON << error, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - } - - static void SendReply(TActorSystem* actorSystem, IViewer* viewer, const NMon::TEvHttpInfo::TPtr& event, const TJsonSettings& jsonSettings, NProtoBuf::Message* resp, ui32 status) { - Y_VERIFY(resp); - Y_VERIFY(resp->GetArena()); - Y_UNUSED(status); - auto* typedResponse = static_cast<TGrpcProtoResponseType*>(resp); - if (!typedResponse->operation().result().template Is<TGrpcProtoResultType>()) { - TStringStream json; - auto* httpResult = google::protobuf::Arena::CreateMessage<FederatedQueryHttp::Error>(resp->GetArena()); - FqConvert(typedResponse->operation(), *httpResult); - FqPackToJson(json, *httpResult, jsonSettings); - - // todo: remap ydb status to http code - actorSystem->Send(event->Sender, new NMon::TEvHttpInfoRes(TStringBuilder() << HTTPBADREQUESTJSON << json.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return; - } - - auto* grpcResult = google::protobuf::Arena::CreateMessage<TGrpcProtoResultType>(resp->GetArena()); - typedResponse->operation().result().UnpackTo(grpcResult); - - if (THttpProtoResultType::descriptor()->full_name() == google::protobuf::Empty::descriptor()->full_name()) { - actorSystem->Send(event->Sender, new NMon::TEvHttpInfoRes( - "HTTP/1.1 204 No Content\r\n" - "Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return; - } - - TStringStream json; - auto* httpResult = google::protobuf::Arena::CreateMessage<THttpProtoResultType>(resp->GetArena()); - FqConvert(*grpcResult, *httpResult); - FqPackToJson(json, *httpResult, jsonSettings); - - actorSystem->Send(event->Sender, new NMon::TEvHttpInfoRes(viewer->GetHTTPOKJSON(event->Get()) + json.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - } -}; - -template <typename ProtoType> -void ProtoToPublicJsonSchema(IOutputStream& to) { - TJsonSettings settings; - settings.EnumAsNumbers = false; - settings.EmptyRepeated = true; - settings.EnumValueFilter = [](const TString& value) { - return !value.EndsWith("UNSPECIFIED"); - }; - - TProtoToJson::ProtoToJsonSchema<ProtoType>(to, settings); -} - - -#define DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, t1, t2, t3, t4, t5) \ -class TJson##action : public TGrpcCallWrapper<t1, t2, t3, t4, t5> { \ - typedef TGrpcCallWrapper<t1, t2, t3, t4, t5> TBase; \ -public: \ - TJson##action(IViewer* viewer, const TRequest& request) \ - : TBase(viewer, request, &NGRpcService::Create##internalAction##RequestOperationCall) {} \ -} - -#define DECLARE_YQ_GRPC_ACTOR(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, FederatedQueryHttp::action##Result, YandexQuery::internalAction##Response) -#define DECLARE_YQ_GRPC_ACTOR_WIHT_EMPTY_RESULT(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, ::google::protobuf::Empty, YandexQuery::internalAction##Response) - -//#define DECLARE_YQ_GRPC_ACTOR(action) DECLARE_YQ_GRPC_ACTOR_IMPL(action, action, YandexQuery::action##Request, YandexQuery::action##Request, YandexQuery::action##Result, YandexQuery::action##Result, YandexQuery::action##Response) -//#define DECLARE_YQ_GRPC_ACTOR_WITH_REMAPPING(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, FederatedQueryHttp::action##Result, YandexQuery::internalAction##Response) -//#define DECLARE_YQ_GRPC_ACTOR_WITH_REMAPPING_RESULT(action, internalAction, resultType) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, resultType, YandexQuery::internalAction##Response) - -// create queries -DECLARE_YQ_GRPC_ACTOR(CreateQuery, CreateQuery); - -template <> -struct TJsonRequestSchema<TJsonCreateQuery> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::CreateQueryResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonCreateQuery> { - static TString GetParameters() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::CreateQueryRequest>(stream); - auto bodyScheme = stream.Str(); - - return TStringBuilder() << R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"body","in":"body","required":true, "schema": )___" << bodyScheme << "}]"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonCreateQuery> { - static TString GetSummary() { - return "\"Create new query\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonCreateQuery> { - static TString GetDescription() { - return "\"Create new query and optionally run it\""; - } -}; - -// describe query -DECLARE_YQ_GRPC_ACTOR(GetQuery, DescribeQuery); - -template <> -struct TJsonRequestSchema<TJsonGetQuery> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::GetQueryResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonGetQuery> { - static TString GetParameters() { - return R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"query_id","in":"path","description":"query id", "required": true, "type":"string"} - ])___"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonGetQuery> { - static TString GetSummary() { - return "\"Get information about query\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonGetQuery> { - static TString GetDescription() { - return "\"Get detailed information about specified query\""; - } -}; - -// delete query -DECLARE_YQ_GRPC_ACTOR_WIHT_EMPTY_RESULT(DeleteQuery, DeleteQuery); - -template <> -struct TJsonRequestSchema<TJsonDeleteQuery> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::DeleteQueryResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonDeleteQuery> { - static TString GetParameters() { - return R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"idempotency-key","in":"header","description":"idempotency key", "required": false, "type":"string"}, - {"name":"query_id","in":"path","description":"query id", "required": true, "type":"string"} - ])___"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonDeleteQuery> { - static TString GetSummary() { - return "\"Delete query\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonDeleteQuery> { - static TString GetDescription() { - return "\"Delete existing query by id\""; - } -}; - -// get query status -DECLARE_YQ_GRPC_ACTOR(GetQueryStatus, GetQueryStatus); - -template <> -struct TJsonRequestSchema<TJsonGetQueryStatus> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::GetQueryStatusResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonGetQueryStatus> { - static TString GetParameters() { - return R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"idempotency-key","in":"header","description":"idempotency key", "required": false, "type":"string"}, - {"name":"query_id","in":"path","description":"query id", "required": true, "type":"string"} - ])___"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonGetQueryStatus> { - static TString GetSummary() { - return "\"Get query status\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonGetQueryStatus> { - static TString GetDescription() { - return "\"Get status of the query\""; - } -}; - -// stop query -DECLARE_YQ_GRPC_ACTOR_WIHT_EMPTY_RESULT(StopQuery, ControlQuery); - -template <> -struct TJsonRequestSchema<TJsonStopQuery> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::StopQueryResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonStopQuery> { - static TString GetParameters() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::StopQueryRequest>(stream); - auto bodyScheme = stream.Str(); - - return TStringBuilder() << R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"idempotency-key","in":"header","description":"idempotency key", "required": false, "type":"string"}, - {"name":"query_id","in":"path","description":"query id", "required": true, "type":"string"}, - {"name":"body","in":"body","required":false, "schema": )___" << bodyScheme << "}]"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonStopQuery> { - static TString GetSummary() { - return "\"Stop query\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonStopQuery> { - static TString GetDescription() { - return "\"Stop running query\""; - } -}; - -// get result data -DECLARE_YQ_GRPC_ACTOR(GetResultData, GetResultData); - -template <> -struct TJsonRequestSchema<TJsonGetResultData> { - static TString GetSchema() { - TStringStream stream; - ProtoToPublicJsonSchema<FederatedQueryHttp::GetResultDataResult>(stream); - return stream.Str(); - } -}; - -template <> -struct TJsonRequestParameters<TJsonGetResultData> { - static TString GetParameters() { - return R"___([ - {"name":"folder_id","in":"path","description":"folder id","required":true,"type":"string"}, - {"name":"idempotency-key","in":"header","description":"idempotency key", "required": false, "type":"string"}, - {"name":"query_id","in":"path","description":"query id", "required": true, "type":"string"}, - {"name":"result_set_index","in":"query","description":"result set index","required": true, "type":"integer"}, - {"name":"offset","in":"query","description":"row offset","default":0, "type":"integer"}, - {"name":"limit","in":"query","description":"row limit","default":100, "type":"integer"} - ])___"; - } -}; - -template <> -struct TJsonRequestSummary<TJsonGetResultData> { - static TString GetSummary() { - return "\"Get query results\""; - } -}; - -template <> -struct TJsonRequestDescription<TJsonGetResultData> { - static TString GetDescription() { - return "\"Get query results\""; - } -}; - -template <> -void TFQJsonHandlers::Init() { - Router.RegisterHandler(HTTP_METHOD_POST, "/fq/json/queries", std::make_shared<TJsonHandler<TJsonCreateQuery>>()); - Router.RegisterHandler(HTTP_METHOD_GET, "/fq/json/queries/{query_id}", std::make_shared<TJsonHandler<TJsonGetQuery>>()); - Router.RegisterHandler(HTTP_METHOD_DELETE, "/fq/json/queries/{query_id}", std::make_shared<TJsonHandler<TJsonDeleteQuery>>()); - Router.RegisterHandler(HTTP_METHOD_GET, "/fq/json/queries/{query_id}/status", std::make_shared<TJsonHandler<TJsonGetQueryStatus>>()); - Router.RegisterHandler(HTTP_METHOD_GET, "/fq/json/queries/{query_id}/results", std::make_shared<TJsonHandler<TJsonGetResultData>>()); - Router.RegisterHandler(HTTP_METHOD_POST, "/fq/json/queries/{query_id}/stop", std::make_shared<TJsonHandler<TJsonStopQuery>>()); -} - -} -} diff --git a/ydb/core/viewer/json_handlers_vdisk.cpp b/ydb/core/viewer/json_handlers_vdisk.cpp index a80b01f775..4684d8a2ff 100644 --- a/ydb/core/viewer/json_handlers_vdisk.cpp +++ b/ydb/core/viewer/json_handlers_vdisk.cpp @@ -8,8 +8,8 @@ namespace NKikimr::NViewer { template <> void TVDiskJsonHandlers::Init() { - Router.RegisterGetHandler("/vdisk/json/vdiskstat", std::make_shared<TJsonHandler<TJsonVDiskStat>>()); - Router.RegisterGetHandler("/vdisk/json/getblob", std::make_shared<TJsonHandler<TJsonGetBlob>>()); + JsonHandlers["vdisk/json/vdiskstat"] = new TJsonHandler<TJsonVDiskStat>; + JsonHandlers["vdisk/json/getblob"] = new TJsonHandler<TJsonGetBlob>; } } diff --git a/ydb/core/viewer/json_handlers_viewer.cpp b/ydb/core/viewer/json_handlers_viewer.cpp index bc965caa0a..a564147bb9 100644 --- a/ydb/core/viewer/json_handlers_viewer.cpp +++ b/ydb/core/viewer/json_handlers_viewer.cpp @@ -39,40 +39,36 @@ namespace NKikimr::NViewer { template <> void TViewerJsonHandlers::Init() { - Router.RegisterGetHandler("/json/nodelist", std::make_shared<TJsonHandler<TJsonNodeList>>()); - Router.RegisterGetHandler("/json/nodeinfo", std::make_shared<TJsonHandler<TJsonNodeInfo>>()); - Router.RegisterGetHandler("/json/vdiskinfo", std::make_shared<TJsonHandler<TJsonVDiskInfo>>()); - Router.RegisterGetHandler("/json/pdiskinfo", std::make_shared<TJsonHandler<TJsonPDiskInfo>>()); - Router.RegisterGetHandler("/json/describe", std::make_shared<TJsonHandler<TJsonDescribe>>()); - Router.RegisterGetHandler("/json/hotkeys", std::make_shared<TJsonHandler<TJsonHotkeys>>()); - Router.RegisterGetHandler("/json/sysinfo", std::make_shared<TJsonHandler<TJsonSysInfo>>()); - Router.RegisterGetHandler("/json/tabletinfo", std::make_shared<TJsonHandler<TJsonTabletInfo>>()); - Router.RegisterGetHandler("/json/hiveinfo", std::make_shared<TJsonHandler<TJsonHiveInfo>>()); - Router.RegisterGetHandler("/json/bsgroupinfo", std::make_shared<TJsonHandler<TJsonBSGroupInfo>>()); - Router.RegisterGetHandler("/json/bscontrollerinfo", std::make_shared<TJsonHandler<TJsonBSControllerInfo>>()); - Router.RegisterGetHandler("/json/config", std::make_shared<TJsonHandler<TJsonConfig>>()); - Router.RegisterGetHandler("/json/counters", std::make_shared<TJsonHandler<TJsonCounters>>()); - Router.RegisterGetHandler("/json/topicinfo", std::make_shared<TJsonHandler<TJsonTopicInfo>>()); - Router.RegisterGetHandler("/json/pqconsumerinfo", std::make_shared<TJsonHandler<TJsonPQConsumerInfo>>()); - Router.RegisterGetHandler("/json/tabletcounters", std::make_shared<TJsonHandler<TJsonTabletCounters>>()); - Router.RegisterGetHandler("/json/storage", std::make_shared<TJsonHandler<TJsonStorage>>()); - Router.RegisterGetHandler("/json/metainfo", std::make_shared<TJsonHandler<TJsonMetaInfo>>()); - Router.RegisterGetHandler("/json/browse", std::make_shared<TJsonHandler<TJsonBrowse>>()); - Router.RegisterGetHandler("/json/cluster", std::make_shared<TJsonHandler<TJsonCluster>>()); - Router.RegisterGetHandler("/json/content", std::make_shared<TJsonHandler<TJsonContent>>()); - Router.RegisterGetHandler("/json/labeledcounters", std::make_shared<TJsonHandler<TJsonLabeledCounters>>()); - Router.RegisterGetHandler("/json/tenants", std::make_shared<TJsonHandler<TJsonTenants>>()); - Router.RegisterGetHandler("/json/hivestats", std::make_shared<TJsonHandler<TJsonHiveStats>>()); - Router.RegisterGetHandler("/json/tenantinfo", std::make_shared<TJsonHandler<TJsonTenantInfo>>()); - Router.RegisterGetHandler("/json/whoami", std::make_shared<TJsonHandler<TJsonWhoAmI>>()); - Router.RegisterGetHandler("/json/netinfo", std::make_shared<TJsonHandler<TJsonNetInfo>>()); - Router.RegisterGetHandler("/json/compute", std::make_shared<TJsonHandler<TJsonCompute>>()); - Router.RegisterGetHandler("/json/healthcheck", std::make_shared<TJsonHandler<TJsonHealthCheck>>()); - Router.RegisterGetHandler("/json/nodes", std::make_shared<TJsonHandler<TJsonNodes>>()); - Router.RegisterGetHandler("/json/acl", std::make_shared<TJsonHandler<TJsonACL>>()); - - Router.RegisterHandler(HTTP_METHOD_GET, "/json/query", std::make_shared<TJsonHandler<TJsonQuery>>()); - Router.RegisterHandler(HTTP_METHOD_POST, "/json/query", std::make_shared<TJsonHandler<TJsonQuery>>()); -} - -} + JsonHandlers["/json/nodelist"] = new TJsonHandler<TJsonNodeList>; + JsonHandlers["/json/nodeinfo"] = new TJsonHandler<TJsonNodeInfo>; + JsonHandlers["/json/vdiskinfo"] = new TJsonHandler<TJsonVDiskInfo>; + JsonHandlers["/json/pdiskinfo"] = new TJsonHandler<TJsonPDiskInfo>; + JsonHandlers["/json/describe"] = new TJsonHandler<TJsonDescribe>; + JsonHandlers["/json/hotkeys"] = new TJsonHandler<TJsonHotkeys>; + JsonHandlers["/json/sysinfo"] = new TJsonHandler<TJsonSysInfo>; + JsonHandlers["/json/tabletinfo"] = new TJsonHandler<TJsonTabletInfo>; + JsonHandlers["/json/hiveinfo"] = new TJsonHandler<TJsonHiveInfo>; + JsonHandlers["/json/bsgroupinfo"] = new TJsonHandler<TJsonBSGroupInfo>; + JsonHandlers["/json/bscontrollerinfo"] = new TJsonHandler<TJsonBSControllerInfo>; + JsonHandlers["/json/config"] = new TJsonHandler<TJsonConfig>; + JsonHandlers["/json/counters"] = new TJsonHandler<TJsonCounters>; + JsonHandlers["/json/topicinfo"] = new TJsonHandler<TJsonTopicInfo>; + JsonHandlers["/json/pqconsumerinfo"] = new TJsonHandler<TJsonPQConsumerInfo>(); + JsonHandlers["/json/tabletcounters"] = new TJsonHandler<TJsonTabletCounters>; + JsonHandlers["/json/storage"] = new TJsonHandler<TJsonStorage>; + JsonHandlers["/json/metainfo"] = new TJsonHandler<TJsonMetaInfo>; + JsonHandlers["/json/browse"] = new TJsonHandler<TJsonBrowse>; + JsonHandlers["/json/cluster"] = new TJsonHandler<TJsonCluster>; + JsonHandlers["/json/content"] = new TJsonHandler<TJsonContent>; + JsonHandlers["/json/labeledcounters"] = new TJsonHandler<TJsonLabeledCounters>; + JsonHandlers["/json/tenants"] = new TJsonHandler<TJsonTenants>; + JsonHandlers["/json/hivestats"] = new TJsonHandler<TJsonHiveStats>; + JsonHandlers["/json/tenantinfo"] = new TJsonHandler<TJsonTenantInfo>; + JsonHandlers["/json/whoami"] = new TJsonHandler<TJsonWhoAmI>; + JsonHandlers["/json/query"] = new TJsonHandler<TJsonQuery>; + JsonHandlers["/json/netinfo"] = new TJsonHandler<TJsonNetInfo>; + JsonHandlers["/json/compute"] = new TJsonHandler<TJsonCompute>; + JsonHandlers["/json/healthcheck"] = new TJsonHandler<TJsonHealthCheck>; + JsonHandlers["/json/nodes"] = new TJsonHandler<TJsonNodes>; + JsonHandlers["/json/acl"] = new TJsonHandler<TJsonACL>; +}} diff --git a/ydb/core/viewer/json_healthcheck.h b/ydb/core/viewer/json_healthcheck.h index 8739f6008b..2f0e5efa73 100644 --- a/ydb/core/viewer/json_healthcheck.h +++ b/ydb/core/viewer/json_healthcheck.h @@ -28,9 +28,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonHealthCheck(IViewer* viewer, const TRequest& request) + TJsonHealthCheck(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap() { diff --git a/ydb/core/viewer/json_hiveinfo.h b/ydb/core/viewer/json_hiveinfo.h index a229cb7096..0fa58d281d 100644 --- a/ydb/core/viewer/json_hiveinfo.h +++ b/ydb/core/viewer/json_hiveinfo.h @@ -28,9 +28,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonHiveInfo(IViewer* viewer, const TRequest& request) + TJsonHiveInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap() { diff --git a/ydb/core/viewer/json_hivestats.h b/ydb/core/viewer/json_hivestats.h index 0460526b81..4c2e623006 100644 --- a/ydb/core/viewer/json_hivestats.h +++ b/ydb/core/viewer/json_hivestats.h @@ -27,9 +27,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonHiveStats(IViewer* viewer, const TRequest& request) + TJsonHiveStats(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap() { diff --git a/ydb/core/viewer/json_hotkeys.h b/ydb/core/viewer/json_hotkeys.h index 6ec4cc372f..714a9aa17c 100644 --- a/ydb/core/viewer/json_hotkeys.h +++ b/ydb/core/viewer/json_hotkeys.h @@ -41,9 +41,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonHotkeys(IViewer* viewer, const TRequest& request) + TJsonHotkeys(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { diff --git a/ydb/core/viewer/json_labeledcounters.h b/ydb/core/viewer/json_labeledcounters.h index 33cb5efff6..3b3663bc47 100644 --- a/ydb/core/viewer/json_labeledcounters.h +++ b/ydb/core/viewer/json_labeledcounters.h @@ -33,9 +33,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonLabeledCounters(IViewer* viewer, const TRequest& request) + TJsonLabeledCounters(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_metainfo.h b/ydb/core/viewer/json_metainfo.h index 97c3bb69e0..f507909e24 100644 --- a/ydb/core/viewer/json_metainfo.h +++ b/ydb/core/viewer/json_metainfo.h @@ -41,9 +41,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonMetaInfo(IViewer* viewer, const TRequest& request) + TJsonMetaInfo(IViewer *viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_netinfo.h b/ydb/core/viewer/json_netinfo.h index 3c0446ef77..8d4ab1ddee 100644 --- a/ydb/core/viewer/json_netinfo.h +++ b/ydb/core/viewer/json_netinfo.h @@ -44,9 +44,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonNetInfo(IViewer* viewer, const TRequest& request) + TJsonNetInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap() { diff --git a/ydb/core/viewer/json_nodelist.h b/ydb/core/viewer/json_nodelist.h index c9653d465c..7512294151 100644 --- a/ydb/core/viewer/json_nodelist.h +++ b/ydb/core/viewer/json_nodelist.h @@ -22,9 +22,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonNodeList(IViewer* viewer, const TRequest& request) + TJsonNodeList(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_nodes.h b/ydb/core/viewer/json_nodes.h index 765bfb5081..352ab12060 100644 --- a/ydb/core/viewer/json_nodes.h +++ b/ydb/core/viewer/json_nodes.h @@ -84,10 +84,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonNodes(IViewer* viewer, const TRequest& request) + TJsonNodes(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(std::move(ev)) { const auto& params(Event->Get()->Request.GetParams()); JsonSettings.EnumAsNumbers = !FromStringWithDefault<bool>(params.Get("enums"), true); diff --git a/ydb/core/viewer/json_pqconsumerinfo.h b/ydb/core/viewer/json_pqconsumerinfo.h index e312b585fa..b7526edf7d 100644 --- a/ydb/core/viewer/json_pqconsumerinfo.h +++ b/ydb/core/viewer/json_pqconsumerinfo.h @@ -34,9 +34,12 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonPQConsumerInfo(IViewer* viewer, const TRequest& request) + TJsonPQConsumerInfo( + IViewer* viewer, + NMon::TEvHttpInfo::TPtr& ev + ) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/json_query.h index f42371ef10..fc7566e71c 100644 --- a/ydb/core/viewer/json_query.h +++ b/ydb/core/viewer/json_query.h @@ -40,10 +40,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonQuery(IViewer* viewer, const TRequest& request) + TJsonQuery(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(ev) {} STATEFN(StateWork) { diff --git a/ydb/core/viewer/json_storage.h b/ydb/core/viewer/json_storage.h index bbb90cbbc2..91891e6da8 100644 --- a/ydb/core/viewer/json_storage.h +++ b/ydb/core/viewer/json_storage.h @@ -84,10 +84,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonStorage(IViewer* viewer, const TRequest& request) + TJsonStorage(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(std::move(ev)) { const auto& params(Event->Get()->Request.GetParams()); JsonSettings.EnumAsNumbers = !FromStringWithDefault<bool>(params.Get("enums"), true); diff --git a/ydb/core/viewer/json_tabletcounters.h b/ydb/core/viewer/json_tabletcounters.h index 6ac06fac55..19202d95d1 100644 --- a/ydb/core/viewer/json_tabletcounters.h +++ b/ydb/core/viewer/json_tabletcounters.h @@ -33,9 +33,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonTabletCounters(IViewer* viewer, const TRequest& request) + TJsonTabletCounters(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} static NTabletPipe::TClientConfig InitPipeClientConfig() { diff --git a/ydb/core/viewer/json_tabletinfo.h b/ydb/core/viewer/json_tabletinfo.h index 2061dfe2fe..3f273e8e95 100644 --- a/ydb/core/viewer/json_tabletinfo.h +++ b/ydb/core/viewer/json_tabletinfo.h @@ -55,8 +55,8 @@ class TJsonTabletInfo : public TJsonWhiteboardRequest<TEvWhiteboard::TEvTabletSt using TThis = TJsonTabletInfo; TVector<ui64> Tablets; public: - TJsonTabletInfo(IViewer* viewer, const TRequest& request) - : TJsonWhiteboardRequest(viewer, request) + TJsonTabletInfo(IViewer *viewer, NMon::TEvHttpInfo::TPtr &ev) + : TJsonWhiteboardRequest(viewer, ev) {} static NTabletPipe::TClientConfig InitPipeClientConfig() { diff --git a/ydb/core/viewer/json_tenantinfo.h b/ydb/core/viewer/json_tenantinfo.h index 515350e8e7..9a27f8e968 100644 --- a/ydb/core/viewer/json_tenantinfo.h +++ b/ydb/core/viewer/json_tenantinfo.h @@ -49,9 +49,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonTenantInfo(IViewer* viewer, const TRequest& request) + TJsonTenantInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} TString GetDomainId(TPathId pathId) { diff --git a/ydb/core/viewer/json_tenants.h b/ydb/core/viewer/json_tenants.h index f44f4f516b..098d15813c 100644 --- a/ydb/core/viewer/json_tenants.h +++ b/ydb/core/viewer/json_tenants.h @@ -30,9 +30,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonTenants(IViewer* viewer, const TRequest& request) + TJsonTenants(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap() { diff --git a/ydb/core/viewer/json_topicinfo.h b/ydb/core/viewer/json_topicinfo.h index e25a47ef6a..28d79a446f 100644 --- a/ydb/core/viewer/json_topicinfo.h +++ b/ydb/core/viewer/json_topicinfo.h @@ -29,9 +29,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonTopicInfo(IViewer* viewer, const TRequest& request) + TJsonTopicInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { diff --git a/ydb/core/viewer/json_vdisk_req.h b/ydb/core/viewer/json_vdisk_req.h index 20d5298bac..3a6c3d0884 100644 --- a/ydb/core/viewer/json_vdisk_req.h +++ b/ydb/core/viewer/json_vdisk_req.h @@ -66,10 +66,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonVDiskRequest(IViewer* viewer, const TRequest& request) + TJsonVDiskRequest(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(ev) {} virtual void Bootstrap() { diff --git a/ydb/core/viewer/json_wb_req.h b/ydb/core/viewer/json_wb_req.h index 8fd19767f3..a0f0d9cdda 100644 --- a/ydb/core/viewer/json_wb_req.h +++ b/ydb/core/viewer/json_wb_req.h @@ -66,10 +66,10 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonWhiteboardRequest(IViewer* viewer, const TRequest& request) + TJsonWhiteboardRequest(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Initiator(request.Event->Sender) - , Event(request.Event) + , Initiator(ev->Sender) + , Event(ev) {} THolder<RequestType> BuildRequest(TNodeId nodeId) { diff --git a/ydb/core/viewer/json_whoami.h b/ydb/core/viewer/json_whoami.h index 5bd48a75d4..fea374b41d 100644 --- a/ydb/core/viewer/json_whoami.h +++ b/ydb/core/viewer/json_whoami.h @@ -22,9 +22,9 @@ public: return NKikimrServices::TActivity::VIEWER_HANDLER; } - TJsonWhoAmI(IViewer* viewer, const TRequest& request) + TJsonWhoAmI(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) : Viewer(viewer) - , Event(request.Event) + , Event(ev) {} void Bootstrap(const TActorContext& ctx) { @@ -39,7 +39,7 @@ public: Y_PROTOBUF_SUPPRESS_NODISCARD userToken.ParseFromString(Event->Get()->UserToken); TStringStream json; TProtoToJson::ProtoToJson(json, userToken, JsonSettings); - ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get()) +json.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); + ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get()) + json.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } diff --git a/ydb/core/viewer/protos/CMakeLists.txt b/ydb/core/viewer/protos/CMakeLists.txt index a2cdf6fc63..9331c1366e 100644 --- a/ydb/core/viewer/protos/CMakeLists.txt +++ b/ydb/core/viewer/protos/CMakeLists.txt @@ -15,7 +15,6 @@ target_link_libraries(core-viewer-protos PUBLIC contrib-libs-protobuf ) target_proto_messages(core-viewer-protos PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/protos/fq.proto ${CMAKE_SOURCE_DIR}/ydb/core/viewer/protos/viewer.proto ) target_proto_addincls(core-viewer-protos diff --git a/ydb/core/viewer/protos/fq.proto b/ydb/core/viewer/protos/fq.proto deleted file mode 100644 index 2c6a19f833..0000000000 --- a/ydb/core/viewer/protos/fq.proto +++ /dev/null @@ -1,105 +0,0 @@ -syntax = "proto3"; -option cc_enable_arenas = true; - -package FederatedQueryHttp; - -import "ydb/public/api/protos/annotations/validation.proto"; -import "ydb/public/api/protos/ydb_issue_message.proto"; -import "ydb/public/api/protos/ydb_status_codes.proto"; -import "ydb/public/api/protos/ydb_value.proto"; -import "google/protobuf/timestamp.proto"; -import "ydb/public/api/protos/yq.proto"; - -//////////////////////////////////////////////////////////// - -message Error { - Ydb.StatusIds.StatusCode status = 1; - repeated Ydb.Issue.IssueMessage issues = 2; -} - -message QueryMeta { - google.protobuf.Timestamp created_at = 1; - google.protobuf.Timestamp submitted_at = 2; - google.protobuf.Timestamp finished_at = 3; -} - -message Column { - string name = 1; - string type = 2; -} - -message ResultSetMeta { - int64 rows_count = 1 [(Ydb.value) = ">= 0"]; - bool truncated = 2; -} - -message CreateQueryRequest { - YandexQuery.QueryContent.QueryType type = 1; - string name = 2 [(Ydb.length).le = 1024]; - string text = 3 [(Ydb.length).le = 102400]; // The text of the query itself - string description = 4 [(Ydb.length).le = 10240]; // Description of the query, there can be any text -} - -message CreateQueryResult { - string id = 1 [(Ydb.length).le = 1024]; -} - -message GetQueryRequest { - string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}]; -} - -message GetQueryResult { - enum ComputeStatus { - COMPUTE_STATUS_UNSPECIFIED = 0; - RUNNING = 1; - COMPLETED = 2; - FAILED = 3; - } - - string id = 1; - YandexQuery.QueryContent.QueryType type = 2; - string name = 3 [(Ydb.length).le = 1024]; - string description = 4 [(Ydb.length).le = 10240]; // Description of the query, there can be any text - ComputeStatus status = 5; - string text = 6 [(Ydb.length).le = 102400]; // The text of the query itself - QueryMeta meta = 7; - repeated Ydb.Issue.IssueMessage issues = 8; - repeated ResultSetMeta result_sets = 9; -} - -message GetQueryStatusRequest { - string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}]; -} - -message GetQueryStatusResult { - GetQueryResult.ComputeStatus status = 1; -} - -message DeleteQueryRequest { - string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}]; -} - -message DeleteQueryResult { -} - -message StopQueryRequest { - string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}]; -} - -message StopQueryResult { -} - -message GetResultDataRequest { - string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}]; - int32 result_set_index = 2 [(Ydb.value) = ">= 0"]; - int64 offset = 3 [(Ydb.value) = ">= 0"]; - int64 limit = 4 [(Ydb.value) = "[1; 1000]"]; -} - -message RowData { - repeated string data = 1; -} - -message GetResultDataResult { - Ydb.ResultSet result_set = 1; -} diff --git a/ydb/core/viewer/ut/CMakeLists.darwin.txt b/ydb/core/viewer/ut/CMakeLists.darwin.txt index d5265c5742..ac32bbf09b 100644 --- a/ydb/core/viewer/ut/CMakeLists.darwin.txt +++ b/ydb/core/viewer/ut/CMakeLists.darwin.txt @@ -31,7 +31,6 @@ target_link_options(ydb-core-viewer-ut PRIVATE CoreFoundation ) target_sources(ydb-core-viewer-ut PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/http_router_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/core/viewer/viewer_ut.cpp ) add_test( diff --git a/ydb/core/viewer/ut/CMakeLists.linux.txt b/ydb/core/viewer/ut/CMakeLists.linux.txt index ce2706d468..dfed72ee92 100644 --- a/ydb/core/viewer/ut/CMakeLists.linux.txt +++ b/ydb/core/viewer/ut/CMakeLists.linux.txt @@ -35,7 +35,6 @@ target_link_options(ydb-core-viewer-ut PRIVATE -ldl ) target_sources(ydb-core-viewer-ut PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/viewer/http_router_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/core/viewer/viewer_ut.cpp ) add_test( diff --git a/ydb/core/viewer/viewer.cpp b/ydb/core/viewer/viewer.cpp index f8f8240e03..a59dae14f9 100644 --- a/ydb/core/viewer/viewer.cpp +++ b/ydb/core/viewer/viewer.cpp @@ -25,7 +25,6 @@ #include "json_bsgroupinfo.h" #include "json_nodeinfo.h" #include "json_vdiskinfo.h" -#include "http_router.h" namespace NKikimr { @@ -118,13 +117,6 @@ public: .UseAuth = true, .AllowedSIDs = allowedSIDs, }); - mon->RegisterActorPage({ - .Title = "FederatedQuery", - .RelPath = "fq", - .ActorSystem = ctx.ExecutorThread.ActorSystem, - .ActorId = ctx.SelfID, - .UseAuth = false, - }); auto whiteboardServiceId = NNodeWhiteboard::MakeNodeWhiteboardServiceId(ctx.SelfID.NodeId()); ctx.Send(whiteboardServiceId, new NNodeWhiteboard::TEvWhiteboard::TEvSystemStateAddEndpoint( "http-mon", Sprintf(":%d", KikimrRunConfig.AppConfig.GetMonitoringConfig().GetMonitoringPort()))); @@ -133,7 +125,6 @@ public: ViewerJsonHandlers.Init(); VDiskJsonHandlers.Init(); - FQJsonHandlers.Init(); TWhiteboardInfo<TEvWhiteboard::TEvNodeStateResponse>::InitMerger(); TWhiteboardInfo<TEvWhiteboard::TEvBSGroupStateResponse>::InitMerger(); @@ -178,8 +169,7 @@ public: private: TViewerJsonHandlers ViewerJsonHandlers; TVDiskJsonHandlers VDiskJsonHandlers; - TFQJsonHandlers FQJsonHandlers; - + THashMap<TString, TAutoPtr<TJsonHandlerBase>> JsonHandlers; const TKikimrRunConfig KikimrRunConfig; std::unordered_multimap<NKikimrViewer::EObjectType, TVirtualHandler> VirtualHandlersByParentType; std::unordered_map<NKikimrViewer::EObjectType, TContentHandler> ContentHandlers; @@ -215,22 +205,13 @@ private: json << "},"; json << "\"basePath\": \"/\","; json << "\"schemes\": [\"" << protocol << "\"],"; - json << R"___("securityDefinitions": { - "token": { - "type": "apiKey", - "in": "header", - "name": "authorization", - "description": "Authentication token" - } - }, - "consumes": ["application/json"], + json << R"___("consumes": ["application/json"], "produces": ["application/json"], "paths": {)___"; + ViewerJsonHandlers.PrintForSwagger(json); json << ','; VDiskJsonHandlers.PrintForSwagger(json); - json << ','; - FQJsonHandlers.PrintForSwagger(json); json << R"___(},"definitions":{)___"; json << R"___(}})___"; @@ -342,12 +323,7 @@ private: VDiskJsonHandlers.Handle(this, ev, ctx); return; } - if (filename.StartsWith("fq")) { - FQJsonHandlers.Handle(this, ev, ctx); - return; - } } - if (filename.StartsWith("counters/hosts")) { ctx.ExecutorThread.RegisterActor(new TCountersHostsList(this, ev)); return; diff --git a/ydb/core/viewer/viewer.h b/ydb/core/viewer/viewer.h index 8c107c2e37..5dc4d2dbda 100644 --- a/ydb/core/viewer/viewer.h +++ b/ydb/core/viewer/viewer.h @@ -145,10 +145,8 @@ static const char HTTPOKJSON[] = "HTTP/1.1 200 Ok\r\nAccess-Control-Allow-Origin static const char HTTPOKTEXT[] = "HTTP/1.1 200 Ok\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: Close\r\n\r\n"; static const char HTTPFORBIDDENJSON[] = "HTTP/1.1 403 Forbidden\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: application/json; charset=utf-8\r\nConnection: Close\r\n\r\n"; static const char HTTPGATEWAYTIMEOUT[] = "HTTP/1.1 504 Gateway Time-out\r\nConnection: Close\r\n\r\nGateway Time-out\r\n"; -static const char HTTPBADREQUEST[] = "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: Close\r\n\r\nBad Request\r\n"; -static const char HTTPBADREQUEST_HEADERS[] = "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: Close\r\n\r\n"; -static const char HTTPBADREQUESTJSON[] = "HTTP/1.1 400 Bad Request\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: application/json; charset=utf-8\r\nConnection: Close\r\n\r\n"; -static const char HTTPUNAUTHORIZEDTEXT[] = "HTTP/1.1 401 Unauthorized \r\nAccess-Control-Allow-Origin: *\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: Close\r\n\r\n"; +static const char HTTPBADREQUEST[] = "HTTP/1.1 400 Bad Request\r\nConnection: Close\r\n\r\nBad Request\r\n"; +static const char HTTPBADREQUEST_HEADERS[] = "HTTP/1.1 400 Bad Request\r\nConnection: Close\r\n\r\n"; template <typename ValueType, typename OutputIteratorType> void GenericSplitIds(TStringBuf source, char delim, OutputIteratorType it) { diff --git a/ydb/core/viewer/viewer_ut.cpp b/ydb/core/viewer/viewer_ut.cpp index e9c89d42fe..e85cb3c542 100644 --- a/ydb/core/viewer/viewer_ut.cpp +++ b/ydb/core/viewer/viewer_ut.cpp @@ -108,6 +108,5 @@ Y_UNIT_TEST_SUITE(Viewer) { Y_UNIT_TEST(Swagger) { TestSwagger<TViewerJsonHandlers>(); TestSwagger<TVDiskJsonHandlers>(); - TestSwagger<TFQJsonHandlers>(); } } |