diff --git a/ydb/core/viewer/browse.h b/ydb/core/viewer/browse.h index aa29d6c0f3a4..69569a35b61c 100644 --- a/ydb/core/viewer/browse.h +++ b/ydb/core/viewer/browse.h @@ -1,21 +1,16 @@ #pragma once -#include -#include -#include +#include "browse_events.h" +#include "viewer.h" +#include "wb_aggregate.h" #include #include #include -#include +#include #include #include -#include -#include -#include "browse_events.h" -#include "viewer.h" -#include "wb_aggregate.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -646,4 +641,3 @@ class TBrowseTabletsCommon : public TActorBootstrapped { }; } -} diff --git a/ydb/core/viewer/browse_db.h b/ydb/core/viewer/browse_db.h index 86c4aa264127..f794cb3bbab4 100644 --- a/ydb/core/viewer/browse_db.h +++ b/ydb/core/viewer/browse_db.h @@ -1,20 +1,12 @@ #pragma once -#include -#include +#include "browse.h" +#include "viewer.h" +#include "wb_aggregate.h" #include -#include -#include #include #include -#include -#include -#include -#include "viewer.h" -#include "browse.h" -#include "wb_aggregate.h" -namespace NKikimr { -namespace NViewerDB { +namespace NKikimr::NViewerDB { using namespace NViewer; using namespace NActors; @@ -200,4 +192,3 @@ class TBrowseTable : public TBrowseTabletsCommon { }; } -} diff --git a/ydb/core/viewer/browse_events.h b/ydb/core/viewer/browse_events.h index ee0bbbb37572..92cc2b206bec 100644 --- a/ydb/core/viewer/browse_events.h +++ b/ydb/core/viewer/browse_events.h @@ -1,13 +1,12 @@ #pragma once -#include -#include -#include - #include +#include +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { namespace NViewerEvents { enum EEv { @@ -76,5 +75,4 @@ namespace NViewerEvents { }; } // namespace NViewerEvents -} // namespace NViewer -} // namespace NKikimr +} diff --git a/ydb/core/viewer/browse_pq.h b/ydb/core/viewer/browse_pq.h index 1f2b5d950b16..190b72ad953b 100644 --- a/ydb/core/viewer/browse_pq.h +++ b/ydb/core/viewer/browse_pq.h @@ -1,20 +1,12 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "browse.h" +#include "viewer.h" #include "wb_aggregate.h" +#include +#include +#include -namespace NKikimr { -namespace NViewerPQ { +namespace NKikimr::NViewerPQ { using namespace NViewer; using namespace NActors; @@ -419,4 +411,3 @@ class TBrowseTopic : public TBrowseCommon { }; } -} diff --git a/ydb/core/viewer/check_access.h b/ydb/core/viewer/check_access.h deleted file mode 100644 index bf48d57f600c..000000000000 --- a/ydb/core/viewer/check_access.h +++ /dev/null @@ -1,226 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "json_pipe_req.h" - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; -using NSchemeShard::TEvSchemeShard; -using TNavigate = NSchemeCache::TSchemeCacheNavigate; - -class TCheckAccess : public TViewerPipeClient { - using TThis = TCheckAccess; - using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; - TAutoPtr CacheResult; - TVector Permissions; - -public: - TCheckAccess(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) - {} - - void Bootstrap() override { - const auto& params(Event->Get()->Request.GetParams()); - ui32 timeout = FromStringWithDefault(params.Get("timeout"), 10000); - TString database; - if (params.Has("database")) { - database = params.Get("database"); - } else { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'database' is required")); - } - if (database && database != AppData()->TenantName) { - BLOG_TRACE("Requesting StateStorageEndpointsLookup for " << database); - RequestStateStorageEndpointsLookup(database); // to find some dynamic node and redirect query there - } else { - if (params.Has("permissions")) { - Split(params.Get("permissions"), ",", Permissions); - } else { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'permissions' is required")); - } - if (params.Has("path")) { - RequestSchemeCacheNavigate(params.Get("path")); - } else { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'path' is required")); - } - } - Become(&TThis::StateRequestedNavigate, TDuration::MilliSeconds(timeout), new TEvents::TEvWakeup()); - } - - void Handle(TEvStateStorage::TEvBoardInfo::TPtr& ev) { - BLOG_TRACE("Received TEvBoardInfo"); - ReplyAndPassAway(Viewer->MakeForward(Event->Get(), GetNodesFromBoardReply(ev))); - } - - STATEFN(StateRequestedNavigate) { - switch (ev->GetTypeRewrite()) { - hFunc(TEvStateStorage::TEvBoardInfo, Handle); - hFunc(TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle); - cFunc(TEvents::TSystem::Wakeup, HandleTimeout); - } - } - - void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev) { - CacheResult = ev->Release(); - RequestDone(); - } - - ui32 GetAccessType(const TString& permission) { - TACLAttrs attrs(0); - try { - attrs = ConvertYdbPermissionNameToACLAttrs(permission); - } - catch (const std::exception&) { - } - return attrs.AccessMask; - } - - bool CheckAccessPermission(const NACLib::TSecurityObject* object, const NACLib::TUserToken* token, const TString& permission) { - const auto& kikimrRunConfig = Viewer->GetKikimrRunConfig(); - const auto& securityConfig = kikimrRunConfig.AppConfig.GetDomainsConfig().GetSecurityConfig(); - if (!securityConfig.GetEnforceUserTokenRequirement()) { - if (!securityConfig.GetEnforceUserTokenCheckRequirement() || token == nullptr) { - return true; - } - } - if (token == nullptr) { - return false; - } - if (object == nullptr) { - return false; - } - ui32 access = GetAccessType(permission); - if (access == 0) { - return false; - } - return object->CheckAccess(access, *token); - } - - void ReplyAndPassAway() override { - std::unique_ptr token; - if (Event->Get()->UserToken) { - token = std::make_unique(Event->Get()->UserToken); - } - if (CacheResult == nullptr) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "no SchemeCache response")); - } - if (CacheResult->Request == nullptr) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "wrong SchemeCache response")); - } - if (CacheResult->Request.Get()->ResultSet.empty()) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "SchemeCache response is empty")); - } - if (CacheResult->Request.Get()->ErrorCount != 0) { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", TStringBuilder() << "SchemeCache response error " << static_cast(CacheResult->Request.Get()->ResultSet.front().Status))); - } - - - auto object = CacheResult->Request.Get()->ResultSet.front().SecurityObject; - - NJson::TJsonValue json(NJson::JSON_MAP); - - for (const TString& permission : Permissions) { - json[permission] = CheckAccessPermission(object.Get(), token.get(), permission); - } - - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false))); - } - - void HandleTimeout() { - ReplyAndPassAway(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get(), "text/plain", "Timeout receiving SchemeCache response")); - } - - void ReplyAndPassAway(TString data) { - Send(Event->Sender, new NMon::TEvHttpInfoRes(data, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } -}; - -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - viewer - summary: Check access - description: Check access to the specified path - parameters: - - name: database - in: query - description: database name - type: string - required: true - - name: path - in: query - description: path to check access - type: string - required: true - - name: permissions - in: query - description: permissions to check - required: true - type: array - items: - type: string - enum: - - ydb.database.connect - - ydb.tables.modify - - ydb.tables.read - - ydb.generic.list - - ydb.generic.read - - ydb.generic.write - - ydb.generic.use_legacy - - ydb.generic.use - - ydb.generic.manage - - ydb.generic.full_legacy - - ydb.generic.full - - ydb.database.create - - ydb.database.drop - - ydb.access.grant - - ydb.granular.select_row - - ydb.granular.update_row - - ydb.granular.erase_row - - ydb.granular.read_attributes - - ydb.granular.write_attributes - - ydb.granular.create_directory - - ydb.granular.create_table - - ydb.granular.create_queue - - ydb.granular.remove_schema - - ydb.granular.describe_schema - - ydb.granular.alter_schema - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - - return node; -} - -} -} - diff --git a/ydb/core/viewer/counters_hosts.h b/ydb/core/viewer/counters_hosts.h index 2232f16b00ba..b93a7cb0b485 100644 --- a/ydb/core/viewer/counters_hosts.h +++ b/ydb/core/viewer/counters_hosts.h @@ -1,16 +1,12 @@ #pragma once -#include -#include -#include -#include +#include "viewer.h" #include #include -#include #include -#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; @@ -173,4 +169,3 @@ class TCountersHostsList : public TActorBootstrapped { }; } -} diff --git a/ydb/core/viewer/healthcheck_record.h b/ydb/core/viewer/healthcheck_record.h index 39c94e288773..5b55d2bd1322 100644 --- a/ydb/core/viewer/healthcheck_record.h +++ b/ydb/core/viewer/healthcheck_record.h @@ -1,9 +1,8 @@ #pragma once +#include +#include namespace NKikimr::NViewer { - -using namespace NActors; -using namespace NMonitoring; struct TMetricRecord { TString Database; diff --git a/ydb/core/viewer/json_blobindexstat.h b/ydb/core/viewer/json_blobindexstat.h deleted file mode 100644 index 2cdf56b4bc4f..000000000000 --- a/ydb/core/viewer/json_blobindexstat.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include "json_vdisk_req.h" - -namespace NKikimr { -namespace NViewer { - -using TJsonBlobIndexStat = TJsonVDiskRequest; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "\"Get logoblob index stat from VDisk\""; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "\"Get logoblob index stat from VDisk\""; - } -}; - -} -} diff --git a/ydb/core/viewer/json_bscontrollerinfo.h b/ydb/core/viewer/json_bscontrollerinfo.h deleted file mode 100644 index cf1833742f57..000000000000 --- a/ydb/core/viewer/json_bscontrollerinfo.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include "viewer.h" -#include "json_pipe_req.h" -#include - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; - -class TJsonBSControllerInfo : public TViewerPipeClient { - using TThis = TJsonBSControllerInfo; - using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; - TAutoPtr ControllerInfo; - TJsonSettings JsonSettings; - ui32 Timeout = 0; - -public: - TJsonBSControllerInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) - {} - - void Bootstrap() override { - const auto& params(Event->Get()->Request.GetParams()); - JsonSettings.EnumAsNumbers = !FromStringWithDefault(params.Get("enums"), false); - JsonSettings.UI64AsString = !FromStringWithDefault(params.Get("ui64"), false); - Timeout = FromStringWithDefault(params.Get("timeout"), 10000); - InitConfig(params); - RequestBSControllerInfo(); - const auto ctx = TActivationContext::ActorContextFor(SelfId()); - Become(&TThis::StateRequestedInfo, ctx, TDuration::MilliSeconds(Timeout), new TEvents::TEvWakeup()); - } - - STATEFN(StateRequestedInfo) { - switch (ev->GetTypeRewrite()) { - hFunc(TEvBlobStorage::TEvResponseControllerInfo, Handle); - hFunc(TEvTabletPipe::TEvClientConnected, TBase::Handle); - cFunc(TEvents::TSystem::Wakeup, HandleTimeout); - } - } - - void Handle(TEvBlobStorage::TEvResponseControllerInfo::TPtr& ev) { - ControllerInfo = ev->Release(); - RequestDone(); - } - - void ReplyAndPassAway() override { - TStringStream json; - if (ControllerInfo != nullptr) { - TProtoToJson::ProtoToJson(json, ControllerInfo->Record); - } else { - json << "null"; - } - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), json.Str()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } - - void HandleTimeout() { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Node(R"___( - - name: controller_id - in: query - description: storage controller identifier (tablet id) - required: true - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Storage controller information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about storage controller"; - } -}; - -} -} diff --git a/ydb/core/viewer/json_describe_consumer.h b/ydb/core/viewer/json_describe_consumer.h deleted file mode 100644 index 693f5cc5e065..000000000000 --- a/ydb/core/viewer/json_describe_consumer.h +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once -#include -#include -#include "json_local_rpc.h" - -namespace NKikimr { -namespace NViewer { - -using TDescribeConsumerRpc = TJsonLocalRpc; - -class TJsonDescribeConsumer : public TDescribeConsumerRpc { -public: - using TBase = TDescribeConsumerRpc; - - TJsonDescribeConsumer(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) - : TBase(viewer, ev) - {} - - void Bootstrap() override { - if (Event->Get()->Request.GetMethod() != HTTP_METHOD_GET) { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "Only GET method is allowed")); - } - const auto& params(Event->Get()->Request.GetParams()); - if (params.Has("database")) { - Database = params.Get("database"); - } else if (params.Has("database_path")) { - Database = params.Get("database_path"); - } else { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'database' is required")); - } - - if (params.Has("consumer")) { - Request.set_consumer(params.Get("consumer")); - } else { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'consumer' is required")); - } - - if (params.Has("include_stats")) { - Request.set_include_stats(FromStringWithDefault(params.Get("include_stats"), false)); - } - - TBase::Bootstrap(); - } -}; - -template<> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - viewer - summary: Topic schema detailed information - description: Returns detailed information about topic - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: consumer - in: query - description: consumer name - required: true - type: string - - name: include_stats - in: query - description: include stat flag - required: false - type: bool - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} - -} -} diff --git a/ydb/core/viewer/json_handlers.cpp b/ydb/core/viewer/json_handlers.cpp new file mode 100644 index 000000000000..7f7b070dd37b --- /dev/null +++ b/ydb/core/viewer/json_handlers.cpp @@ -0,0 +1,47 @@ +#include "json_handlers.h" +#include + +namespace NKikimr::NViewer { + +TSimpleYamlBuilder::TSimpleYamlBuilder(TInitializer initializer) { + Method = Root[TString(initializer.Method)]; + if (initializer.Url) { + Method["tags"].push_back(TString(initializer.Url.After('/').Before('/'))); + } + if (initializer.Tag) { + Method["tags"].push_back(TString(initializer.Tag)); + } + if (initializer.Summary) { + Method["summary"] = TString(initializer.Summary); + } + if (initializer.Description) { + Method["description"] = TString(initializer.Description); + } +} + +void TSimpleYamlBuilder::SetParameters(YAML::Node parameters) { + Method["parameters"] = parameters; +} + +void TSimpleYamlBuilder::AddParameter(TParameter parameter) { + YAML::Node param; + param["in"] = "query"; + param["name"] = TString(parameter.Name); + if (parameter.Description) { + param["description"] = TString(parameter.Description); + } + if (parameter.Type) { + param["type"] = TString(parameter.Type); + } + if (parameter.Default) { + param["default"] = TString(parameter.Default); + } + param["required"] = parameter.Required; + Method["parameters"].push_back(param); +} + +void TSimpleYamlBuilder::SetResponseSchema(YAML::Node schema) { + Method["responses"]["200"]["content"]["application/json"]["schema"] = schema; +} + +} diff --git a/ydb/core/viewer/json_handlers.h b/ydb/core/viewer/json_handlers.h index 0a994546740d..81dfe70eb016 100644 --- a/ydb/core/viewer/json_handlers.h +++ b/ydb/core/viewer/json_handlers.h @@ -1,7 +1,7 @@ #pragma once - #include "viewer.h" -#include +#include +#include namespace NKikimr::NViewer { @@ -9,43 +9,24 @@ class TJsonHandlerBase { public: virtual ~TJsonHandlerBase() = default; virtual IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) = 0; - virtual YAML::Node GetResponseJsonSchema() = 0; - virtual TString GetRequestSummary() = 0; - virtual TString GetRequestDescription() = 0; - virtual YAML::Node GetRequestParameters() = 0; virtual YAML::Node GetRequestSwagger() = 0; }; template class TJsonHandler : public TJsonHandlerBase { public: - IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override { - return new ActorRequestType(viewer, event); - } - - YAML::Node GetResponseJsonSchema() override { - static YAML::Node jsonSchema = TJsonRequestSchema::GetSchema(); - return jsonSchema; - } + YAML::Node Swagger; - TString GetRequestSummary() override { - static TString summary = TJsonRequestSummary::GetSummary(); - return summary; - } + TJsonHandler(YAML::Node swagger) + : Swagger(swagger) + {} - TString GetRequestDescription() override { - static TString description = TJsonRequestDescription::GetDescription(); - return description; - } - - YAML::Node GetRequestParameters() override { - static YAML::Node parameters = TJsonRequestParameters::GetParameters(); - return parameters; + IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override { + return new ActorRequestType(viewer, event); } YAML::Node GetRequestSwagger() override { - static YAML::Node swagger = TJsonRequestSwagger::GetSwagger(); - return swagger; + return Swagger; } }; @@ -69,4 +50,35 @@ struct TJsonHandlers { } }; +class TSimpleYamlBuilder { +public: + struct TInitializer { + TStringBuf Method; + TStringBuf Tag; + TStringBuf Url; + TStringBuf Summary; + TStringBuf Description; + }; + + struct TParameter { + TStringBuf Name; + TStringBuf Description; + TStringBuf Type; + TStringBuf Default; + bool Required = false; + }; + + YAML::Node Root; + YAML::Node Method; + + TSimpleYamlBuilder(TInitializer initializer); + void SetParameters(YAML::Node parameters); + void AddParameter(TParameter parameter); + void SetResponseSchema(YAML::Node schema); + + operator YAML::Node() { + return Root; + } +}; + } // namespace NKikimr::NViewer diff --git a/ydb/core/viewer/json_handlers_browse.cpp b/ydb/core/viewer/json_handlers_browse.cpp new file mode 100644 index 000000000000..c9ec41656d8f --- /dev/null +++ b/ydb/core/viewer/json_handlers_browse.cpp @@ -0,0 +1,37 @@ +#include "json_handlers.h" +#include "browse.h" +#include "browse_db.h" +#include "browse_pq.h" +#include "viewer_browse.h" +#include "viewer_content.h" +#include "viewer_metainfo.h" + +namespace NKikimr::NViewer { + +void SetupDBVirtualHandlers(IViewer* viewer) { + viewer->RegisterVirtualHandler( + NKikimrViewer::EObjectType::Table, + [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { + return new NViewerDB::TBrowseTable(owner, browseContext); + }); +} + +void InitViewerMetaInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/metainfo", new TJsonHandler(TJsonMetaInfo::GetSwagger())); +} + +void InitViewerBrowseJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/browse", new TJsonHandler(TJsonBrowse::GetSwagger())); +} + +void InitViewerContentJsonHandler(TJsonHandlers &jsonHandlers) { + jsonHandlers.AddHandler("/viewer/content", new TJsonHandler(TJsonContent::GetSwagger())); +} + +void InitViewerBrowseJsonHandlers(TJsonHandlers& jsonHandlers) { + InitViewerMetaInfoJsonHandler(jsonHandlers); + InitViewerBrowseJsonHandler(jsonHandlers); + InitViewerContentJsonHandler(jsonHandlers); +} + +} diff --git a/ydb/core/viewer/json_handlers_operation.cpp b/ydb/core/viewer/json_handlers_operation.cpp index 4e9c90da6d79..7375d177983b 100644 --- a/ydb/core/viewer/json_handlers_operation.cpp +++ b/ydb/core/viewer/json_handlers_operation.cpp @@ -1,17 +1,32 @@ #include "json_handlers.h" - -#include "operation_get.h" -#include "operation_list.h" #include "operation_cancel.h" #include "operation_forget.h" +#include "operation_get.h" +#include "operation_list.h" namespace NKikimr::NViewer { -void InitOperationJsonHandlers(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/operation/get", new TJsonHandler); - jsonHandlers.AddHandler("/operation/list", new TJsonHandler); - jsonHandlers.AddHandler("/operation/cancel", new TJsonHandler); - jsonHandlers.AddHandler("/operation/forget", new TJsonHandler); +void InitOperationGetJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/operation/get", new TJsonHandler(TOperationGet::GetSwagger())); +} + +void InitOperationListJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/operation/list", new TJsonHandler(TOperationList::GetSwagger())); +} + +void InitOperationCancelJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/operation/cancel", new TJsonHandler(TOperationCancel::GetSwagger())); } +void InitOperationForgetJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/operation/forget", new TJsonHandler(TOperationForget::GetSwagger())); } + +void InitOperationJsonHandlers(TJsonHandlers& jsonHandlers) { + InitOperationGetJsonHandler(jsonHandlers); + InitOperationListJsonHandler(jsonHandlers); + InitOperationCancelJsonHandler(jsonHandlers); + InitOperationForgetJsonHandler(jsonHandlers); +} + +} // namespace NKikimr::NViewer diff --git a/ydb/core/viewer/json_handlers_pdisk.cpp b/ydb/core/viewer/json_handlers_pdisk.cpp index ef99307e25be..55845fc83cad 100644 --- a/ydb/core/viewer/json_handlers_pdisk.cpp +++ b/ydb/core/viewer/json_handlers_pdisk.cpp @@ -1,19 +1,26 @@ -#include -#include - #include "json_handlers.h" - -#include "json_pdisk_restart.h" #include "pdisk_info.h" +#include "pdisk_restart.h" #include "pdisk_status.h" - namespace NKikimr::NViewer { +void InitPDiskInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/pdisk/info", new TJsonHandler(TPDiskInfo::GetSwagger())); +} + +void InitPDiskRestartJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/pdisk/restart", new TJsonHandler(TJsonPDiskRestart::GetSwagger())); +} + +void InitPDiskStatusJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/pdisk/status", new TJsonHandler(TPDiskStatus::GetSwagger())); +} + void InitPDiskJsonHandlers(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/pdisk/info", new TJsonHandler); - jsonHandlers.AddHandler("/pdisk/restart", new TJsonHandler); - jsonHandlers.AddHandler("/pdisk/status", new TJsonHandler); + InitPDiskInfoJsonHandler(jsonHandlers); + InitPDiskRestartJsonHandler(jsonHandlers); + InitPDiskStatusJsonHandler(jsonHandlers); } } diff --git a/ydb/core/viewer/json_handlers_pq.cpp b/ydb/core/viewer/json_handlers_pq.cpp new file mode 100644 index 000000000000..d3503b95b7f9 --- /dev/null +++ b/ydb/core/viewer/json_handlers_pq.cpp @@ -0,0 +1,29 @@ +#include "viewer.h" +#include "browse_pq.h" + +namespace NKikimr::NViewer { + +void SetupPQVirtualHandlers(IViewer* viewer) { + viewer->RegisterVirtualHandler( + NKikimrViewer::EObjectType::Root, + [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { + return new NViewerPQ::TBrowseRoot(owner, browseContext); + }); + viewer->RegisterVirtualHandler( + NKikimrViewer::EObjectType::Consumers, + [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { + return new NViewerPQ::TBrowseConsumers(owner, browseContext); + }); + viewer->RegisterVirtualHandler( + NKikimrViewer::EObjectType::Consumer, + [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { + return new NViewerPQ::TBrowseConsumer(owner, browseContext); + }); + viewer->RegisterVirtualHandler( + NKikimrViewer::EObjectType::Topic, + [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { + return new NViewerPQ::TBrowseTopic(owner, browseContext); + }); +} + +} diff --git a/ydb/core/viewer/json_handlers_scheme.cpp b/ydb/core/viewer/json_handlers_scheme.cpp index c5dc07f28b28..2f1529393c6d 100644 --- a/ydb/core/viewer/json_handlers_scheme.cpp +++ b/ydb/core/viewer/json_handlers_scheme.cpp @@ -1,11 +1,14 @@ #include "json_handlers.h" - #include "scheme_directory.h" namespace NKikimr::NViewer { +void InitSchemeDirectoryHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/scheme/directory", new TJsonSchemeDirectoryHandler()); +} + void InitSchemeJsonHandlers(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/scheme/directory", new TJsonSchemeDirectoryHandler()); + InitSchemeDirectoryHandler(jsonHandlers); } } diff --git a/ydb/core/viewer/json_handlers_storage.cpp b/ydb/core/viewer/json_handlers_storage.cpp index 352f8c3d7c4a..bcd470f1de86 100644 --- a/ydb/core/viewer/json_handlers_storage.cpp +++ b/ydb/core/viewer/json_handlers_storage.cpp @@ -1,9 +1,11 @@ - #include "json_handlers.h" +#include "storage_groups.h" namespace NKikimr::NViewer { -void InitStorageGroupsJsonHandler(TJsonHandlers& jsonHandlers); +void InitStorageGroupsJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/storage/groups", new TJsonHandler(TStorageGroups::GetSwagger())); +} void InitStorageJsonHandlers(TJsonHandlers& jsonHandlers) { InitStorageGroupsJsonHandler(jsonHandlers); diff --git a/ydb/core/viewer/json_handlers_vdisk.cpp b/ydb/core/viewer/json_handlers_vdisk.cpp index 49c869692f08..633bf9c80566 100644 --- a/ydb/core/viewer/json_handlers_vdisk.cpp +++ b/ydb/core/viewer/json_handlers_vdisk.cpp @@ -1,20 +1,56 @@ -#include -#include - #include "json_handlers.h" - -#include "json_vdiskstat.h" -#include "json_getblob.h" -#include "json_blobindexstat.h" -#include "json_vdisk_evict.h" +#include "vdisk_vdiskstat.h" +#include "vdisk_blobindexstat.h" +#include "vdisk_getblob.h" +#include "vdisk_evict.h" namespace NKikimr::NViewer { +void InitVDiskStatJsonHandler(TJsonHandlers& handlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "vdisk", + .Summary = "VDisk statistic", + .Description = "VDisk statistic", + }); + yaml.SetParameters(TJsonVDiskStat::GetParameters()); + yaml.SetResponseSchema(TJsonVDiskStat::GetSchema()); + handlers.AddHandler("/vdisk/vdiskstat", new TJsonHandler(yaml)); +} + +void InitVDiskGetBlobJsonHandler(TJsonHandlers& handlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "vdisk", + .Summary = "Get blob from VDisk", + .Description = "Get blob from VDisk", + }); + yaml.SetParameters(TJsonGetBlob::GetParameters()); + yaml.SetResponseSchema(TJsonGetBlob::GetSchema()); + handlers.AddHandler("/vdisk/getblob", new TJsonHandler(yaml)); +} + +void InitVDiskBlobIndexStatJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "vdisk", + .Summary = "Get logoblob index stat from VDisk", + .Description = "Get logoblob index stat from VDisk", + }); + yaml.SetParameters(TJsonBlobIndexStat::GetParameters()); + yaml.SetResponseSchema(TJsonBlobIndexStat::GetSchema()); + jsonHandlers.AddHandler("/vdisk/blobindexstat", new TJsonHandler(yaml)); +} + +void InitVDiskEvictJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/vdisk/evict", new TJsonHandler(TJsonVDiskEvict::GetSwagger())); +} + void InitVDiskJsonHandlers(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/vdisk/vdiskstat", new TJsonHandler); - jsonHandlers.AddHandler("/vdisk/getblob", new TJsonHandler); - jsonHandlers.AddHandler("/vdisk/blobindexstat", new TJsonHandler); - jsonHandlers.AddHandler("/vdisk/evict", new TJsonHandler); + InitVDiskStatJsonHandler(jsonHandlers); + InitVDiskGetBlobJsonHandler(jsonHandlers); + InitVDiskBlobIndexStatJsonHandler(jsonHandlers); + InitVDiskEvictJsonHandler(jsonHandlers); } } diff --git a/ydb/core/viewer/json_handlers_viewer.cpp b/ydb/core/viewer/json_handlers_viewer.cpp index e037c4f4ea84..fcbf52aa0965 100644 --- a/ydb/core/viewer/json_handlers_viewer.cpp +++ b/ydb/core/viewer/json_handlers_viewer.cpp @@ -1,92 +1,308 @@ -#include - #include "json_handlers.h" - -#include "json_nodelist.h" -#include "json_nodeinfo.h" -#include "json_vdiskinfo.h" -#include "json_pdiskinfo.h" -#include "json_describe.h" -#include "json_describe_topic.h" -#include "json_describe_consumer.h" -#include "json_hotkeys.h" -#include "json_sysinfo.h" -#include "json_tabletinfo.h" -#include "json_hiveinfo.h" -#include "json_bsgroupinfo.h" -#include "json_bscontrollerinfo.h" -#include "json_config.h" -#include "json_counters.h" -#include "json_topicinfo.h" -#include "json_pqconsumerinfo.h" -#include "json_tabletcounters.h" -#include "json_storage.h" -#include "json_storage_usage.h" -#include "json_metainfo.h" -#include "json_browse.h" -#include "json_cluster.h" -#include "json_content.h" -#include "json_labeledcounters.h" -#include "json_tenants.h" -#include "json_hivestats.h" -#include "json_tenantinfo.h" -#include "json_whoami.h" -#include "json_query.h" -#include "json_netinfo.h" -#include "json_compute.h" -#include "json_healthcheck.h" -#include "json_nodes.h" -#include "json_acl.h" -#include "json_graph.h" -#include "json_render.h" -#include "json_autocomplete.h" -#include "check_access.h" +#include "viewer_acl.h" +#include "viewer_autocomplete.h" +#include "viewer_bscontrollerinfo.h" +#include "viewer_capabilities.h" +#include "viewer_check_access.h" +#include "viewer_cluster.h" +#include "viewer_compute.h" +#include "viewer_config.h" +#include "viewer_counters.h" +#include "viewer_describe_consumer.h" +#include "viewer_describe.h" +#include "viewer_describe_topic.h" +#include "viewer_graph.h" +#include "viewer_healthcheck.h" +#include "viewer_hiveinfo.h" +#include "viewer_hivestats.h" +#include "viewer_hotkeys.h" +#include "viewer_labeled_counters.h" +#include "viewer_netinfo.h" +#include "viewer_nodelist.h" +#include "viewer_nodes.h" +#include "viewer_pqconsumerinfo.h" +#include "viewer_query.h" +#include "viewer_render.h" +#include "viewer_storage.h" +#include "viewer_storage_usage.h" +#include "viewer_tabletcounters.h" +#include "viewer_tenantinfo.h" +#include "viewer_tenants.h" +#include "viewer_topicinfo.h" +#include "viewer_whoami.h" namespace NKikimr::NViewer { -void InitViewerCapabilitiesJsonHandler(TJsonHandlers& jsonHandlers); +TBSGroupState GetBSGroupOverallStateWithoutLatency( + const NKikimrWhiteboard::TBSGroupStateInfo& info, + const TMap& vDisksIndex, + const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { + + TBSGroupState groupState; + groupState.Overall = NKikimrViewer::EFlag::Grey; + + const auto& vDiskIds = info.GetVDiskIds(); + std::unordered_map failedRings; + std::unordered_map failedDomains; + TVector vDiskFlags; + vDiskFlags.reserve(vDiskIds.size()); + for (auto iv = vDiskIds.begin(); iv != vDiskIds.end(); ++iv) { + const NKikimrBlobStorage::TVDiskID& vDiskId = *iv; + NKikimrViewer::EFlag flag = NKikimrViewer::EFlag::Grey; + auto ie = vDisksIndex.find(vDiskId); + if (ie != vDisksIndex.end()) { + auto pDiskId = std::make_pair(ie->second.GetNodeId(), ie->second.GetPDiskId()); + auto ip = pDisksIndex.find(pDiskId); + if (ip != pDisksIndex.end()) { + const NKikimrWhiteboard::TPDiskStateInfo& pDiskInfo(ip->second); + flag = Max(flag, GetPDiskOverallFlag(pDiskInfo)); + } else { + flag = NKikimrViewer::EFlag::Red; + } + const NKikimrWhiteboard::TVDiskStateInfo& vDiskInfo(ie->second); + flag = Max(flag, GetVDiskOverallFlag(vDiskInfo)); + if (vDiskInfo.GetDiskSpace() > NKikimrWhiteboard::EFlag::Green) { + groupState.SpaceProblems++; + } + } else { + flag = NKikimrViewer::EFlag::Red; + } + vDiskFlags.push_back(flag); + if (flag == NKikimrViewer::EFlag::Red || flag == NKikimrViewer::EFlag::Blue) { + groupState.MissingDisks++; + ++failedRings[vDiskId.GetRing()]; + ++failedDomains[vDiskId.GetDomain()]; + } + groupState.Overall = Max(groupState.Overall, flag); + } + + groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); // without failed rings we only allow to raise group status up to Blue/Yellow + TString erasure = info.GetErasureSpecies(); + if (erasure == TErasureType::ErasureSpeciesName(TErasureType::ErasureNone)) { + if (!failedDomains.empty()) { + groupState.Overall = NKikimrViewer::EFlag::Red; + } + } else if (erasure == TErasureType::ErasureSpeciesName(TErasureType::ErasureMirror3dc)) { + if (failedRings.size() > 2) { + groupState.Overall = NKikimrViewer::EFlag::Red; + } else if (failedRings.size() == 2) { // TODO: check for 1 ring - 1 domain rule + groupState.Overall = NKikimrViewer::EFlag::Orange; + } else if (failedRings.size() > 0) { + groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); + } + } else if (erasure == TErasureType::ErasureSpeciesName(TErasureType::Erasure4Plus2Block)) { + if (failedDomains.size() > 2) { + groupState.Overall = NKikimrViewer::EFlag::Red; + } else if (failedDomains.size() > 1) { + groupState.Overall = NKikimrViewer::EFlag::Orange; + } else if (failedDomains.size() > 0) { + groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); + } + } + return groupState; +} + +NKikimrViewer::EFlag GetBSGroupOverallFlagWithoutLatency( + const NKikimrWhiteboard::TBSGroupStateInfo& info, + const TMap& vDisksIndex, + const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { + return GetBSGroupOverallStateWithoutLatency(info, vDisksIndex, pDisksIndex).Overall; +} + +TBSGroupState GetBSGroupOverallState( + const NKikimrWhiteboard::TBSGroupStateInfo& info, + const TMap& vDisksIndex, + const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { + TBSGroupState state = GetBSGroupOverallStateWithoutLatency(info, vDisksIndex, pDisksIndex); + if (info.HasLatency()) { + state.Overall = Max(state.Overall, Min(NKikimrViewer::EFlag::Yellow, GetViewerFlag(info.GetLatency()))); + } + return state; +} + +NKikimrViewer::EFlag GetBSGroupOverallFlag( + const NKikimrWhiteboard::TBSGroupStateInfo& info, + const TMap& vDisksIndex, + const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { + return GetBSGroupOverallState(info, vDisksIndex, pDisksIndex).Overall; +} + +void InitViewerCapabilitiesJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Viewer capabilities", + .Description = "Viewer capabilities", + }); + jsonHandlers.AddHandler("/viewer/capabilities", new TJsonHandler(yaml)); +} + +void InitViewerNodelistJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/nodelist", new TJsonHandler(TJsonNodeList::GetSwagger())); +} + +void InitViewerNodeInfoJsonHandler(TJsonHandlers& jsonHandlers); +void InitViewerSysInfoJsonHandler(TJsonHandlers& jsonHandlers); +void InitViewerVDiskInfoJsonHandler(TJsonHandlers& jsonHandlers); +void InitViewerPDiskInfoJsonHandler(TJsonHandlers& jsonHandlers); +void InitViewerTabletInfoJsonHandler(TJsonHandlers& jsonHandlers); + +void InitViewerDescribeJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/describe", new TJsonHandler(TJsonDescribe::GetSwagger())); +} + +void InitViewerDescribeTopicJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/describe_topic", new TJsonHandler(TJsonDescribeTopic::GetSwagger())); +} + +void InitViewerDescribeConsumerJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/describe_consumer", new TJsonHandler(TJsonDescribeConsumer::GetSwagger())); +} + +void InitViewerHotkeysJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/hotkeys", new TJsonHandler(TJsonHotkeys::GetSwagger())); +} + +void InitViewerHiveInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/hiveinfo", new TJsonHandler(TJsonHiveInfo::GetSwagger())); +} + +void InitViewerBSGroupInfoJsonHandler(TJsonHandlers& jsonHandlers); + +void InitViewerBSControllerInfoJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/bscontrollerinfo", new TJsonHandler(TJsonBSControllerInfo::GetSwagger())); +} + +void InitViewerConfigJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/config", new TJsonHandler(TJsonConfig::GetSwagger())); +} + +void InitViewerCountersJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/counters", new TJsonHandler(TJsonCounters::GetSwagger())); +} + +void InitViewerTopicInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/topicinfo", new TJsonHandler(TJsonTopicInfo::GetSwagger())); +} + +void InitViewerPQConsumerInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/pqconsumerinfo", new TJsonHandler(TJsonPQConsumerInfo::GetSwagger())); +} + +void InitViewerTabletCountersJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/tabletcounters", new TJsonHandler(TJsonTabletCounters::GetSwagger())); +} + +void InitViewerStorageJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/storage", new TJsonHandler(TJsonStorage::GetSwagger())); +} + +void InitViewerStorageUsageJsonHandler(TJsonHandlers &handlers) { + handlers.AddHandler("/viewer/storage_usage", new TJsonHandler(TJsonStorageUsage::GetSwagger())); +} + +void InitViewerClusterJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/cluster", new TJsonHandler(TJsonCluster::GetSwagger())); +} + +void InitViewerLabeledCountersJsonHandler(TJsonHandlers &handlers) { + handlers.AddHandler("/viewer/labeledcounters", new TJsonHandler(TJsonLabeledCounters::GetSwagger())); +} + +void InitViewerTenantsJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/tenants", new TJsonHandler(TJsonTenants::GetSwagger())); +} + +void InitViewerHiveStatsJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/hivestats", new TJsonHandler(TJsonHiveStats::GetSwagger())); +} + +void InitViewerTenantInfoJsonHandler(TJsonHandlers &handlers) { + handlers.AddHandler("/viewer/tenantinfo", new TJsonHandler(TJsonTenantInfo::GetSwagger())); +} + +void InitViewerWhoAmIJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/whoami", new TJsonHandler(TJsonWhoAmI::GetSwagger())); +} + +void InitViewerQueryJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/query", new TJsonHandler(TJsonQuery::GetSwagger())); +} + +void InitViewerNetInfoJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/netinfo", new TJsonHandler(TJsonNetInfo::GetSwagger())); +} + +void InitViewerComputeJsonHandler(TJsonHandlers &handlers) { + handlers.AddHandler("/viewer/compute", new TJsonHandler(TJsonCompute::GetSwagger())); +} + +void InitViewerHealthCheckJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/healthcheck", new TJsonHandler(TJsonHealthCheck::GetSwagger())); +} + +void InitViewerNodesJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/nodes", new TJsonHandler(TJsonNodes::GetSwagger())); +} + +void InitViewerACLJsonHandler(TJsonHandlers &jsonHandlers) { + jsonHandlers.AddHandler("/viewer/acl", new TJsonHandler(TJsonACL::GetSwagger())); +} + +void InitViewerGraphJsonHandler(TJsonHandlers &handlers) { + handlers.AddHandler("/viewer/graph", new TJsonHandler(TJsonGraph::GetSwagger())); +} + +void InitViewerRenderJsonHandler(TJsonHandlers& handlers) { + handlers.AddHandler("/viewer/render", new TJsonHandler(TJsonRender::GetSwagger())); +} + +void InitViewerAutocompleteJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/autocomplete", new TJsonHandler(TJsonAutocomplete::GetSwagger())); +} + +void InitViewerCheckAccessJsonHandler(TJsonHandlers& jsonHandlers) { + jsonHandlers.AddHandler("/viewer/check_access", new TJsonHandler(TCheckAccess::GetSwagger())); +} void InitViewerJsonHandlers(TJsonHandlers& jsonHandlers) { InitViewerCapabilitiesJsonHandler(jsonHandlers); - jsonHandlers.AddHandler("/viewer/nodelist", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/nodeinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/sysinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/vdiskinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/pdiskinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/tabletinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/describe", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/describe_topic", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/describe_consumer", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/hotkeys", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/hiveinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/bsgroupinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/bscontrollerinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/config", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/counters", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/topicinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/pqconsumerinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/tabletcounters", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/storage", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/storage_usage", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/metainfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/browse", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/cluster", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/content", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/labeledcounters", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/tenants", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/hivestats", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/tenantinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/whoami", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/query", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/netinfo", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/compute", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/healthcheck", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/nodes", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/acl", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/graph", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/render", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/autocomplete", new TJsonHandler); - jsonHandlers.AddHandler("/viewer/check_access", new TJsonHandler); + InitViewerNodelistJsonHandler(jsonHandlers); + InitViewerNodeInfoJsonHandler(jsonHandlers); + InitViewerSysInfoJsonHandler(jsonHandlers); + InitViewerVDiskInfoJsonHandler(jsonHandlers); + InitViewerPDiskInfoJsonHandler(jsonHandlers); + InitViewerTabletInfoJsonHandler(jsonHandlers); + InitViewerDescribeJsonHandler(jsonHandlers); + InitViewerDescribeTopicJsonHandler(jsonHandlers); + InitViewerDescribeConsumerJsonHandler(jsonHandlers); + InitViewerHotkeysJsonHandler(jsonHandlers); + InitViewerHiveInfoJsonHandler(jsonHandlers); + InitViewerBSGroupInfoJsonHandler(jsonHandlers); + InitViewerBSControllerInfoJsonHandler(jsonHandlers); + InitViewerConfigJsonHandler(jsonHandlers); + InitViewerCountersJsonHandler(jsonHandlers); + InitViewerTopicInfoJsonHandler(jsonHandlers); + InitViewerPQConsumerInfoJsonHandler(jsonHandlers); + InitViewerTabletCountersJsonHandler(jsonHandlers); + InitViewerStorageJsonHandler(jsonHandlers); + InitViewerStorageUsageJsonHandler(jsonHandlers); + InitViewerClusterJsonHandler(jsonHandlers); + InitViewerLabeledCountersJsonHandler(jsonHandlers); + InitViewerTenantsJsonHandler(jsonHandlers); + InitViewerHiveStatsJsonHandler(jsonHandlers); + InitViewerTenantInfoJsonHandler(jsonHandlers); + InitViewerWhoAmIJsonHandler(jsonHandlers); + InitViewerQueryJsonHandler(jsonHandlers); + InitViewerNetInfoJsonHandler(jsonHandlers); + InitViewerComputeJsonHandler(jsonHandlers); + InitViewerHealthCheckJsonHandler(jsonHandlers); + InitViewerNodesJsonHandler(jsonHandlers); + InitViewerACLJsonHandler(jsonHandlers); + InitViewerGraphJsonHandler(jsonHandlers); + InitViewerRenderJsonHandler(jsonHandlers); + InitViewerAutocompleteJsonHandler(jsonHandlers); + InitViewerCheckAccessJsonHandler(jsonHandlers); } } diff --git a/ydb/core/viewer/json_local_rpc.h b/ydb/core/viewer/json_local_rpc.h index 00cd683cbb72..f8aabfe71ca6 100644 --- a/ydb/core/viewer/json_local_rpc.h +++ b/ydb/core/viewer/json_local_rpc.h @@ -1,17 +1,8 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" - +#include "viewer.h" +#include #include -#include namespace NKikimr { namespace NViewer { diff --git a/ydb/core/viewer/json_pipe_req.cpp b/ydb/core/viewer/json_pipe_req.cpp index b759922719c9..49f683caf101 100644 --- a/ydb/core/viewer/json_pipe_req.cpp +++ b/ydb/core/viewer/json_pipe_req.cpp @@ -1,4 +1,5 @@ #include "json_pipe_req.h" +#include namespace NKikimr::NViewer { @@ -410,6 +411,10 @@ TString TViewerPipeClient::GetHTTPOKJSON(TString response, TInstant lastModified return Viewer->GetHTTPOKJSON(GetRequest(), std::move(response), lastModified); } +TString TViewerPipeClient::GetHTTPOKJSON(const NJson::TJsonValue& response, TInstant lastModified) { + return GetHTTPOKJSON(NJson::WriteJson(response, false), lastModified); +} + TString TViewerPipeClient::GetHTTPGATEWAYTIMEOUT(TString contentType, TString response) { return Viewer->GetHTTPGATEWAYTIMEOUT(GetRequest(), std::move(contentType), std::move(response)); } @@ -422,6 +427,10 @@ TString TViewerPipeClient::GetHTTPINTERNALERROR(TString contentType, TString res return Viewer->GetHTTPINTERNALERROR(GetRequest(), std::move(contentType), std::move(response)); } +TString TViewerPipeClient::GetHTTPFORBIDDEN(TString contentType, TString response) { + return Viewer->GetHTTPFORBIDDEN(GetRequest(), std::move(contentType), std::move(response)); +} + TString TViewerPipeClient::MakeForward(const std::vector& nodes) { return Viewer->MakeForward(GetRequest(), nodes); } @@ -443,6 +452,10 @@ void TViewerPipeClient::Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev) { } } +void TViewerPipeClient::HandleTimeout() { + ReplyAndPassAway(GetHTTPGATEWAYTIMEOUT()); +} + void TViewerPipeClient::PassAway() { ClosePipes(); TBase::PassAway(); diff --git a/ydb/core/viewer/json_pipe_req.h b/ydb/core/viewer/json_pipe_req.h index d7ecd55d6c9c..0ae68e68f277 100644 --- a/ydb/core/viewer/json_pipe_req.h +++ b/ydb/core/viewer/json_pipe_req.h @@ -1,28 +1,26 @@ #pragma once - -#include -#include -#include -#include -#include -#include +#include "viewer.h" #include #include +#include #include +#include #include #include +#include #include #include #include -#include -#include "viewer.h" +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NKikimr; using namespace NSchemeCache; using NNodeWhiteboard::TNodeId; +using NNodeWhiteboard::TTabletId; class TViewerPipeClient : public TActorBootstrapped { using TBase = TActorBootstrapped; @@ -50,7 +48,7 @@ class TViewerPipeClient : public TActorBootstrapped { ui32 Requests = 0; }; - std::unordered_map PipeInfo; + std::unordered_map PipeInfo; struct TDelayedRequest { std::unique_ptr Event; @@ -152,17 +150,11 @@ class TViewerPipeClient : public TActorBootstrapped { NTabletPipe::TClientConfig GetPipeClientConfig(); ~TViewerPipeClient(); - TViewerPipeClient(); - TViewerPipeClient(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev); - - TActorId ConnectTabletPipe(NNodeWhiteboard::TTabletId tabletId); - + TActorId ConnectTabletPipe(TTabletId tabletId); void SendEvent(std::unique_ptr event); - void SendRequest(TActorId recipient, IEventBase* ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}); - void SendRequestToPipe(TActorId pipe, IEventBase* ev, ui64 cookie = 0, NWilson::TTraceId traceId = {}); template @@ -180,109 +172,70 @@ class TViewerPipeClient : public TActorBootstrapped { } void SendDelayedRequests(); + void RequestHiveDomainStats(TTabletId hiveId); + void RequestHiveNodeStats(TTabletId hiveId, TPathId pathId); + void RequestHiveStorageStats(TTabletId hiveId); - void RequestHiveDomainStats(NNodeWhiteboard::TTabletId hiveId); - - void RequestHiveNodeStats(NNodeWhiteboard::TTabletId hiveId, TPathId pathId); - - void RequestHiveStorageStats(NNodeWhiteboard::TTabletId hiveId); - - NNodeWhiteboard::TTabletId GetConsoleId() { + TTabletId GetConsoleId() { return MakeConsoleID(); } - TRequestResponse MakeRequestHiveStorageStats(NNodeWhiteboard::TTabletId hiveId); + TTabletId GetBSControllerId() { + return MakeBSControllerID(); + } + TRequestResponse MakeRequestHiveStorageStats(TTabletId hiveId); void RequestConsoleListTenants(); - TRequestResponse MakeRequestConsoleListTenants(); - void RequestConsoleGetTenantStatus(const TString& path); - - NNodeWhiteboard::TTabletId GetBSControllerId() { - return MakeBSControllerID(); - } - void RequestBSControllerConfig(); - void RequestBSControllerConfigWithStoragePools(); - TRequestResponse MakeRequestBSControllerConfigWithStoragePools(); - void RequestBSControllerInfo(); - void RequestBSControllerSelectGroups(THolder request); - TRequestResponse MakeRequestBSControllerSelectGroups(THolder request, ui64 cookie = 0); - void RequestBSControllerPDiskRestart(ui32 nodeId, ui32 pdiskId, bool force = false); - void RequestBSControllerVDiskEvict(ui32 groupId, ui32 groupGeneration, ui32 failRealmIdx, ui32 failDomainIdx, ui32 vdiskIdx, bool force = false); - TRequestResponse RequestBSControllerPDiskInfo(ui32 nodeId, ui32 pdiskId); - TRequestResponse RequestBSControllerVDiskInfo(ui32 nodeId, ui32 pdiskId); - TRequestResponse RequestBSControllerGroups(); - TRequestResponse RequestBSControllerPools(); - TRequestResponse RequestBSControllerVSlots(); - TRequestResponse RequestBSControllerPDisks(); - void RequestBSControllerPDiskUpdateStatus(const NKikimrBlobStorage::TUpdateDriveStatus& driveStatus, bool force = false); - void RequestSchemeCacheNavigate(const TString& path); - void RequestSchemeCacheNavigate(const TPathId& pathId); - TRequestResponse MakeRequestSchemeCacheNavigate(const TString& path, ui64 cookie = 0); - TRequestResponse MakeRequestSchemeCacheNavigate(TPathId pathId, ui64 cookie = 0); - void RequestTxProxyDescribe(const TString& path); - void RequestStateStorageEndpointsLookup(const TString& path); - void RequestStateStorageMetadataCacheEndpointsLookup(const TString& path); - std::vector GetNodesFromBoardReply(TEvStateStorage::TEvBoardInfo::TPtr& ev); - void InitConfig(const TCgiParameters& params); - void InitConfig(const TRequestSettings& settings); - void ClosePipes(); - - ui32 FailPipeConnect(NNodeWhiteboard::TTabletId tabletId); + ui32 FailPipeConnect(TTabletId tabletId); bool IsLastRequest() const { return Requests == 1; } TRequestState GetRequest() const; - void ReplyAndPassAway(TString data, const TString& error = {}); TString GetHTTPOK(TString contentType = {}, TString response = {}, TInstant lastModified = {}); - TString GetHTTPOKJSON(TString response = {}, TInstant lastModified = {}); - + TString GetHTTPOKJSON(const NJson::TJsonValue& response, TInstant lastModified = {}); TString GetHTTPGATEWAYTIMEOUT(TString contentType = {}, TString response = {}); - TString GetHTTPBADREQUEST(TString contentType = {}, TString response = {}); - TString GetHTTPINTERNALERROR(TString contentType = {}, TString response = {}); - + TString GetHTTPFORBIDDEN(TString contentType = {}, TString response = {}); TString MakeForward(const std::vector& nodes); void RequestDone(ui32 requests = 1); - void Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev); - + void HandleTimeout(); void PassAway() override; }; } -} diff --git a/ydb/core/viewer/json_storage_base.h b/ydb/core/viewer/json_storage_base.h index 986127c6e231..1f8616ce6bbc 100644 --- a/ydb/core/viewer/json_storage_base.h +++ b/ydb/core/viewer/json_storage_base.h @@ -1,17 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include +#include "json_pipe_req.h" #include "viewer.h" +#include "viewer_bsgroupinfo.h" +#include "viewer_vdiskinfo.h" +#include "viewer_pdiskinfo.h" #include "viewer_helper.h" -#include "json_pipe_req.h" -#include "json_vdiskinfo.h" -#include "json_pdiskinfo.h" +#include "wb_merge.h" template<> struct std::hash { @@ -31,8 +25,7 @@ struct std::equal_to { } }; -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; @@ -104,10 +97,10 @@ class TJsonStorageBase : public TViewerPipeClient { TString Erasure; ui32 Degraded; float Usage; - uint64 Used; - uint64 Limit; - uint64 Read; - uint64 Write; + ui64 Used; + ui64 Limit; + ui64 Read; + ui64 Write; TGroupRow() : Used(0) @@ -561,4 +554,3 @@ class TJsonStorageBase : public TViewerPipeClient { }; } -} diff --git a/ydb/core/viewer/json_vdisk_req.h b/ydb/core/viewer/json_vdisk_req.h index 09d1ad1ab64b..71ccc636ca7f 100644 --- a/ydb/core/viewer/json_vdisk_req.h +++ b/ydb/core/viewer/json_vdisk_req.h @@ -1,18 +1,12 @@ #pragma once -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" +#include "viewer.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; - template struct TJsonVDiskRequestHelper { static std::unique_ptr MakeRequest(NMon::TEvHttpInfo::TPtr &, TString *) { @@ -24,7 +18,6 @@ struct TJsonVDiskRequestHelper { } }; - template class TJsonVDiskRequest : public TViewerPipeClient { enum EEv { @@ -199,10 +192,11 @@ class TJsonVDiskRequest : public TViewerPipeClient { void ReplyAndPassAway() override { ReplyAndPassAway({}); } -}; -template -struct TJsonRequestParameters> { + static YAML::Node GetSchema() { + return TProtoToYaml::ProtoToYamlSchema(); + } + static YAML::Node GetParameters() { return YAML::Load(R"___( - name: node_id @@ -251,12 +245,4 @@ struct TJsonRequestParameters> { } }; -template -struct TJsonRequestSchema> { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -} } diff --git a/ydb/core/viewer/json_vdiskstat.h b/ydb/core/viewer/json_vdiskstat.h deleted file mode 100644 index 8aaa81ed1a9d..000000000000 --- a/ydb/core/viewer/json_vdiskstat.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include "json_vdisk_req.h" - -namespace NKikimr { -namespace NViewer { - -using TJsonVDiskStat = TJsonVDiskRequest; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "VDisk statistic"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "VDisk statistic"; - } -}; - -} -} diff --git a/ydb/core/viewer/json_wb_req.cpp b/ydb/core/viewer/json_wb_req.cpp new file mode 100644 index 000000000000..cb430846abc8 --- /dev/null +++ b/ydb/core/viewer/json_wb_req.cpp @@ -0,0 +1,226 @@ +#include "viewer_bsgroupinfo.h" +#include "viewer_nodeinfo.h" +#include "viewer_pdiskinfo.h" +#include "viewer_sysinfo.h" +#include "viewer_tabletinfo.h" +#include "viewer_vdiskinfo.h" +#include "json_handlers.h" + +namespace NKikimr::NViewer { + +YAML::Node GetWhiteboardRequestParameters() { + return YAML::Load(R"___( + - name: node_id + in: query + description: node identifier + required: false + type: integer + - name: merge + in: query + description: merge information from nodes + required: false + type: boolean + - name: group + in: query + description: group information by field + required: false + type: string + - name: all + in: query + description: return all possible key combinations (for enums only) + required: false + type: boolean + - name: filter + in: query + description: filter information by field + required: false + type: string + - name: alive + in: query + description: request from alive (connected) nodes only + required: false + type: boolean + - name: enums + in: query + description: convert enums to strings + required: false + type: boolean + - name: ui64 + in: query + description: return ui64 as number + required: false + type: boolean + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + - name: retries + in: query + description: number of retries + required: false + type: integer + - name: retry_period + in: query + description: retry period in ms + required: false + type: integer + default: 500 + - name: static + in: query + description: request from static nodes only + required: false + type: boolean + - name: since + in: query + description: filter by update time + required: false + type: string + )___"); +} + +void InitViewerBSGroupInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Storage groups information", + .Description = "Returns information about storage groups" + }); + yaml.SetParameters(GetWhiteboardRequestParameters()); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/bsgroupinfo", new TJsonHandler(yaml)); + TWhiteboardInfo::InitMerger(); +} + +void InitViewerNodeInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Interconnect information", + .Description = "Returns information about node connections" + }); + yaml.SetParameters(GetWhiteboardRequestParameters()); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/nodeinfo", new TJsonHandler(yaml)); + TWhiteboardInfo::InitMerger(); +} + +void InitViewerPDiskInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "PDisk information", + .Description = "Returns information about PDisks" + }); + yaml.SetParameters(GetWhiteboardRequestParameters()); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/pdiskinfo", new TJsonHandler(yaml)); +} + +void InitViewerSysInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "System information", + .Description = "Returns system information" + }); + yaml.SetParameters(GetWhiteboardRequestParameters()); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/sysinfo", new TJsonHandler(yaml)); +} + +void InitViewerTabletInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Tablet information", + .Description = "Returns information about tablets" + }); + yaml.AddParameter({ + .Name = "node_id", + .Description = "node identifier", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "merge", + .Description = "merge information from nodes", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "group", + .Description = "group information by field", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "all", + .Description = "return all possible key combinations (for enums only)", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "filter", + .Description = "filter information by field", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "alive", + .Description = "request from alive (connected) nodes only", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "retries", + .Description = "number of retries", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "retry_period", + .Description = "retry period in ms", + .Type = "integer", + .Default = "500", + }); + yaml.AddParameter({ + .Name = "static", + .Description = "request from static nodes only", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "since", + .Description = "filter by update time", + .Type = "string", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/tabletinfo", new TJsonHandler(yaml)); +} + +void InitViewerVDiskInfoJsonHandler(TJsonHandlers& jsonHandlers) { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "VDisk information", + .Description = "Returns information about VDisks" + }); + yaml.SetParameters(GetWhiteboardRequestParameters()); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + jsonHandlers.AddHandler("/viewer/vdiskinfo", new TJsonHandler(yaml)); +} + +} diff --git a/ydb/core/viewer/json_wb_req.h b/ydb/core/viewer/json_wb_req.h index 03bc949d4ebf..235b8e52eeec 100644 --- a/ydb/core/viewer/json_wb_req.h +++ b/ydb/core/viewer/json_wb_req.h @@ -1,28 +1,26 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" -#include "wb_merge.h" -#include "wb_group.h" +#include "log.h" +#include "viewer.h" #include "wb_filter.h" +#include "wb_group.h" +#include "wb_merge.h" #include "wb_req.h" -#include "log.h" +#include +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; +YAML::Node GetWhiteboardRequestParameters(); + template class TJsonWhiteboardRequest : public TWhiteboardRequest { -protected: +public: using TThis = TJsonWhiteboardRequest; using TBase = TWhiteboardRequest; using TResponseType = typename TResponseEventType::ProtoRecordType; @@ -30,7 +28,6 @@ class TJsonWhiteboardRequest : public TWhiteboardRequest -struct TJsonRequestParameters> { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: node_id - in: query - description: node identifier - required: false - type: integer - - name: merge - in: query - description: merge information from nodes - required: false - type: boolean - - name: group - in: query - description: group information by field - required: false - type: string - - name: all - in: query - description: return all possible key combinations (for enums only) - required: false - type: boolean - - name: filter - in: query - description: filter information by field - required: false - type: string - - name: alive - in: query - description: request from alive (connected) nodes only - required: false - type: boolean - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: retries - in: query - description: number of retries - required: false - type: integer - - name: retry_period - in: query - description: retry period in ms - required: false - type: integer - default: 500 - - name: static - in: query - description: request from static nodes only - required: false - type: boolean - - name: since - in: query - description: filter by update time - required: false - type: string - )___"); - } -}; - -template -struct TJsonRequestSchema> { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -} } diff --git a/ydb/core/viewer/log.h b/ydb/core/viewer/log.h index 8a0fe6dcf054..da5229ff0c68 100644 --- a/ydb/core/viewer/log.h +++ b/ydb/core/viewer/log.h @@ -1,16 +1,13 @@ #pragma once - -#include #include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { inline TString GetLogPrefix() { return {}; } -} } #define BLOG_D(stream) LOG_DEBUG_S(*TlsActivationContext, NKikimrServices::VIEWER, GetLogPrefix() << stream) diff --git a/ydb/core/viewer/operation_cancel.h b/ydb/core/viewer/operation_cancel.h index eea1a238bb88..dc55fc145fdb 100644 --- a/ydb/core/viewer/operation_cancel.h +++ b/ydb/core/viewer/operation_cancel.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include "json_local_rpc.h" +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TOperationCancelRpc = TJsonLocalRpc -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( post: - tags: - - operation - summary: Cancels operation - description: > - Starts cancellation of a long-running operation, - Clients can use GetOperation to check whether the cancellation succeeded - or whether the operation completed despite cancellation. - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: id - in: query - description: operation id - required: true - type: string - requestBody: - content: - application/json: - schema: {} - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - node["post"]["requestBody"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + tags: + - operation + summary: Cancels operation + description: > + Starts cancellation of a long-running operation, + Clients can use GetOperation to check whether the cancellation succeeded + or whether the operation completed despite cancellation. + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: id + in: query + description: operation id + required: true + type: string + requestBody: + content: + application/json: + schema: {} + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + node["post"]["requestBody"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; } -} + diff --git a/ydb/core/viewer/operation_forget.h b/ydb/core/viewer/operation_forget.h index b8338ae78409..2ba961755530 100644 --- a/ydb/core/viewer/operation_forget.h +++ b/ydb/core/viewer/operation_forget.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include "json_local_rpc.h" +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TOperationForgetRpc = TJsonLocalRpc -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - post: - tags: - - operation - summary: Forgets operation - description: > - Forgets long-running operation. It does not cancel the operation and returns - an error if operation was not completed. - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: id - in: query - description: operation id - required: true - type: string - requestBody: - content: - application/json: - schema: {} - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - node["post"]["requestBody"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + post: + tags: + - operation + summary: Forgets operation + description: > + Forgets long-running operation. It does not cancel the operation and returns + an error if operation was not completed. + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: id + in: query + description: operation id + required: true + type: string + requestBody: + content: + application/json: + schema: {} + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + node["post"]["requestBody"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; } -} diff --git a/ydb/core/viewer/operation_get.h b/ydb/core/viewer/operation_get.h index 5fd4a0b61f4c..3b9ffeb4b48f 100644 --- a/ydb/core/viewer/operation_get.h +++ b/ydb/core/viewer/operation_get.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include "json_local_rpc.h" +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TOperationGetRpc = TJsonLocalRpc -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - operation - summary: Get operation - description: Check status for a given operation - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: id - in: query - description: operation id - required: true - type: string - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - operation + summary: Get operation + description: Check status for a given operation + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: id + in: query + description: operation id + required: true + type: string + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; } -} diff --git a/ydb/core/viewer/operation_list.h b/ydb/core/viewer/operation_list.h index e78b59188101..585f1812c17d 100644 --- a/ydb/core/viewer/operation_list.h +++ b/ydb/core/viewer/operation_list.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include "json_local_rpc.h" +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TOperationListRpc = TJsonLocalRpc -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - operation - summary: List operations - description: Lists operations that match the specified filter in the request - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: kind - in: query - description: kind - required: true - type: string - - name: page_size - in: query - description: page size - required: false - type: integer - - name: page_token - in: query - description: page token - required: false - type: string - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - TProtoToYaml::FillEnum(node["get"]["parameters"][1]["enum"], NProtoBuf::GetEnumDescriptor(), { - .ConvertToLowerCase = true, - .SkipDefaultValue = true - }); - return node; -} + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - operation + summary: List operations + description: Lists operations that match the specified filter in the request + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: kind + in: query + description: kind + required: true + type: string + - name: page_size + in: query + description: page size + required: false + type: integer + - name: page_token + in: query + description: page token + required: false + type: string + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + TProtoToYaml::FillEnum(node["get"]["parameters"][1]["enum"], NProtoBuf::GetEnumDescriptor(), { + .ConvertToLowerCase = true, + .SkipDefaultValue = true + }); + return node; + } +}; } -} diff --git a/ydb/core/viewer/pdisk_info.h b/ydb/core/viewer/pdisk_info.h index 844f939275da..78b105f6b891 100644 --- a/ydb/core/viewer/pdisk_info.h +++ b/ydb/core/viewer/pdisk_info.h @@ -1,17 +1,9 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" +#include "viewer.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -231,53 +223,51 @@ class TPDiskInfo : public TViewerPipeClient { }); TBase::ReplyAndPassAway(GetHTTPOKJSON(json.Str())); } -}; -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - pdisk - summary: Gets PDisk info - description: Gets PDisk information from Whiteboard and BSC - parameters: - - name: node_id - in: query - description: node identifier - type: integer - - name: pdisk_id - in: query - description: pdisk identifier - required: true - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - YAML::Node properties(node["get"]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["BSC"]["properties"]); - TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["StatusV2"], NProtoBuf::GetEnumDescriptor()); - TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["DecommitStatus"], NProtoBuf::GetEnumDescriptor()); - TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["Type"], NProtoBuf::GetEnumDescriptor()); - TProtoToYaml::FillEnum(properties["VDisks"]["items"]["properties"]["StatusV2"], NProtoBuf::GetEnumDescriptor()); - return node; -} + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - pdisk + summary: Gets PDisk info + description: Gets PDisk information from Whiteboard and BSC + parameters: + - name: node_id + in: query + description: node identifier + type: integer + - name: pdisk_id + in: query + description: pdisk identifier + required: true + type: integer + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + YAML::Node properties(node["get"]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["BSC"]["properties"]); + TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["StatusV2"], NProtoBuf::GetEnumDescriptor()); + TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["DecommitStatus"], NProtoBuf::GetEnumDescriptor()); + TProtoToYaml::FillEnum(properties["PDisk"]["properties"]["Type"], NProtoBuf::GetEnumDescriptor()); + TProtoToYaml::FillEnum(properties["VDisks"]["items"]["properties"]["StatusV2"], NProtoBuf::GetEnumDescriptor()); + return node; + } +}; } -} diff --git a/ydb/core/viewer/json_pdisk_restart.h b/ydb/core/viewer/pdisk_restart.h similarity index 71% rename from ydb/core/viewer/json_pdisk_restart.h rename to ydb/core/viewer/pdisk_restart.h index ff92e7011a63..440a4429a082 100644 --- a/ydb/core/viewer/json_pdisk_restart.h +++ b/ydb/core/viewer/pdisk_restart.h @@ -1,16 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" +#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -161,61 +155,60 @@ class TJsonPDiskRestart : public TViewerPipeClient { } PassAway(); } -}; -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - return YAML::Load(R"___( - post: - tags: - - pdisk - summary: Restart PDisk - description: Restart PDisk on the specified node - parameters: - - name: node_id - in: query - description: node identifier - type: integer - - name: pdisk_id - in: query - description: pdisk identifier - required: true - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: force - in: query - description: attempt forced operation, ignore warnings - required: false - type: boolean - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: boolean - description: was operation successful or not - error: - type: string - description: details about failed operation - forceRetryPossible: - type: boolean - description: if true, operation can be retried with force flag - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); -} + static YAML::Node GetSwagger() { + return YAML::Load(R"___( + post: + tags: + - pdisk + summary: Restart PDisk + description: Restart PDisk on the specified node + parameters: + - name: node_id + in: query + description: node identifier + type: integer + - name: pdisk_id + in: query + description: pdisk identifier + required: true + type: integer + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + - name: force + in: query + description: attempt forced operation, ignore warnings + required: false + type: boolean + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: boolean + description: was operation successful or not + error: + type: string + description: details about failed operation + forceRetryPossible: + type: boolean + description: if true, operation can be retried with force flag + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + } + +}; -} } diff --git a/ydb/core/viewer/pdisk_status.h b/ydb/core/viewer/pdisk_status.h index 783d7a7f1db7..a8330716ef46 100644 --- a/ydb/core/viewer/pdisk_status.h +++ b/ydb/core/viewer/pdisk_status.h @@ -1,17 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" +#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; extern bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event); @@ -154,89 +147,87 @@ class TPDiskStatus : public TViewerPipeClient { } PassAway(); } -}; -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( post: - tags: - - pdisk - summary: Updates PDisk status - description: Updates PDisk status in BSC - parameters: - - name: node_id - in: query - description: node identifier - type: integer - - name: pdisk_id - in: query - description: pdisk identifier - required: true - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: force - in: query - description: attempt forced operation, ignore warnings - required: false - type: boolean - requestBody: - description: Updates of PDisk statuses - required: true - content: - application/json: - schema: - type: object - properties: - status: - type: string - enum: [ACTIVE, INACTIVE, BROKEN, FAULTY, TO_BE_REMOVED, UNKNOWN] - description: > - PDisk operational status: - * `ACTIVE` - working as expected - * `INACTIVE` - new groups are not created using this drive, but existing ones continue to work as expected - * `BROKEN` - drive is marked as not working, groups will be immediately moved out of this drive upon receiving this status - * `FAULTY` - drive is expected to become BROKEN soon, new groups are not created, old groups are asynchronously moved out from this drive - * `TO_BE_REMOVED` - same as INACTIVE, but drive is counted in fault model as not working - decommit_status: - type: string - enum: [DECOMMIT_NONE, DECOMMIT_PENDING, DECOMMIT_IMMINENT, DECOMMIT_REJECTED] - description: > - PDisk decommission status: - * `DECOMMIT_NONE` - disk is not in decomission state - * `DECOMMIT_PENDING` - decomission is planned for this disk, but not started yet. existing slots are not moved from the disk, but no new slots are allocated on it - * `DECOMMIT_IMMINENT` - decomission has started for this disk. existing slots are moved from the disk - * `DECOMMIT_REJECTED` - no slots from other disks are placed on this disk in the process of decommission - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: boolean - description: was operation successful or not - error: - type: string - description: details about failed operation - forceRetryPossible: - type: boolean - description: if true, operation can be retried with force flag - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - return node; -} + tags: + - pdisk + summary: Updates PDisk status + description: Updates PDisk status in BSC + parameters: + - name: node_id + in: query + description: node identifier + type: integer + - name: pdisk_id + in: query + description: pdisk identifier + required: true + type: integer + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + - name: force + in: query + description: attempt forced operation, ignore warnings + required: false + type: boolean + requestBody: + description: Updates of PDisk statuses + required: true + content: + application/json: + schema: + type: object + properties: + status: + type: string + enum: [ACTIVE, INACTIVE, BROKEN, FAULTY, TO_BE_REMOVED, UNKNOWN] + description: > + PDisk operational status: + * `ACTIVE` - working as expected + * `INACTIVE` - new groups are not created using this drive, but existing ones continue to work as expected + * `BROKEN` - drive is marked as not working, groups will be immediately moved out of this drive upon receiving this status + * `FAULTY` - drive is expected to become BROKEN soon, new groups are not created, old groups are asynchronously moved out from this drive + * `TO_BE_REMOVED` - same as INACTIVE, but drive is counted in fault model as not working + decommit_status: + type: string + enum: [DECOMMIT_NONE, DECOMMIT_PENDING, DECOMMIT_IMMINENT, DECOMMIT_REJECTED] + description: > + PDisk decommission status: + * `DECOMMIT_NONE` - disk is not in decomission state + * `DECOMMIT_PENDING` - decomission is planned for this disk, but not started yet. existing slots are not moved from the disk, but no new slots are allocated on it + * `DECOMMIT_IMMINENT` - decomission has started for this disk. existing slots are moved from the disk + * `DECOMMIT_REJECTED` - no slots from other disks are placed on this disk in the process of decommission + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: boolean + description: was operation successful or not + error: + type: string + description: details about failed operation + forceRetryPossible: + type: boolean + description: if true, operation can be retried with force flag + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + return node; + } +}; } -} diff --git a/ydb/core/viewer/protos/viewer.proto b/ydb/core/viewer/protos/viewer.proto index 0232a1b03fbf..ba88f0b2db0d 100644 --- a/ydb/core/viewer/protos/viewer.proto +++ b/ydb/core/viewer/protos/viewer.proto @@ -638,18 +638,17 @@ message TEvDescribeSchemeInfo { Cache = 2; } - optional string Status = 1; - optional string Reason = 2; - optional string Path = 3; - optional NKikimrSchemeOp.TPathDescription PathDescription = 4; - optional fixed64 DEPRECATED_PathOwner = 5; // replaced by PathOwnerId - optional fixed64 PathId = 6; - - optional string LastExistedPrefixPath = 7; - optional fixed64 LastExistedPrefixPathId = 8; - optional NKikimrSchemeOp.TPathDescription LastExistedPrefixDescription = 9; - optional fixed64 PathOwnerId = 10; - optional ESource Source = 11; + string Status = 1; + string Reason = 2; + string Path = 3; + NKikimrSchemeOp.TPathDescription PathDescription = 4; + fixed64 DEPRECATED_PathOwner = 5; // replaced by PathOwnerId + fixed64 PathId = 6; + string LastExistedPrefixPath = 7; + fixed64 LastExistedPrefixPathId = 8; + NKikimrSchemeOp.TPathDescription LastExistedPrefixDescription = 9; + fixed64 PathOwnerId = 10; + ESource Source = 11; } enum EAutocompleteType { diff --git a/ydb/core/viewer/query_autocomplete_helper.h b/ydb/core/viewer/query_autocomplete_helper.h index e523ceb029bb..9096a0f4261e 100644 --- a/ydb/core/viewer/query_autocomplete_helper.h +++ b/ydb/core/viewer/query_autocomplete_helper.h @@ -1,6 +1,8 @@ #pragma once - +#include #include +#include +#include namespace NKikimr::NViewer { diff --git a/ydb/core/viewer/scheme_directory.h b/ydb/core/viewer/scheme_directory.h index 400504fbd822..8198b0a8e597 100644 --- a/ydb/core/viewer/scheme_directory.h +++ b/ydb/core/viewer/scheme_directory.h @@ -1,11 +1,10 @@ #pragma once -#include -#include -#include "json_local_rpc.h" #include "json_handlers.h" +#include "json_local_rpc.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { class TSchemeDirectory : public IActor { public: @@ -66,6 +65,10 @@ class TSchemeDirectoryRequest : public LocalRpcType { class TJsonSchemeDirectoryHandler : public TJsonHandler { public: + TJsonSchemeDirectoryHandler() + : TJsonHandler(GetSwagger()) + {} + IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override { switch (event->Get()->Request.GetMethod()) { case HTTP_METHOD_GET: @@ -78,102 +81,100 @@ class TJsonSchemeDirectoryHandler : public TJsonHandler { throw std::logic_error("Bad request method"); } } -}; -template<> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( get: - tags: - - scheme - summary: List directory - description: Returns information about given directory and objects inside it - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: path - in: query - description: path to directory - required: true - type: string - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout + tags: + - scheme + summary: List directory + description: Returns information about given directory and objects inside it + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: path + in: query + description: path to directory + required: true + type: string + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout post: - tags: - - scheme - summary: Make directory - description: Makes directory - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: path - in: query - description: path to directory - required: true - type: string - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout + tags: + - scheme + summary: Make directory + description: Makes directory + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: path + in: query + description: path to directory + required: true + type: string + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout delete: - tags: - - scheme - summary: Remove directory - description: Removes directory - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: path - in: query - description: path to directory - required: true - type: string - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - node["delete"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + tags: + - scheme + summary: Remove directory + description: Removes directory + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: path + in: query + description: path to directory + required: true + type: string + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + node["delete"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; } -} diff --git a/ydb/core/viewer/storage_groups.cpp b/ydb/core/viewer/storage_groups.h similarity index 94% rename from ydb/core/viewer/storage_groups.cpp rename to ydb/core/viewer/storage_groups.h index 8046767b86be..897332a5d176 100644 --- a/ydb/core/viewer/storage_groups.cpp +++ b/ydb/core/viewer/storage_groups.h @@ -1,24 +1,12 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" -#include "viewer_helper.h" +#pragma once #include "json_handlers.h" #include "json_pipe_req.h" -#include "json_vdiskinfo.h" -#include "json_pdiskinfo.h" -#include "json_bsgroupinfo.h" +#include "log.h" +#include "viewer_helper.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NProtobufJson; @@ -74,7 +62,6 @@ struct TVSlotId : TPDiskId { bool operator ==(const TVSlotId& a) const = default; }; -} } template<> @@ -94,14 +81,11 @@ struct std::hash { } }; -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; -using ::google::protobuf::FieldDescriptor; - enum class EGroupFields : ui8 { GroupId, PoolName, @@ -1689,118 +1673,111 @@ class TStorageGroups : public TViewerPipeClient { }); TBase::ReplyAndPassAway(GetHTTPOKJSON(out.Str())); } -}; - -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - post: - tags: - - storage - summary: Storage groups - description: Information about storage groups - parameters: - - name: database - in: query - description: database name - required: false - type: string - - name: pool - in: query - description: storage pool name - required: false - type: string - - name: node_id - in: query - description: node id - required: false - type: integer - - name: pdisk_id - in: query - description: pdisk id - required: false - type: integer - - name: group_id - in: query - description: group id - required: false - type: integer - - name: need_groups - in: query - description: return groups information - required: false - type: boolean - default: true - - name: need_disks - in: query - description: return disks information - required: false - type: boolean - default: true - - name: with - in: query - description: > - filter groups by missing or space: - * `missing` - * `space` - required: false - type: string - - name: sort - in: query - description: > - sort by: - * `PoolName` - * `Kind` - * `MediaType` - * `Erasure` - * `MissingDisks` - * `Usage` - * `GroupId` - * `Used` - * `Limit` - * `Usage` - * `Read` - * `Write` - required: false - type: string - - name: offset - in: query - description: skip N nodes - required: false - type: integer - - name: limit - in: query - description: limit to N nodes - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - description: format depends on schema parameter - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + post: + tags: + - storage + summary: Storage groups + description: Information about storage groups + parameters: + - name: database + in: query + description: database name + required: false + type: string + - name: pool + in: query + description: storage pool name + required: false + type: string + - name: node_id + in: query + description: node id + required: false + type: integer + - name: pdisk_id + in: query + description: pdisk id + required: false + type: integer + - name: group_id + in: query + description: group id + required: false + type: integer + - name: need_groups + in: query + description: return groups information + required: false + type: boolean + default: true + - name: need_disks + in: query + description: return disks information + required: false + type: boolean + default: true + - name: with + in: query + description: > + filter groups by missing or space: + * `missing` + * `space` + required: false + type: string + - name: sort + in: query + description: > + sort by: + * `PoolName` + * `Kind` + * `MediaType` + * `Erasure` + * `MissingDisks` + * `Usage` + * `GroupId` + * `Used` + * `Limit` + * `Usage` + * `Read` + * `Write` + required: false + type: string + - name: offset + in: query + description: skip N nodes + required: false + type: integer + - name: limit + in: query + description: limit to N nodes + required: false + type: integer + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + description: format depends on schema parameter + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; -void InitStorageGroupsJsonHandler(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/storage/groups", new TJsonHandler); } - -} // namespace NViewer -} // namespace NKikimr diff --git a/ydb/core/viewer/vdisk_blobindexstat.h b/ydb/core/viewer/vdisk_blobindexstat.h new file mode 100644 index 000000000000..37e1aa39ea9e --- /dev/null +++ b/ydb/core/viewer/vdisk_blobindexstat.h @@ -0,0 +1,10 @@ +#pragma once +#include "json_vdisk_req.h" +#include + +namespace NKikimr::NViewer { + +using TJsonBlobIndexStat = TJsonVDiskRequest; + + +} diff --git a/ydb/core/viewer/json_vdisk_evict.h b/ydb/core/viewer/vdisk_evict.h similarity index 71% rename from ydb/core/viewer/json_vdisk_evict.h rename to ydb/core/viewer/vdisk_evict.h index c37c5ab5e803..624762654ad1 100644 --- a/ydb/core/viewer/json_vdisk_evict.h +++ b/ydb/core/viewer/vdisk_evict.h @@ -1,16 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include "viewer.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -184,82 +178,80 @@ class TJsonVDiskEvict : public TViewerPipeClient { TBase::Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json)), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - return YAML::Load(R"___( + static YAML::Node GetSwagger() { + return YAML::Load(R"___( post: - tags: - - vdisk - summary: VDisk evict - description: VDisk evict - parameters: - - name: vdisk_id - in: query - description: vdisk identifier - required: false - type: string - - name: group_id - in: query - description: group identifier - required: false - type: integer - - name: group_generation_id - in: query - description: group generation identifier - required: false - type: integer - - name: fail_realm_idx - in: query - description: fail realm identifier - required: false - type: integer - - name: fail_domain_ids - in: query - description: fail domain identifier - required: false - type: integer - - name: vdisk_idx - in: query - description: vdisk idx identifier - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: force - in: query - description: attempt forced operation, ignore warnings - required: false - type: boolean - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: boolean - description: was operation successful or not - error: - type: string - description: details about failed operation - forceRetryPossible: - type: boolean - description: if true, operation can be retried with force flag - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); -} + tags: + - vdisk + summary: VDisk evict + description: VDisk evict + parameters: + - name: vdisk_id + in: query + description: vdisk identifier + required: false + type: string + - name: group_id + in: query + description: group identifier + required: false + type: integer + - name: group_generation_id + in: query + description: group generation identifier + required: false + type: integer + - name: fail_realm_idx + in: query + description: fail realm identifier + required: false + type: integer + - name: fail_domain_ids + in: query + description: fail domain identifier + required: false + type: integer + - name: vdisk_idx + in: query + description: vdisk idx identifier + required: false + type: integer + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + - name: force + in: query + description: attempt forced operation, ignore warnings + required: false + type: boolean + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: boolean + description: was operation successful or not + error: + type: string + description: details about failed operation + forceRetryPossible: + type: boolean + description: if true, operation can be retried with force flag + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + } +}; } -} diff --git a/ydb/core/viewer/json_getblob.h b/ydb/core/viewer/vdisk_getblob.h similarity index 80% rename from ydb/core/viewer/json_getblob.h rename to ydb/core/viewer/vdisk_getblob.h index d09c691dcb90..71340249b78e 100644 --- a/ydb/core/viewer/json_getblob.h +++ b/ydb/core/viewer/vdisk_getblob.h @@ -1,14 +1,9 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "json_vdisk_req.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TJsonGetBlob = TJsonVDiskRequest; @@ -79,20 +74,4 @@ struct TJsonVDiskRequestHelper { } }; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Get blob from VDisk"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Get blob from VDisk"; - } -}; - -} } diff --git a/ydb/core/viewer/vdisk_vdiskstat.h b/ydb/core/viewer/vdisk_vdiskstat.h new file mode 100644 index 000000000000..8d71da596369 --- /dev/null +++ b/ydb/core/viewer/vdisk_vdiskstat.h @@ -0,0 +1,9 @@ +#pragma once +#include "json_vdisk_req.h" +#include + +namespace NKikimr::NViewer { + +using TJsonVDiskStat = TJsonVDiskRequest; + +} diff --git a/ydb/core/viewer/viewer.cpp b/ydb/core/viewer/viewer.cpp index ea22224d02ab..fb8a9f5c2734 100644 --- a/ydb/core/viewer/viewer.cpp +++ b/ydb/core/viewer/viewer.cpp @@ -1,83 +1,40 @@ -#include -#include -#include -#include -#include +#include "viewer.h" +#include "counters_hosts.h" +#include "json_handlers.h" +#include "log.h" +#include "viewer_request.h" +#include #include -#include +#include #include +#include +#include +#include #include +#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" -#include "viewer_request.h" -#include "viewer_probes.h" -#include #include -#include "browse_pq.h" -#include "browse_db.h" -#include "counters_hosts.h" -#include "json_healthcheck.h" - -#include "json_handlers.h" - -#include "json_bsgroupinfo.h" -#include "json_nodeinfo.h" -#include "json_vdiskinfo.h" - +#include +#include +#include +#include +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; extern void InitViewerJsonHandlers(TJsonHandlers& jsonHandlers); +extern void InitViewerBrowseJsonHandlers(TJsonHandlers& jsonHandlers); extern void InitPDiskJsonHandlers(TJsonHandlers& jsonHandlers); extern void InitVDiskJsonHandlers(TJsonHandlers& jsonHandlers); extern void InitOperationJsonHandlers(TJsonHandlers& jsonHandlers); extern void InitSchemeJsonHandlers(TJsonHandlers& jsonHandlers); extern void InitStorageJsonHandlers(TJsonHandlers& jsonHandlers); -void SetupPQVirtualHandlers(IViewer* viewer) { - viewer->RegisterVirtualHandler( - NKikimrViewer::EObjectType::Root, - [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { - return new NViewerPQ::TBrowseRoot(owner, browseContext); - }); - viewer->RegisterVirtualHandler( - NKikimrViewer::EObjectType::Consumers, - [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { - return new NViewerPQ::TBrowseConsumers(owner, browseContext); - }); - viewer->RegisterVirtualHandler( - NKikimrViewer::EObjectType::Consumer, - [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { - return new NViewerPQ::TBrowseConsumer(owner, browseContext); - }); - viewer->RegisterVirtualHandler( - NKikimrViewer::EObjectType::Topic, - [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { - return new NViewerPQ::TBrowseTopic(owner, browseContext); - }); -} - -void SetupDBVirtualHandlers(IViewer* viewer) { - viewer->RegisterVirtualHandler( - NKikimrViewer::EObjectType::Table, - [] (const TActorId& owner, const IViewer::TBrowseContext& browseContext) -> IActor* { - return new NViewerDB::TBrowseTable(owner, browseContext); - }); -} - class TViewer : public TActorBootstrapped, public IViewer { public: static constexpr NKikimrServices::TActivity::EType ActorActivityType() { @@ -95,7 +52,6 @@ class TViewer : public TActorBootstrapped, public IViewer { Become(&TThis::StateWork); NActors::TMon* mon = AppData(ctx)->Mon; if (mon) { - NLwTraceMonPage::ProbeRegistry().AddProbesList(LWTRACE_GET_PROBES(VIEWER_PROVIDER)); TVector viewerAllowedSIDs; TVector monitoringAllowedSIDs; { @@ -189,6 +145,7 @@ class TViewer : public TActorBootstrapped, public IViewer { InitStorageJsonHandlers(JsonHandlers); InitOperationJsonHandlers(JsonHandlers); InitSchemeJsonHandlers(JsonHandlers); + InitViewerBrowseJsonHandlers(JsonHandlers); for (const auto& handler : JsonHandlers.JsonHandlersList) { // temporary handling of old paths @@ -206,9 +163,6 @@ class TViewer : public TActorBootstrapped, public IViewer { JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodelist"] = JsonHandlers.JsonHandlersIndex["/viewer/nodelist"]; JsonHandlers.JsonHandlersIndex["/viewer/v2/json/tabletinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/tabletinfo"]; JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodeinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/nodeinfo"]; - - TWhiteboardInfo::InitMerger(); - TWhiteboardInfo::InitMerger(); } } @@ -414,24 +368,9 @@ class TViewer : public TActorBootstrapped, public IViewer { YAML::Node paths; for (const TString& name : JsonHandlers.JsonHandlersList) { const auto& handler = JsonHandlers.JsonHandlersIndex[name]; - TString tag = TString(TStringBuf(name.substr(1)).Before('/')); - auto path = paths[name]; auto swagger = handler->GetRequestSwagger(); - if (swagger.IsNull()) { - auto get = path["get"]; - get["tags"].push_back(tag); - if (auto summary = handler->GetRequestSummary()) { - get["summary"] = summary; - } - if (auto description = handler->GetRequestDescription()) { - get["description"] = description; - } - get["parameters"] = handler->GetRequestParameters(); - auto responses = get["responses"]; - auto response200 = responses["200"]; - response200["content"]["application/json"]["schema"] = handler->GetResponseJsonSchema(); - } else { - path = swagger; + if (!swagger.IsNull()) { + paths[name] = swagger; } } return paths; @@ -987,100 +926,6 @@ NKikimrViewer::EFlag GetVDiskOverallFlag(const NKikimrWhiteboard::TVDiskStateInf return flag; } -TBSGroupState GetBSGroupOverallStateWithoutLatency( - const NKikimrWhiteboard::TBSGroupStateInfo& info, - const TMap& vDisksIndex, - const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { - - TBSGroupState groupState; - groupState.Overall = NKikimrViewer::EFlag::Grey; - - const auto& vDiskIds = info.GetVDiskIds(); - std::unordered_map failedRings; - std::unordered_map failedDomains; - TVector vDiskFlags; - vDiskFlags.reserve(vDiskIds.size()); - for (auto iv = vDiskIds.begin(); iv != vDiskIds.end(); ++iv) { - const NKikimrBlobStorage::TVDiskID& vDiskId = *iv; - NKikimrViewer::EFlag flag = NKikimrViewer::EFlag::Grey; - auto ie = vDisksIndex.find(vDiskId); - if (ie != vDisksIndex.end()) { - auto pDiskId = std::make_pair(ie->second.GetNodeId(), ie->second.GetPDiskId()); - auto ip = pDisksIndex.find(pDiskId); - if (ip != pDisksIndex.end()) { - const NKikimrWhiteboard::TPDiskStateInfo& pDiskInfo(ip->second); - flag = Max(flag, GetPDiskOverallFlag(pDiskInfo)); - } else { - flag = NKikimrViewer::EFlag::Red; - } - const NKikimrWhiteboard::TVDiskStateInfo& vDiskInfo(ie->second); - flag = Max(flag, GetVDiskOverallFlag(vDiskInfo)); - if (vDiskInfo.GetDiskSpace() > NKikimrWhiteboard::EFlag::Green) { - groupState.SpaceProblems++; - } - } else { - flag = NKikimrViewer::EFlag::Red; - } - vDiskFlags.push_back(flag); - if (flag == NKikimrViewer::EFlag::Red || flag == NKikimrViewer::EFlag::Blue) { - groupState.MissingDisks++; - ++failedRings[vDiskId.GetRing()]; - ++failedDomains[vDiskId.GetDomain()]; - } - groupState.Overall = Max(groupState.Overall, flag); - } - - groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); // without failed rings we only allow to raise group status up to Blue/Yellow - TString erasure = info.GetErasureSpecies(); - if (erasure == TErasureType::ErasureSpeciesName(TErasureType::ErasureNone)) { - if (!failedDomains.empty()) { - groupState.Overall = NKikimrViewer::EFlag::Red; - } - } else if (erasure == TErasureType::ErasureSpeciesName(TErasureType::ErasureMirror3dc)) { - if (failedRings.size() > 2) { - groupState.Overall = NKikimrViewer::EFlag::Red; - } else if (failedRings.size() == 2) { // TODO: check for 1 ring - 1 domain rule - groupState.Overall = NKikimrViewer::EFlag::Orange; - } else if (failedRings.size() > 0) { - groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); - } - } else if (erasure == TErasureType::ErasureSpeciesName(TErasureType::Erasure4Plus2Block)) { - if (failedDomains.size() > 2) { - groupState.Overall = NKikimrViewer::EFlag::Red; - } else if (failedDomains.size() > 1) { - groupState.Overall = NKikimrViewer::EFlag::Orange; - } else if (failedDomains.size() > 0) { - groupState.Overall = Min(groupState.Overall, NKikimrViewer::EFlag::Yellow); - } - } - return groupState; -} - -NKikimrViewer::EFlag GetBSGroupOverallFlagWithoutLatency( - const NKikimrWhiteboard::TBSGroupStateInfo& info, - const TMap& vDisksIndex, - const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { - return GetBSGroupOverallStateWithoutLatency(info, vDisksIndex, pDisksIndex).Overall; -} - -TBSGroupState GetBSGroupOverallState( - const NKikimrWhiteboard::TBSGroupStateInfo& info, - const TMap& vDisksIndex, - const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { - TBSGroupState state = GetBSGroupOverallStateWithoutLatency(info, vDisksIndex, pDisksIndex); - if (info.HasLatency()) { - state.Overall = Max(state.Overall, Min(NKikimrViewer::EFlag::Yellow, GetViewerFlag(info.GetLatency()))); - } - return state; -} - -NKikimrViewer::EFlag GetBSGroupOverallFlag( - const NKikimrWhiteboard::TBSGroupStateInfo& info, - const TMap& vDisksIndex, - const TMap, const NKikimrWhiteboard::TPDiskStateInfo&>& pDisksIndex) { - return GetBSGroupOverallState(info, vDisksIndex, pDisksIndex).Overall; -} - NKikimrViewer::EFlag GetViewerFlag(Ydb::Monitoring::StatusFlag::Status flag) { switch (flag) { case Ydb::Monitoring::StatusFlag::GREY: @@ -1136,5 +981,4 @@ NKikimrViewer::EFlag GetViewerFlag(NKikimrWhiteboard::EFlag flag) { return static_cast((int)flag); } -} // NNodeTabletMonitor -} // NKikimr +} diff --git a/ydb/core/viewer/viewer.h b/ydb/core/viewer/viewer.h index 67cac550005c..b41bd789c1a5 100644 --- a/ydb/core/viewer/viewer.h +++ b/ydb/core/viewer/viewer.h @@ -1,21 +1,14 @@ #pragma once - -#include -#include - +#include #include -#include +#include +#include #include +#include #include -#include -#include -#include -#include #include -#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { inline TActorId MakeViewerID(ui32 node) { char x[12] = {'v','i','e','w','e','r'}; @@ -214,32 +207,6 @@ void SetupPQVirtualHandlers(IViewer* viewer); void SetupDBVirtualHandlers(IViewer* viewer); void SetupKqpContentHandler(IViewer* viewer); -template -struct TJsonRequestSchema { - static YAML::Node GetSchema() { return {}; } -}; - -template -struct TJsonRequestSummary { - static TString GetSummary() { return {}; } -}; - -template -struct TJsonRequestDescription { - static TString GetDescription() { return {}; } -}; - -template -struct TJsonRequestParameters { - static YAML::Node GetParameters() { return {}; } -}; - -template -struct TJsonRequestSwagger { - static YAML::Node GetSwagger() { return {}; } -}; - - template void GenericSplitIds(TStringBuf source, char delim, OutputIteratorType it) { for (TStringBuf value = source.NextTok(delim); !value.empty(); value = source.NextTok(delim)) { @@ -300,8 +267,5 @@ NKikimrViewer::EFlag GetFlagFromUsage(double usage); NKikimrWhiteboard::EFlag GetWhiteboardFlag(NKikimrViewer::EFlag flag); NKikimrViewer::EFlag GetViewerFlag(NKikimrWhiteboard::EFlag flag); -NKikimrViewer::EFlag GetViewerFlag(Ydb::Monitoring::StatusFlag::Status flag); - -} // NViewer -} // NKikimr +} diff --git a/ydb/core/viewer/json_acl.h b/ydb/core/viewer/viewer_acl.h similarity index 56% rename from ydb/core/viewer/json_acl.h rename to ydb/core/viewer/viewer_acl.h index 14055628e0db..2a2147b507f5 100644 --- a/ydb/core/viewer/json_acl.h +++ b/ydb/core/viewer/viewer_acl.h @@ -1,33 +1,24 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include "log.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; -using NSchemeShard::TEvSchemeShard; class TJsonACL : public TViewerPipeClient { using TThis = TJsonACL; using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; + using TBase::ReplyAndPassAway; TAutoPtr CacheResult; TJsonSettings JsonSettings; bool MergeRules = false; ui32 Timeout = 0; public: - TJsonACL(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonACL(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) {} void Bootstrap() override { @@ -150,23 +141,18 @@ class TJsonACL : public TViewerPipeClient { } } - void ReplyAndPassAway(TString data) { - Send(Event->Sender, new NMon::TEvHttpInfoRes(data, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } - void ReplyAndPassAway() override { if (CacheResult == nullptr) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "no SchemeCache response")); + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "no SchemeCache response")); } if (CacheResult->Request == nullptr) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "wrong SchemeCache response")); + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "wrong SchemeCache response")); } if (CacheResult->Request.Get()->ResultSet.empty()) { - return ReplyAndPassAway(Viewer->GetHTTPINTERNALERROR(Event->Get(), "text/plain", "SchemeCache response is empty")); + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "SchemeCache response is empty")); } if (CacheResult->Request.Get()->ErrorCount != 0) { - return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", TStringBuilder() << "SchemeCache response error " << static_cast(CacheResult->Request.Get()->ResultSet.front().Status))); + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", TStringBuilder() << "SchemeCache response error " << static_cast(CacheResult->Request.Get()->ResultSet.front().Status))); } const auto& entry = CacheResult->Request.Get()->ResultSet.front(); NKikimrViewer::TMetaInfo metaInfo; @@ -191,110 +177,103 @@ class TJsonACL : public TViewerPipeClient { TStringStream json; TProtoToJson::ProtoToJson(json, metaInfo, JsonSettings); - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), json.Str())); + ReplyAndPassAway(GetHTTPOKJSON(json.Str())); } - void HandleTimeout() { - ReplyAndPassAway(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get())); - } -}; - -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( get: - tags: - - viewer - summary: ACL information - description: Returns information about ACL of an object - parameters: - - name: database - in: query - description: database name - type: string - required: false - - name: path - in: query - description: schema path - required: true - type: string - - name: merge_rules - in: query - description: merge access rights into access rules - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - properties: - Common: - type: object - properties: - Path: - type: string - Owner: - type: string - ACL: - type: array - items: - type: object - properties: - AccessType: - type: string - Subject: - type: string - AccessRules: - type: array - items: - type: string - AccessRights: - type: array - items: - type: string - InheritanceType: - type: array - items: - type: string - EffectiveACL: - type: array - items: - type: object - properties: - AccessType: - type: string - Subject: - type: string - AccessRules: - type: array - items: - type: string - AccessRights: - type: array - items: - type: string - InheritanceType: - type: array - items: - type: string - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout + tags: + - viewer + summary: ACL information + description: Returns information about ACL of an object + parameters: + - name: database + in: query + description: database name + type: string + required: false + - name: path + in: query + description: schema path + required: true + type: string + - name: merge_rules + in: query + description: merge access rights into access rules + type: boolean + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + Common: + type: object + properties: + Path: + type: string + Owner: + type: string + ACL: + type: array + items: + type: object + properties: + AccessType: + type: string + Subject: + type: string + AccessRules: + type: array + items: + type: string + AccessRights: + type: array + items: + type: string + InheritanceType: + type: array + items: + type: string + EffectiveACL: + type: array + items: + type: object + properties: + AccessType: + type: string + Subject: + type: string + AccessRules: + type: array + items: + type: string + AccessRights: + type: array + items: + type: string + InheritanceType: + type: array + items: + type: string + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); - )___"); - - return node; -} + return node; + } +}; } -} diff --git a/ydb/core/viewer/json_autocomplete.h b/ydb/core/viewer/viewer_autocomplete.h similarity index 88% rename from ydb/core/viewer/json_autocomplete.h rename to ydb/core/viewer/viewer_autocomplete.h index d9733e4550a1..396e5d98b111 100644 --- a/ydb/core/viewer/json_autocomplete.h +++ b/ydb/core/viewer/viewer_autocomplete.h @@ -1,16 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include - +#include "json_handlers.h" +#include "json_pipe_req.h" +#include "log.h" #include "query_autocomplete_helper.h" #include "viewer_request.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using TNavigate = NSchemeCache::TSchemeCacheNavigate; @@ -439,78 +434,58 @@ class TJsonAutocomplete : public TViewerPipeClient { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } - } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Autocomplete information", + .Description = "Returns autocomplete information about objects in the database" + }); + yaml.AddParameter({ + .Name = "database", + .Description = "database name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "table", + .Description = "table list", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "prefix", + .Description = "known part of the word", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "limit of entities", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "direct", + .Description = "force execution on current node", + .Type = "boolean", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: database - in: query - description: database name - required: false - type: string - - name: table - in: query - description: table list - required: false - type: string - - name: prefix - in: query - description: known part of the word - required: false - type: string - - name: limit - in: query - description: limit of entities - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: direct - in: query - description: force execution on current node - required: false - type: boolean - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Autocomplete information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns autocomplete information about objects in the database"; - } -}; - -} } diff --git a/ydb/core/viewer/json_browse.h b/ydb/core/viewer/viewer_browse.h similarity index 80% rename from ydb/core/viewer/json_browse.h rename to ydb/core/viewer/viewer_browse.h index 223e91571b6a..82bc218c97e6 100644 --- a/ydb/core/viewer/json_browse.h +++ b/ydb/core/viewer/viewer_browse.h @@ -1,21 +1,10 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include #include "browse.h" #include "browse_db.h" -#include "browse_pq.h" -#include +#include "json_handlers.h" #include "viewer.h" #include "wb_aggregate.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -199,56 +188,37 @@ class TJsonBrowse : public TActorBootstrapped { html << request << Endl; } } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: true - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Schema information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns brief information about schema object"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "obsolete", + .Summary = "Schema information", + .Description = "Returns brief information about schema object" + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + .Required = true + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean" + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean" + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer" + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; } -} diff --git a/ydb/core/viewer/viewer_bscontrollerinfo.h b/ydb/core/viewer/viewer_bscontrollerinfo.h new file mode 100644 index 000000000000..95b7c51be01a --- /dev/null +++ b/ydb/core/viewer/viewer_bscontrollerinfo.h @@ -0,0 +1,88 @@ +#pragma once +#include "json_handlers.h" +#include "json_pipe_req.h" +#include "viewer.h" + +namespace NKikimr::NViewer { + +using namespace NActors; + +class TJsonBSControllerInfo : public TViewerPipeClient { + using TThis = TJsonBSControllerInfo; + using TBase = TViewerPipeClient; + using TBase::ReplyAndPassAway; + TAutoPtr ControllerInfo; + TJsonSettings JsonSettings; + ui32 Timeout = 0; + +public: + TJsonBSControllerInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) + {} + + void Bootstrap() override { + const auto& params(Event->Get()->Request.GetParams()); + JsonSettings.EnumAsNumbers = !FromStringWithDefault(params.Get("enums"), false); + JsonSettings.UI64AsString = !FromStringWithDefault(params.Get("ui64"), false); + Timeout = FromStringWithDefault(params.Get("timeout"), 10000); + InitConfig(params); + RequestBSControllerInfo(); + Become(&TThis::StateRequestedInfo, TDuration::MilliSeconds(Timeout), new TEvents::TEvWakeup()); + } + + STATEFN(StateRequestedInfo) { + switch (ev->GetTypeRewrite()) { + hFunc(TEvBlobStorage::TEvResponseControllerInfo, Handle); + hFunc(TEvTabletPipe::TEvClientConnected, TBase::Handle); + cFunc(TEvents::TSystem::Wakeup, TBase::HandleTimeout); + } + } + + void Handle(TEvBlobStorage::TEvResponseControllerInfo::TPtr& ev) { + ControllerInfo = ev->Release(); + RequestDone(); + } + + void ReplyAndPassAway() override { + TStringStream json; + if (ControllerInfo != nullptr) { + TProtoToJson::ProtoToJson(json, ControllerInfo->Record); + } else { + json << "null"; + } + ReplyAndPassAway(GetHTTPOKJSON(json.Str())); + } + + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Storage controller information", + .Description = "Returns information about storage controller" + }); + yaml.AddParameter({ + .Name = "controller_id", + .Description = "storage controller identifier (tablet id)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; + } +}; + +} diff --git a/ydb/core/viewer/json_bsgroupinfo.h b/ydb/core/viewer/viewer_bsgroupinfo.h similarity index 75% rename from ydb/core/viewer/json_bsgroupinfo.h rename to ydb/core/viewer/viewer_bsgroupinfo.h index 24c05ffe5d7a..ba8f6a63835c 100644 --- a/ydb/core/viewer/json_bsgroupinfo.h +++ b/ydb/core/viewer/viewer_bsgroupinfo.h @@ -1,14 +1,7 @@ #pragma once -#include -#include -#include -#include -#include -#include "wb_merge.h" #include "json_wb_req.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template <> struct TWhiteboardInfo { @@ -55,19 +48,4 @@ struct TWhiteboardMergerComparator { using TJsonBSGroupInfo = TJsonWhiteboardRequest; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Storage groups information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about storage groups"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_capabilities.cpp b/ydb/core/viewer/viewer_capabilities.cpp deleted file mode 100644 index ee96e078bb96..000000000000 --- a/ydb/core/viewer/viewer_capabilities.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include "viewer.h" -#include "json_handlers.h" -#include "json_pipe_req.h" - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; - -class TViewerCapabilities : public TViewerPipeClient { -public: - using TThis = TViewerCapabilities; - using TBase = TViewerPipeClient; - - TViewerCapabilities(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) - : TBase(viewer, ev) - {} - - void Bootstrap() override { - ReplyAndPassAway(); - } - - void ReplyAndPassAway() override { - NJson::TJsonValue json; - json["Capabilities"] = Viewer->GetCapabilities(); - TBase::ReplyAndPassAway(GetHTTPOKJSON(NJson::WriteJson(json, false))); - } -}; - -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - post: - tags: - - viewer - summary: Viewer capabilities - description: Viewer capabilities - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - description: format depends on schema parameter - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - return node; -} - - -void InitViewerCapabilitiesJsonHandler(TJsonHandlers& jsonHandlers) { - jsonHandlers.AddHandler("/viewer/capabilities", new TJsonHandler()); -} - -} // namespace NViewer -} // namespace NKikimr diff --git a/ydb/core/viewer/viewer_capabilities.h b/ydb/core/viewer/viewer_capabilities.h new file mode 100644 index 000000000000..3804ecbede94 --- /dev/null +++ b/ydb/core/viewer/viewer_capabilities.h @@ -0,0 +1,28 @@ +#pragma once +#include "json_pipe_req.h" + +namespace NKikimr::NViewer { + +using namespace NActors; + +class TViewerCapabilities : public TViewerPipeClient { +public: + using TThis = TViewerCapabilities; + using TBase = TViewerPipeClient; + + TViewerCapabilities(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TBase(viewer, ev) + {} + + void Bootstrap() override { + ReplyAndPassAway(); + } + + void ReplyAndPassAway() override { + NJson::TJsonValue json; + json["Capabilities"] = Viewer->GetCapabilities(); + TBase::ReplyAndPassAway(GetHTTPOKJSON(json)); + } +}; + +} diff --git a/ydb/core/viewer/viewer_check_access.h b/ydb/core/viewer/viewer_check_access.h new file mode 100644 index 000000000000..55c088413111 --- /dev/null +++ b/ydb/core/viewer/viewer_check_access.h @@ -0,0 +1,208 @@ +#pragma once +#include "json_handlers.h" +#include "json_pipe_req.h" +#include "log.h" +#include + +namespace NKikimr::NViewer { + +using namespace NActors; +using TNavigate = NSchemeCache::TSchemeCacheNavigate; + +class TCheckAccess : public TViewerPipeClient { + using TThis = TCheckAccess; + using TBase = TViewerPipeClient; + using TBase::ReplyAndPassAway; + TAutoPtr CacheResult; + TVector Permissions; + +public: + TCheckAccess(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) + {} + + void Bootstrap() override { + const auto& params(Event->Get()->Request.GetParams()); + ui32 timeout = FromStringWithDefault(params.Get("timeout"), 10000); + TString database; + if (params.Has("database")) { + database = params.Get("database"); + } else { + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "field 'database' is required")); + } + if (database && database != AppData()->TenantName) { + BLOG_TRACE("Requesting StateStorageEndpointsLookup for " << database); + RequestStateStorageEndpointsLookup(database); // to find some dynamic node and redirect query there + } else { + if (params.Has("permissions")) { + Split(params.Get("permissions"), ",", Permissions); + } else { + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "field 'permissions' is required")); + } + if (params.Has("path")) { + RequestSchemeCacheNavigate(params.Get("path")); + } else { + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "field 'path' is required")); + } + } + Become(&TThis::StateRequestedNavigate, TDuration::MilliSeconds(timeout), new TEvents::TEvWakeup()); + } + + void Handle(TEvStateStorage::TEvBoardInfo::TPtr& ev) { + BLOG_TRACE("Received TEvBoardInfo"); + ReplyAndPassAway(Viewer->MakeForward(Event->Get(), GetNodesFromBoardReply(ev))); + } + + STATEFN(StateRequestedNavigate) { + switch (ev->GetTypeRewrite()) { + hFunc(TEvStateStorage::TEvBoardInfo, Handle); + hFunc(TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle); + cFunc(TEvents::TSystem::Wakeup, HandleTimeout); + } + } + + void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev) { + CacheResult = ev->Release(); + RequestDone(); + } + + ui32 GetAccessType(const TString& permission) { + TACLAttrs attrs(0); + try { + attrs = ConvertYdbPermissionNameToACLAttrs(permission); + } + catch (const std::exception&) { + } + return attrs.AccessMask; + } + + bool CheckAccessPermission(const NACLib::TSecurityObject* object, const NACLib::TUserToken* token, const TString& permission) { + const auto& kikimrRunConfig = Viewer->GetKikimrRunConfig(); + const auto& securityConfig = kikimrRunConfig.AppConfig.GetDomainsConfig().GetSecurityConfig(); + if (!securityConfig.GetEnforceUserTokenRequirement()) { + if (!securityConfig.GetEnforceUserTokenCheckRequirement() || token == nullptr) { + return true; + } + } + if (token == nullptr) { + return false; + } + if (object == nullptr) { + return false; + } + ui32 access = GetAccessType(permission); + if (access == 0) { + return false; + } + return object->CheckAccess(access, *token); + } + + void ReplyAndPassAway() override { + std::unique_ptr token; + if (Event->Get()->UserToken) { + token = std::make_unique(Event->Get()->UserToken); + } + if (CacheResult == nullptr) { + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "no SchemeCache response")); + } + if (CacheResult->Request == nullptr) { + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "wrong SchemeCache response")); + } + if (CacheResult->Request.Get()->ResultSet.empty()) { + return ReplyAndPassAway(GetHTTPINTERNALERROR("text/plain", "SchemeCache response is empty")); + } + if (CacheResult->Request.Get()->ErrorCount != 0) { + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", TStringBuilder() << "SchemeCache response error " << static_cast(CacheResult->Request.Get()->ResultSet.front().Status))); + } + + + auto object = CacheResult->Request.Get()->ResultSet.front().SecurityObject; + + NJson::TJsonValue json(NJson::JSON_MAP); + + for (const TString& permission : Permissions) { + json[permission] = CheckAccessPermission(object.Get(), token.get(), permission); + } + + ReplyAndPassAway(GetHTTPOKJSON(json)); + } + + void HandleTimeout() { + ReplyAndPassAway(GetHTTPGATEWAYTIMEOUT("text/plain", "Timeout receiving SchemeCache response")); + } + + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - viewer + summary: Check access + description: Check access to the specified path + parameters: + - name: database + in: query + description: database name + type: string + required: true + - name: path + in: query + description: path to check access + type: string + required: true + - name: permissions + in: query + description: permissions to check + required: true + type: array + items: + type: string + enum: + - ydb.database.connect + - ydb.tables.modify + - ydb.tables.read + - ydb.generic.list + - ydb.generic.read + - ydb.generic.write + - ydb.generic.use_legacy + - ydb.generic.use + - ydb.generic.manage + - ydb.generic.full_legacy + - ydb.generic.full + - ydb.database.create + - ydb.database.drop + - ydb.access.grant + - ydb.granular.select_row + - ydb.granular.update_row + - ydb.granular.erase_row + - ydb.granular.read_attributes + - ydb.granular.write_attributes + - ydb.granular.create_directory + - ydb.granular.create_table + - ydb.granular.create_queue + - ydb.granular.remove_schema + - ydb.granular.describe_schema + - ydb.granular.alter_schema + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + + return node; + } +}; + +} diff --git a/ydb/core/viewer/json_cluster.h b/ydb/core/viewer/viewer_cluster.h similarity index 88% rename from ydb/core/viewer/json_cluster.h rename to ydb/core/viewer/viewer_cluster.h index c1e7d6e421df..d78f7a2b4d91 100644 --- a/ydb/core/viewer/json_cluster.h +++ b/ydb/core/viewer/viewer_cluster.h @@ -1,23 +1,16 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "json_pipe_req.h" #include "viewer.h" -#include "viewer_probes.h" +#include "viewer_bsgroupinfo.h" +#include "viewer_pdiskinfo.h" +#include "viewer_tabletinfo.h" +#include "viewer_vdiskinfo.h" -LWTRACE_USING(VIEWER_PROVIDER); - -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; -using ::google::protobuf::FieldDescriptor; class TJsonCluster : public TViewerPipeClient { using TThis = TJsonCluster; @@ -462,20 +455,6 @@ class TJsonCluster : public TViewerPipeClient { TProtoToJson::ProtoToJson(json, pbCluster, JsonSettings); Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), std::move(json.Str())), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - const TInstant now = TActivationContext::Now(); - LWPROBE(ViewerClusterHandler, TBase::SelfId().NodeId(), Tablets, EventLog.IsTimeout, - EventLog.StartTime.MilliSeconds(), - (now - EventLog.StartTime).MilliSeconds(), - (EventLog.StartHandleListTenantsResponseTime - EventLog.StartTime).MilliSeconds(), - (EventLog.StartHandleNodesInfoTime - EventLog.StartTime).MilliSeconds(), - (EventLog.StartMergeBSGroupsTime - EventLog.StartTime).MilliSeconds(), - (EventLog.StartMergeVDisksTime - EventLog.StartMergeBSGroupsTime).MilliSeconds(), - (EventLog.StartMergePDisksTime - EventLog.StartMergeVDisksTime).MilliSeconds(), - (EventLog.StartMergeTabletsTime - EventLog.StartMergePDisksTime).MilliSeconds(), - (EventLog.StartResponseBuildingTime - EventLog.StartMergeTabletsTime).MilliSeconds(), - (now - EventLog.StartResponseBuildingTime).MilliSeconds() - ); - PassAway(); } @@ -483,56 +462,37 @@ class TJsonCluster : public TViewerPipeClient { EventLog.IsTimeout = true; ReplyAndPassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: tablets - in: query - description: return system tablets state - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Cluster information"; - } -}; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about cluster"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Cluster information", + .Description = "Returns information about cluster" + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "tablets", + .Description = "return system tablets state", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; } -} diff --git a/ydb/core/viewer/json_compute.h b/ydb/core/viewer/viewer_compute.h similarity index 89% rename from ydb/core/viewer/json_compute.h rename to ydb/core/viewer/viewer_compute.h index 21ac3f0a60ea..19ff4a470cbe 100644 --- a/ydb/core/viewer/json_compute.h +++ b/ydb/core/viewer/viewer_compute.h @@ -1,25 +1,13 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" -#include "viewer_helper.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include "log.h" +#include "viewer_helper.h" +#include "viewer_tabletinfo.h" #include "wb_aggregate.h" #include "wb_merge.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -617,91 +605,72 @@ class TJsonCompute : public TViewerPipeClient { Result.AddErrors("Timeout occurred"); ReplyAndPassAway(); } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Compute information", + .Description = "Returns information about compute layer of database", + }); + yaml.AddParameter({ + .Name = "version", + .Description = "query version (v1, v2)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "uptime", + .Description = "return only nodes with less uptime in sec.", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "problems_only", + .Description = "return only problem nodes", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "filter", + .Description = "filter nodes by id or host", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "sort", + .Description = "sort by (NodeId,Host,DC,Rack,Version,Uptime,Memory,CPU,LoadAverage)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "offset", + .Description = "skip N nodes", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "limit to N nodes", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: version - in: query - description: query version (v1, v2) - required: false - type: string - - name: path - in: query - description: schema path - required: false - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: uptime - in: query - description: return only nodes with less uptime in sec. - required: false - type: integer - - name: problems_only - in: query - description: return only problem nodes - required: false - type: boolean - - name: filter - in: query - description: filter nodes by id or host - required: false - type: string - - name: sort - in: query - description: sort by (NodeId,Host,DC,Rack,Version,Uptime,Memory,CPU,LoadAverage) - required: false - type: string - - name: offset - in: query - description: skip N nodes - required: false - type: integer - - name: limit - in: query - description: limit to N nodes - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Database compute information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about compute layer of database"; - } -}; - -} } diff --git a/ydb/core/viewer/json_config.h b/ydb/core/viewer/viewer_config.h similarity index 62% rename from ydb/core/viewer/json_config.h rename to ydb/core/viewer/viewer_config.h index e239c82fc4f8..b8e68bcd305e 100644 --- a/ydb/core/viewer/json_config.h +++ b/ydb/core/viewer/viewer_config.h @@ -1,14 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -38,28 +34,17 @@ class TJsonConfig : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), json.Str()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Configuration"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Configuration", + .Description = "Returns configuration", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns configuration"; - } -}; - -} } diff --git a/ydb/core/viewer/json_content.h b/ydb/core/viewer/viewer_content.h similarity index 70% rename from ydb/core/viewer/json_content.h rename to ydb/core/viewer/viewer_content.h index 0d9399d36022..1ce656981f29 100644 --- a/ydb/core/viewer/json_content.h +++ b/ydb/core/viewer/viewer_content.h @@ -1,17 +1,10 @@ -#pragma once -#include -#include -#include -#include -#include -#include "viewer.h" #include "browse.h" +#include "json_handlers.h" +#include "viewer.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; -using ::google::protobuf::FieldDescriptor; class TJsonContent : public TActorBootstrapped { using TThis = TJsonContent; @@ -135,65 +128,52 @@ class TJsonContent : public TActorBootstrapped { Die(ctx); } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: true - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: key - in: query - description: key for positioning - required: false - type: string - - name: limit - in: query - description: rows limit - required: false - type: integer - - name: offset - in: query - description: offset in rows - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Schema content preview"; - } -}; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Return schema preview"; +public: + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "obsolete", + .Summary = "Schema content preview", + .Description = "Return schema preview" + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "key", + .Description = "key for positioning", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "rows limit", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "offset", + .Description = "offset in rows", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + return yaml; } }; - -} } diff --git a/ydb/core/viewer/json_counters.h b/ydb/core/viewer/viewer_counters.h similarity index 97% rename from ydb/core/viewer/json_counters.h rename to ydb/core/viewer/viewer_counters.h index 8ad296bcbe43..6bb10f92d5ce 100644 --- a/ydb/core/viewer/json_counters.h +++ b/ydb/core/viewer/viewer_counters.h @@ -1,14 +1,12 @@ #pragma once -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "viewer.h" -#include "json_tabletinfo.h" +#include "viewer_bsgroupinfo.h" +#include "viewer_pdiskinfo.h" +#include "viewer_tabletinfo.h" +#include "viewer_vdiskinfo.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using ::google::protobuf::FieldDescriptor; @@ -433,7 +431,17 @@ class TJsonCounters : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } + + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "counters", + .Description = "counters", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; + } }; } -} diff --git a/ydb/core/viewer/json_describe.h b/ydb/core/viewer/viewer_describe.h similarity index 78% rename from ydb/core/viewer/json_describe.h rename to ydb/core/viewer/viewer_describe.h index 27280609dda4..bac7c46aec89 100644 --- a/ydb/core/viewer/json_describe.h +++ b/ydb/core/viewer/viewer_describe.h @@ -1,17 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include "log.h" +#include "viewer.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using NSchemeShard::TEvSchemeShard; @@ -20,8 +14,7 @@ using TNavigate = NSchemeCache::TSchemeCacheNavigate; class TJsonDescribe : public TViewerPipeClient { using TThis = TJsonDescribe; using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; + using TBase::ReplyAndPassAway; TAutoPtr SchemeShardResult; TAutoPtr CacheResult; TAutoPtr DescribeResult; @@ -31,9 +24,8 @@ class TJsonDescribe : public TViewerPipeClient { int Requests = 0; public: - TJsonDescribe(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonDescribe(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) {} void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { @@ -269,8 +261,7 @@ class TJsonDescribe : public TViewerPipeClient { json << "null"; } - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), json.Str()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + ReplyAndPassAway(GetHTTPOKJSON(json.Str())); } void DecodeExternalTableContent(TStringStream& json) const { @@ -310,111 +301,91 @@ class TJsonDescribe : public TViewerPipeClient { } void HandleTimeout() { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + ReplyAndPassAway(GetHTTPGATEWAYTIMEOUT()); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: false - type: string - - name: schemeshard_id - in: query - description: schemeshard identifier (tablet id) - required: false - type: integer - - name: path_id - in: query - description: path id - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: backup - in: query - description: return backup information - required: false - type: boolean - default: true - - name: private - in: query - description: return private tables - required: false - type: boolean - default: true - - name: children - in: query - description: return children - required: false - type: boolean - default: true - - name: boundaries - in: query - description: return boundaries - required: false - type: boolean - default: false - - name: partition_config - in: query - description: return partition configuration - required: false - type: boolean - default: true - - name: partition_stats - in: query - description: return partitions statistics - required: false - type: boolean - default: false - - name: partitioning_info - in: query - description: return partitioning information - required: false - type: boolean - default: true - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Schema detailed information", + .Description = "Returns detailed information about schema object" + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "schemeshard_id", + .Description = "schemeshard identifier (tablet id)", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "path_id", + .Description = "path id", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "backup", + .Description = "return backup information", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "private", + .Description = "return private tables", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "children", + .Description = "return children", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "boundaries", + .Description = "return boundaries", + .Type = "boolean", + .Default = "false", + }); + yaml.AddParameter({ + .Name = "partition_config", + .Description = "return partition configuration", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "partition_stats", + .Description = "return partitions statistics", + .Type = "boolean", + .Default = "false", + }); + yaml.AddParameter({ + .Name = "partitioning_info", + .Description = "return partitioning information", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Schema detailed information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns detailed information about schema object"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_describe_consumer.h b/ydb/core/viewer/viewer_describe_consumer.h new file mode 100644 index 000000000000..bdc4f0d84516 --- /dev/null +++ b/ydb/core/viewer/viewer_describe_consumer.h @@ -0,0 +1,105 @@ +#pragma once +#include "json_handlers.h" +#include "json_local_rpc.h" +#include +#include + +namespace NKikimr::NViewer { + +using TDescribeConsumerRpc = TJsonLocalRpc; + +class TJsonDescribeConsumer : public TDescribeConsumerRpc { +public: + using TBase = TDescribeConsumerRpc; + + TJsonDescribeConsumer(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TBase(viewer, ev) + {} + + void Bootstrap() override { + if (Event->Get()->Request.GetMethod() != HTTP_METHOD_GET) { + return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "Only GET method is allowed")); + } + const auto& params(Event->Get()->Request.GetParams()); + if (params.Has("database")) { + Database = params.Get("database"); + } else if (params.Has("database_path")) { + Database = params.Get("database_path"); + } else { + return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'database' is required")); + } + + if (params.Has("consumer")) { + Request.set_consumer(params.Get("consumer")); + } else { + return ReplyAndPassAway(Viewer->GetHTTPBADREQUEST(Event->Get(), "text/plain", "field 'consumer' is required")); + } + + if (params.Has("include_stats")) { + Request.set_include_stats(FromStringWithDefault(params.Get("include_stats"), false)); + } + + TBase::Bootstrap(); + } + + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - viewer + summary: Topic schema detailed information + description: Returns detailed information about topic + parameters: + - name: database + in: query + description: database name + required: true + type: string + - name: consumer + in: query + description: consumer name + required: true + type: string + - name: include_stats + in: query + description: include stat flag + required: false + type: bool + - name: timeout + in: query + description: timeout in ms + required: false + type: integer + - name: enums + in: query + description: convert enums to strings + required: false + type: boolean + - name: ui64 + in: query + description: return ui64 as number + required: false + type: boolean + responses: + 200: + description: OK + content: + application/json: + schema: {} + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); + return node; + } +}; + +} diff --git a/ydb/core/viewer/json_describe_topic.h b/ydb/core/viewer/viewer_describe_topic.h similarity index 50% rename from ydb/core/viewer/json_describe_topic.h rename to ydb/core/viewer/viewer_describe_topic.h index 2a7a8fb418dc..5e94d20097b5 100644 --- a/ydb/core/viewer/json_describe_topic.h +++ b/ydb/core/viewer/viewer_describe_topic.h @@ -1,10 +1,9 @@ -#pragma once -#include -#include +#include "json_handlers.h" #include "json_local_rpc.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using TDescribeTopicRpc = TJsonLocalRpc -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( - get: - tags: - - viewer - summary: Topic schema detailed information - description: Returns detailed information about topic - parameters: - - name: database - in: query - description: database name - required: true - type: string - - name: path - in: query - description: schema path - required: true - type: string - - name: include_stats - in: query - description: include stat flag - required: false - type: bool - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - responses: - 200: - description: OK - content: - application/json: - schema: {} - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema(); - return node; -} + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Topic schema detailed information", + .Description = "Returns detailed information about topic", + }); + yaml.AddParameter({ + .Name = "database", + .Description = "database name", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "include_stats", + .Description = "include stat flag", + .Type = "bool", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Required = false, + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; + } +}; } -} diff --git a/ydb/core/viewer/json_graph.h b/ydb/core/viewer/viewer_graph.h similarity index 60% rename from ydb/core/viewer/json_graph.h rename to ydb/core/viewer/viewer_graph.h index 20fa68980227..de5de41ba1da 100644 --- a/ydb/core/viewer/json_graph.h +++ b/ydb/core/viewer/viewer_graph.h @@ -1,33 +1,27 @@ #pragma once -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" +#include "json_pipe_req.h" #include "log.h" +#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; -class TJsonGraph : public TActorBootstrapped { - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; +class TJsonGraph : public TViewerPipeClient { + using TThis = TJsonGraph; + using TBase = TViewerPipeClient; + using TBase::ReplyAndPassAway; std::vector Metrics; public: - static constexpr NKikimrServices::TActivity::EType ActorActivityType() { - return NKikimrServices::TActivity::VIEWER_HANDLER; - } - - TJsonGraph(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonGraph(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) {} - void Bootstrap() { + void Bootstrap() override { BLOG_TRACE("Graph received request for " << Event->Get()->Request.GetUri()); const auto& params(Event->Get()->Request.GetParams()); NKikimrGraph::TEvGetMetrics getRequest; @@ -37,8 +31,7 @@ class TJsonGraph : public TActorBootstrapped { getRequest.AddMetrics(metric); } } else { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPBADREQUEST(Event->Get(), {}, "Bad Request"), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return PassAway(); + return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "no 'target' parameter specified")); } if (params.Has("from")) { getRequest.SetTimeFrom(FromStringWithDefault(params.Get("from"))); @@ -57,7 +50,7 @@ class TJsonGraph : public TActorBootstrapped { STATEFN(StateWork) { switch (ev->GetTypeRewrite()) { hFunc(NGraph::TEvGraph::TEvMetricsResult, Handle); - cFunc(TEvents::TSystem::Wakeup, Timeout); + cFunc(TEvents::TSystem::Wakeup, HandleTimeout); } } @@ -69,22 +62,19 @@ class TJsonGraph : public TActorBootstrapped { if (response.GetError()) { json["status"] = "error"; json["error"] = response.GetError(); - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false)), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return PassAway(); + return ReplyAndPassAway(GetHTTPOKJSON(json)); } if (response.DataSize() != Metrics.size()) { json["status"] = "error"; json["error"] = "Invalid data size received"; - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false)), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return PassAway(); + return ReplyAndPassAway(GetHTTPOKJSON(json)); } for (size_t nMetric = 0; nMetric < response.DataSize(); ++nMetric) { const auto& protoMetric(response.GetData(nMetric)); if (response.TimeSize() != protoMetric.ValuesSize()) { json["status"] = "error"; json["error"] = "Invalid value size received"; - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false)), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - return PassAway(); + return ReplyAndPassAway(GetHTTPOKJSON(json)); } } if (!params.Has("format") || params.Get("format") == "graphite") { // graphite @@ -133,62 +123,46 @@ class TJsonGraph : public TActorBootstrapped { } } - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false)), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + ReplyAndPassAway(GetHTTPOKJSON(json)); } - void Timeout() { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: target - in: query - description: metrics comma delimited - required: true - type: string - - name: from - in: query - description: time in seconds - required: false - type: integer - - name: until - in: query - description: time in seconds - required: false - type: integer - - name: maxDataPoints - in: query - description: maximum number of data points - required: false - type: integer - - name: format - in: query - description: response format, could be prometheus or graphite - required: false - type: string - )___"); - } -}; + void ReplyAndPassAway() override {} -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Graph data"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Graph data", + .Description = "Returns graph data", + }); + yaml.AddParameter({ + .Name = "target", + .Description = "metrics comma delimited", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "from", + .Description = "time in seconds", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "until", + .Description = "time in seconds", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "maxDataPoints", + .Description = "maximum number of data points", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "format", + .Description = "response format, could be prometheus or graphite", + .Type = "string", + }); + return yaml; } }; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns graph data"; - } -}; - -} } diff --git a/ydb/core/viewer/json_healthcheck.h b/ydb/core/viewer/viewer_healthcheck.h similarity index 78% rename from ydb/core/viewer/json_healthcheck.h rename to ydb/core/viewer/viewer_healthcheck.h index 1d0d54415ad8..6bd447ef6b82 100644 --- a/ydb/core/viewer/json_healthcheck.h +++ b/ydb/core/viewer/viewer_healthcheck.h @@ -1,24 +1,15 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include "healthcheck_record.h" +#include "json_handlers.h" +#include "json_pipe_req.h" #include "viewer.h" -#include -#include -#include #include -#include -#include "json_pipe_req.h" -#include "healthcheck_record.h" -#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; +using namespace NMonitoring; enum HealthCheckResponseFormat { JSON, @@ -99,7 +90,10 @@ class TJsonHealthCheck : public TViewerPipeClient { JsonSettings.EnumAsNumbers = !FromStringWithDefault(params.Get("enums"), true); JsonSettings.UI64AsString = !FromStringWithDefault(params.Get("ui64"), false); } - Database = params.Get("tenant"); + Database = params.Get("database"); + if (Database.empty()) { + Database = params.Get("tenant"); + } Cache = FromStringWithDefault(params.Get("cache"), Cache); MergeRecords = FromStringWithDefault(params.Get("merge_records"), MergeRecords); Timeout = FromStringWithDefault(params.Get("timeout"), 10000); @@ -252,86 +246,67 @@ class TJsonHealthCheck : public TViewerPipeClient { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: tenant - in: query - description: path to database - required: false - type: string - - name: cache - in: query - description: use cache - required: false - type: boolean - - name: verbose - in: query - description: return verbose status - required: false - type: boolean - - name: merge_records - in: query - description: merge records - required: false - type: boolean - - name: max_level - in: query - description: max depth of issues to return - required: false - type: integer - - name: min_status - in: query - description: min status of issues to return - required: false - type: string - - name: format - in: query - description: format of reply - required: false - type: string - )___"); - } -}; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Self-check result"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Self-check result", + .Description = "Performs self-check and returns result", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "database", + .Description = "database name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "cache", + .Description = "use cache", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "verbose", + .Description = "return verbose status", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "merge_records", + .Description = "merge records", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "max_level", + .Description = "max depth of issues to return", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "min_status", + .Description = "min status of issues to return", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "format", + .Description = "format of reply", + .Type = "string", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Performs self-check and returns result"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_helper.h b/ydb/core/viewer/viewer_helper.h index 1d92ac7570f1..2786e410ef03 100644 --- a/ydb/core/viewer/viewer_helper.h +++ b/ydb/core/viewer/viewer_helper.h @@ -1,5 +1,4 @@ #pragma once - #include namespace NKikimr::NViewer { diff --git a/ydb/core/viewer/json_hiveinfo.h b/ydb/core/viewer/viewer_hiveinfo.h similarity index 51% rename from ydb/core/viewer/json_hiveinfo.h rename to ydb/core/viewer/viewer_hiveinfo.h index a93458369d3c..197024042701 100644 --- a/ydb/core/viewer/json_hiveinfo.h +++ b/ydb/core/viewer/viewer_hiveinfo.h @@ -1,33 +1,24 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" -#include +#include "viewer.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; class TJsonHiveInfo : public TViewerPipeClient { using TThis = TJsonHiveInfo; using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; + using TBase::ReplyAndPassAway; TAutoPtr HiveInfo; TJsonSettings JsonSettings; ui32 Timeout = 0; TNodeId NodeId = 0; public: - TJsonHiveInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonHiveInfo(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) {} void Bootstrap() override { @@ -88,84 +79,60 @@ class TJsonHiveInfo : public TViewerPipeClient { } else { json << "null"; } - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), json.Str()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - } - - void HandleTimeout() { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + ReplyAndPassAway(GetHTTPOKJSON(json.Str())); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: hive_id - in: query - description: hive identifier (tablet id) - required: true - type: string - - name: tablet_id - in: query - description: tablet id filter - required: false - type: string - - name: tablet_type - in: query - description: tablet type filter - required: false - type: string - - name: followers - in: query - description: return followers - required: false - type: boolean - - name: metrics - in: query - description: return tablet metrics - required: false - type: boolean - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Hive Info", + .Description = "Returns information about the hive", + }); + yaml.AddParameter({ + .Name = "hive_id", + .Description = "hive identifier (tablet id)", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "tablet_id", + .Description = "tablet id filter", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "tablet_type", + .Description = "tablet type filter", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "followers", + .Description = "return followers", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "metrics", + .Description = "return tablet metrics", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Hive information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about tablets from Hive"; - } -}; - -} } diff --git a/ydb/core/viewer/json_hivestats.h b/ydb/core/viewer/viewer_hivestats.h similarity index 56% rename from ydb/core/viewer/json_hivestats.h rename to ydb/core/viewer/viewer_hivestats.h index d1529630df59..80cee5c512a1 100644 --- a/ydb/core/viewer/json_hivestats.h +++ b/ydb/core/viewer/viewer_hivestats.h @@ -1,16 +1,8 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" -#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -74,66 +66,47 @@ class TJsonHiveStats : public TViewerPipeClient { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: hive_id - in: query - description: hive identifier (tablet id) - required: true - type: string - - name: followers - in: query - description: return followers - required: false - type: boolean - - name: metrics - in: query - description: return tablet metrics - required: false - type: boolean - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Hive statistics", + .Description = "Returns information about Hive statistics", + }); + yaml.AddParameter({ + .Name = "hive_id", + .Description = "hive identifier (tablet id)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "followers", + .Description = "return followers", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "metrics", + .Description = "return tablet metrics", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Hive statistics"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about Hive statistics"; - } -}; - -} } diff --git a/ydb/core/viewer/json_hotkeys.h b/ydb/core/viewer/viewer_hotkeys.h similarity index 79% rename from ydb/core/viewer/json_hotkeys.h rename to ydb/core/viewer/viewer_hotkeys.h index a0e67a5d8389..4fef525e7c9f 100644 --- a/ydb/core/viewer/json_hotkeys.h +++ b/ydb/core/viewer/viewer_hotkeys.h @@ -1,18 +1,9 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using NSchemeShard::TEvSchemeShard; @@ -21,8 +12,7 @@ class TJsonHotkeys : public TViewerPipeClient { static const bool WithRetry = false; using TThis = TJsonHotkeys; using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; + using TBase::ReplyAndPassAway; TAutoPtr DescribeResult; ui32 Timeout = 0; ui32 Limit = 0; @@ -38,9 +28,8 @@ class TJsonHotkeys : public TViewerPipeClient { TMultiSet>, KeysComparator> Keys; public: - TJsonHotkeys(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonHotkeys(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) {} void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { @@ -142,25 +131,49 @@ class TJsonHotkeys : public TViewerPipeClient { if (DescribeResult != nullptr) { switch (DescribeResult->GetRecord().GetStatus()) { case NKikimrScheme::StatusAccessDenied: - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPFORBIDDEN(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); - return; + return ReplyAndPassAway(GetHTTPFORBIDDEN()); default: break; } } NJson::TJsonValue root = BuildResponse(); - TString json = NJson::WriteJson(root, false); - - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), json), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + ReplyAndPassAway(GetHTTPOKJSON(root)); } - void HandleTimeout() { - Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); - PassAway(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Information about current hot keys in a datashard", + .Description = "Samples and returns information about current hot keys", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "path to the table", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enable_sampling", + .Description = "enable sampling", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "polling_factor", + .Description = "polling factor", + .Type = "float", + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "limit of hot keys", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + return yaml; } }; } -} diff --git a/ydb/core/viewer/json_labeledcounters.h b/ydb/core/viewer/viewer_labeled_counters.h similarity index 69% rename from ydb/core/viewer/json_labeledcounters.h rename to ydb/core/viewer/viewer_labeled_counters.h index c8ea014b6205..f2a9272d30c1 100644 --- a/ydb/core/viewer/json_labeledcounters.h +++ b/ydb/core/viewer/viewer_labeled_counters.h @@ -1,15 +1,12 @@ #pragma once -#include -#include -#include -#include +#include "json_handlers.h" +#include "viewer.h" #include -#include #include -#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -47,7 +44,7 @@ class TJsonLabeledCounters : public TActorBootstrapped { Topic = NPersQueue::ConvertNewTopicName(params.Get("topic")); if (Topic.empty()) Topic = "*"; - Consumer = NPersQueue::ConvertNewConsumerName(params.Get("consumer"), ctx); + Consumer = NPersQueue::ConvertNewConsumerName(params.Get("consumer")); DC = params.Get("dc"); if (DC.empty()) DC = "*"; @@ -145,93 +142,71 @@ class TJsonLabeledCounters : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: group - in: query - description: group name - required: false - type: string - - name: dc - in: query - description: datacenter name - required: false - type: string - default: "*" - - name: topic - in: query - description: topic name - required: false - type: string - default: "*" - - name: consumer - in: query - description: consumer name - required: false - type: string - default: "" - - name: group_names - in: query - description: group names - required: false - type: string - - name: counters - in: query - description: counters names - required: false - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - default: false - - name: all - in: query - description: return information about all topics and clients - required: false - type: boolean - default: false - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - default: false - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - default: 10000 - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Labeled counters info", + .Description = "Returns information about labeled counters", + }); + yaml.AddParameter({ + .Name = "group", + .Description = "group name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "dc", + .Description = "datacenter name", + .Type = "string", + .Default = "*", + }); + yaml.AddParameter({ + .Name = "topic", + .Description = "topic name", + .Type = "string", + .Default = "*", + }); + yaml.AddParameter({ + .Name = "consumer", + .Description = "consumer name", + .Type = "string", + .Default = "", + }); + yaml.AddParameter({ + .Name = "group_names", + .Description = "group names", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "counters", + .Description = "counters names", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "all", + .Description = "return information about all topics and clients", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + .Default = "10000", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Labeled counters info"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about labeled counters"; - } -}; - -} } diff --git a/ydb/core/viewer/json_metainfo.h b/ydb/core/viewer/viewer_metainfo.h similarity index 66% rename from ydb/core/viewer/json_metainfo.h rename to ydb/core/viewer/viewer_metainfo.h index b96a26a4478a..dcd7a12629e4 100644 --- a/ydb/core/viewer/json_metainfo.h +++ b/ydb/core/viewer/viewer_metainfo.h @@ -1,25 +1,9 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "browse.h" -#include +#include "json_handlers.h" #include "viewer.h" #include "wb_aggregate.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -124,66 +108,42 @@ class TJsonMetaInfo : public TActorBootstrapped { html << request << Endl; } } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: false - type: string - - name: tablet_id - in: query - description: tablet identifier - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: counters - in: query - description: return tablet counters - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "obsolete", + .Summary = "Schema meta information", + .Description = "Returns meta information about schema path", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "counters", + .Description = "return tablet counters", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Schema meta information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns meta information about schema path"; - } -}; - -} } diff --git a/ydb/core/viewer/json_netinfo.h b/ydb/core/viewer/viewer_netinfo.h similarity index 86% rename from ydb/core/viewer/json_netinfo.h rename to ydb/core/viewer/viewer_netinfo.h index c10cd7d745f5..edddfa3010b8 100644 --- a/ydb/core/viewer/json_netinfo.h +++ b/ydb/core/viewer/viewer_netinfo.h @@ -1,24 +1,11 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" +#include "viewer.h" #include "wb_aggregate.h" #include "wb_merge.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -294,61 +281,42 @@ class TJsonNetInfo : public TViewerPipeClient { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Network information", + .Description = "Returns network information", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "hive_id", + .Description = "hive identifier (tablet id)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: false - type: string - - name: hive_id - in: query - description: hive identifier (tablet id) - required: false - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Network information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns network information"; - } -}; - -} } diff --git a/ydb/core/viewer/json_nodeinfo.h b/ydb/core/viewer/viewer_nodeinfo.h similarity index 70% rename from ydb/core/viewer/json_nodeinfo.h rename to ydb/core/viewer/viewer_nodeinfo.h index ac1dbb04878d..5165a1c96442 100644 --- a/ydb/core/viewer/json_nodeinfo.h +++ b/ydb/core/viewer/viewer_nodeinfo.h @@ -1,14 +1,7 @@ #pragma once -#include -#include -#include -#include -#include -#include "wb_merge.h" #include "json_wb_req.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template <> struct TWhiteboardInfo { @@ -44,19 +37,4 @@ struct TWhiteboardInfo { using TJsonNodeInfo = TJsonWhiteboardRequest; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Interconnect information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about node connections"; - } -}; - -} } diff --git a/ydb/core/viewer/json_nodelist.h b/ydb/core/viewer/viewer_nodelist.h similarity index 70% rename from ydb/core/viewer/json_nodelist.h rename to ydb/core/viewer/viewer_nodelist.h index d1d3310f616e..d3b2963a1f4a 100644 --- a/ydb/core/viewer/json_nodelist.h +++ b/ydb/core/viewer/viewer_nodelist.h @@ -1,14 +1,11 @@ #pragma once +#include "json_handlers.h" +#include "viewer.h" +#include #include -#include -#include #include -#include -#include -#include "viewer.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -81,43 +78,37 @@ class TJsonNodeList : public TActorBootstrapped { void Timeout(const TActorContext &ctx) { ReplyAndDie(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return YAML::Load(R"___( - type: array - title: TEvNodeListResponse - items: - type: object - title: TNodeInfo - properties: - Id: - type: integer - Host: - type: string - Address: - type: string - Port: - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Nodes list"; - } -}; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns list of nodes"; + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( + get: + tags: + - viewer + summary: Nodes list + description: Returns list of nodes + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: array + title: TEvNodeListResponse + items: + type: object + title: TNodeInfo + properties: + Id: + type: integer + Host: + type: string + Address: + type: string + Port: + type: integer + )___"); + return node; } }; } -} diff --git a/ydb/core/viewer/json_nodes.h b/ydb/core/viewer/viewer_nodes.h similarity index 91% rename from ydb/core/viewer/json_nodes.h rename to ydb/core/viewer/viewer_nodes.h index e327d79d990c..3d305dd103e2 100644 --- a/ydb/core/viewer/json_nodes.h +++ b/ydb/core/viewer/viewer_nodes.h @@ -1,24 +1,16 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" +#include "json_pipe_req.h" +#include "log.h" #include "viewer.h" #include "viewer_helper.h" -#include "json_pipe_req.h" -#include "json_sysinfo.h" -#include "json_pdiskinfo.h" +#include "viewer_tabletinfo.h" +#include "wb_group.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; -using ::google::protobuf::FieldDescriptor; class TJsonNodes : public TViewerPipeClient { using TThis = TJsonNodes; @@ -709,8 +701,8 @@ class TJsonNodes : public TViewerPipeClient { return 0; } - static uint32 GetMissing(const NKikimrViewer::TNodeInfo& nodeInfo) { - uint32 missing = 0; + static ui32 GetMissing(const NKikimrViewer::TNodeInfo& nodeInfo) { + ui32 missing = 0; for (const auto& pDisk : nodeInfo.GetPDisks()) { if (pDisk.state() != NKikimrBlobStorage::TPDiskState::Normal) { missing++; @@ -924,106 +916,87 @@ class TJsonNodes : public TViewerPipeClient { void HandleTimeout() { ReplyAndPassAway(); } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Nodes info", + .Description = "Information about nodes", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as numbers", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "path to schema object", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "with", + .Description = "filter nodes by missing disks or space", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "type", + .Description = "nodes type to get (static,dynamic,any)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "storage", + .Description = "return storage info", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "tablets", + .Description = "return tablets info", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "sort", + .Description = "sort by (NodeId,Host,DC,Rack,Version,Uptime,Memory,CPU,LoadAverage,Missing)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "offset", + .Description = "skip N nodes", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "limit to N nodes", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "uptime", + .Description = "return only nodes with less uptime in sec.", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "problems_only", + .Description = "return only problem nodes", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "filter", + .Description = "filter nodes by id or host", + .Type = "string", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as numbers - required: false - type: boolean - - name: path - in: query - description: path to schema object - required: false - type: string - - name: with - in: query - description: filter nodes by missing disks or space - required: false - type: string - - name: type - in: query - description: nodes type to get (static,dynamic,any) - required: false - type: string - - name: storage - in: query - description: return storage info - required: false - type: boolean - - name: tablets - in: query - description: return tablets info - required: false - type: boolean - - name: sort - in: query - description: sort by (NodeId,Host,DC,Rack,Version,Uptime,Memory,CPU,LoadAverage,Missing) - required: false - type: string - - name: offset - in: query - description: skip N nodes - required: false - type: integer - - name: limit - in: query - description: limit to N nodes - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: uptime - in: query - description: return only nodes with less uptime in sec. - required: false - type: integer - - name: problems_only - in: query - description: return only problem nodes - required: false - type: boolean - - name: filter - in: query - description: filter nodes by id or host - required: false - type: string - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Nodes info"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Information about nodes"; - } -}; - -} } diff --git a/ydb/core/viewer/json_pdiskinfo.h b/ydb/core/viewer/viewer_pdiskinfo.h similarity index 69% rename from ydb/core/viewer/json_pdiskinfo.h rename to ydb/core/viewer/viewer_pdiskinfo.h index 5a2ff46edc2f..7c85393e667b 100644 --- a/ydb/core/viewer/json_pdiskinfo.h +++ b/ydb/core/viewer/viewer_pdiskinfo.h @@ -1,13 +1,7 @@ #pragma once -#include -#include -#include -#include -#include #include "json_wb_req.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template <> struct TWhiteboardInfo { @@ -41,19 +35,4 @@ struct TWhiteboardInfo { using TJsonPDiskInfo = TJsonWhiteboardRequest; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "PDisk information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns PDisk information"; - } -}; - -} } diff --git a/ydb/core/viewer/json_pqconsumerinfo.h b/ydb/core/viewer/viewer_pqconsumerinfo.h similarity index 65% rename from ydb/core/viewer/json_pqconsumerinfo.h rename to ydb/core/viewer/viewer_pqconsumerinfo.h index 0071ec99e8bd..88cc9d305f1c 100644 --- a/ydb/core/viewer/json_pqconsumerinfo.h +++ b/ydb/core/viewer/viewer_pqconsumerinfo.h @@ -1,20 +1,14 @@ #pragma once -#include -#include -#include -#include -#include +#include "json_handlers.h" +#include "viewer.h" #include -#include +#include #include -#include "viewer.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; - class TJsonPQConsumerInfo : public TActorBootstrapped { using TBase = TActorBootstrapped; IViewer* Viewer; @@ -115,76 +109,54 @@ class TJsonPQConsumerInfo : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: topic - in: query - description: topic name - required: true - type: string - - name: dc - in: query - description: dc name (required with version >= 3) - required: false - type: string - default: "" - - name: version - in: query - description: query version - required: false - type: integer - default: 0 - - name: client - in: query - description: client name - required: true - type: string - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - default: false - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - default: false - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - default: 10000 - )___"); - } -}; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Consumer-topic metrics"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Consumer-topic metrics", + .Description = "Returns consumer-topic metrics", + }); + yaml.AddParameter({ + .Name = "topic", + .Description = "topic name", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "dc", + .Description = "dc name (required with version >= 3)", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "version", + .Description = "query version", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "client", + .Description = "client name", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns consumer-topic metrics"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_probes.cpp b/ydb/core/viewer/viewer_probes.cpp deleted file mode 100644 index 616d63e91e39..000000000000 --- a/ydb/core/viewer/viewer_probes.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "viewer_probes.h" -LWTRACE_DEFINE_PROVIDER(VIEWER_PROVIDER) diff --git a/ydb/core/viewer/viewer_probes.h b/ydb/core/viewer/viewer_probes.h deleted file mode 100644 index 3ce88fc06f1a..000000000000 --- a/ydb/core/viewer/viewer_probes.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -#define VIEWER_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ - PROBE(ViewerClusterHandler, \ - GROUPS(), \ - TYPES(ui32, bool, bool, \ - double, double, double, double, \ - double, double, double, double, \ - double, double), \ - NAMES("nodeId", "tabletsParam", "requestTimeout", \ - "startTime", "totalDurationMs", \ - "getListTenantsResponseDurationMs","getNodesInfoDurationMs", \ - "collectingDurationMs", "mergeBSGroupsDurationMs", \ - "mergeVDisksDurationMs", "mergePDisksDurationMs", \ - "mergeTabletsDurationMs", "responseBuildingDurationMs")) \ -/**/ -LWTRACE_DECLARE_PROVIDER(VIEWER_PROVIDER) diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/viewer_query.h similarity index 84% rename from ydb/core/viewer/json_query.h rename to ydb/core/viewer/viewer_query.h index 2fa05b20225d..de09c55d4320 100644 --- a/ydb/core/viewer/json_query.h +++ b/ydb/core/viewer/viewer_query.h @@ -1,29 +1,21 @@ #pragma once -#include "viewer.h" -#include -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" +#include "json_pipe_req.h" +#include "log.h" #include #include #include -#include #include #include -#include "json_pipe_req.h" -#include "viewer_request.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NMonitoring; -using ::google::protobuf::FieldDescriptor; using namespace NNodeWhiteboard; +bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event); + class TJsonQuery : public TViewerPipeClient { using TThis = TJsonQuery; using TBase = TViewerPipeClient; @@ -611,133 +603,132 @@ class TJsonQuery : public TViewerPipeClient { NProtobufJson::Proto2Json(response.GetQueryStats(), jsonResponse["stats"]); } } -}; -template <> -YAML::Node TJsonRequestSwagger::GetSwagger() { - YAML::Node node = YAML::Load(R"___( +public: + static YAML::Node GetSwagger() { + YAML::Node node = YAML::Load(R"___( post: - tags: - - viewer - summary: Executes SQL query - description: Executes SQL query - parameters: - - name: action - in: query - type: string - enum: [execute-scan, execute-script, execute-query, execute-data, explain-ast, explain-scan, explain-script, explain-query, explain-data, cancel-query] - required: true - description: > - execute method: - * `execute-query` - execute query (QueryService) - * `execute-data` - execute data query (DataQuery) - * `execute-scan` - execute scan query (ScanQuery) - * `execute-script` - execute script query (ScriptingService) - * `explain-query` - explain query (QueryService) - * `explain-data` - explain data query (DataQuery) - * `explain-scan` - explain scan query (ScanQuery) - * `explain-script` - explain script query (ScriptingService) - * `cancel-query` - cancel query (using query_id) - - name: database - in: query - description: database name - type: string - required: false - - name: query - in: query - description: SQL query text - type: string - required: false - - name: query_id - in: query - description: unique query identifier (uuid) - use the same id to cancel query - required: false - - name: syntax - in: query - description: > - query syntax: - * `yql_v1` - YQL v1 (default) - * `pg` - PostgreSQL compatible - type: string - enum: [yql_v1, pg] - required: false - - name: schema - in: query - description: > - result format schema: - * `classic` - * `modern` - * `multi` - * `ydb` - type: string - enum: [classic, modern, ydb, multi] - required: false - - name: stats - in: query - description: > - return stats: - * `profile` - * `full` - type: string - enum: [profile, full] - required: false - - name: transaction_mode - in: query - description: > - transaction mode: - * `serializable-read-write` - * `online-read-only` - * `stale-read-only` - * `snapshot-read-only` - type: string - enum: [serializable-read-write, online-read-only, stale-read-only, snapshot-read-only] - required: false - - name: direct - in: query - description: force processing query on current node - type: boolean - required: false - - name: base64 - in: query - description: return strings using base64 encoding - type: string - required: false - - name: timeout - in: query - description: timeout in ms - type: integer - required: false - - name: ui64 - in: query - description: return ui64 as number to avoid 56-bit js rounding - type: boolean - required: false - requestBody: + tags: + - viewer + summary: Executes SQL query description: Executes SQL query - required: false - content: - application/json: - schema: - type: object - description: the same properties as in query parameters - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - description: format depends on schema parameter - 400: - description: Bad Request - 403: - description: Forbidden - 504: - description: Gateway Timeout - )___"); - return node; -} - + parameters: + - name: action + in: query + type: string + enum: [execute-scan, execute-script, execute-query, execute-data, explain-ast, explain-scan, explain-script, explain-query, explain-data, cancel-query] + required: true + description: > + execute method: + * `execute-query` - execute query (QueryService) + * `execute-data` - execute data query (DataQuery) + * `execute-scan` - execute scan query (ScanQuery) + * `execute-script` - execute script query (ScriptingService) + * `explain-query` - explain query (QueryService) + * `explain-data` - explain data query (DataQuery) + * `explain-scan` - explain scan query (ScanQuery) + * `explain-script` - explain script query (ScriptingService) + * `cancel-query` - cancel query (using query_id) + - name: database + in: query + description: database name + type: string + required: false + - name: query + in: query + description: SQL query text + type: string + required: false + - name: query_id + in: query + description: unique query identifier (uuid) - use the same id to cancel query + required: false + - name: syntax + in: query + description: > + query syntax: + * `yql_v1` - YQL v1 (default) + * `pg` - PostgreSQL compatible + type: string + enum: [yql_v1, pg] + required: false + - name: schema + in: query + description: > + result format schema: + * `classic` + * `modern` + * `multi` + * `ydb` + type: string + enum: [classic, modern, ydb, multi] + required: false + - name: stats + in: query + description: > + return stats: + * `profile` + * `full` + type: string + enum: [profile, full] + required: false + - name: transaction_mode + in: query + description: > + transaction mode: + * `serializable-read-write` + * `online-read-only` + * `stale-read-only` + * `snapshot-read-only` + type: string + enum: [serializable-read-write, online-read-only, stale-read-only, snapshot-read-only] + required: false + - name: direct + in: query + description: force processing query on current node + type: boolean + required: false + - name: base64 + in: query + description: return strings using base64 encoding + type: string + required: false + - name: timeout + in: query + description: timeout in ms + type: integer + required: false + - name: ui64 + in: query + description: return ui64 as number to avoid 56-bit js rounding + type: boolean + required: false + requestBody: + description: Executes SQL query + required: false + content: + application/json: + schema: + type: object + description: the same properties as in query parameters + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + description: format depends on schema parameter + 400: + description: Bad Request + 403: + description: Forbidden + 504: + description: Gateway Timeout + )___"); + return node; + } +}; } -} + diff --git a/ydb/core/viewer/json_query_old.h b/ydb/core/viewer/viewer_query_old.h similarity index 98% rename from ydb/core/viewer/json_query_old.h rename to ydb/core/viewer/viewer_query_old.h index 6ef43bacc234..9b130e9be793 100644 --- a/ydb/core/viewer/json_query_old.h +++ b/ydb/core/viewer/viewer_query_old.h @@ -1,23 +1,14 @@ #pragma once +#include "json_pipe_req.h" +#include "log.h" #include "viewer.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "viewer_request.h" #include #include -#include #include #include -#include "json_pipe_req.h" -#include "viewer_request.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NMonitoring; @@ -627,9 +618,6 @@ class TJsonQueryOld : public TViewerPipeClient { NProtobufJson::Proto2Json(response.GetQueryStats(), jsonResponse["stats"]); } } - }; - -} } diff --git a/ydb/core/viewer/json_render.h b/ydb/core/viewer/viewer_render.h similarity index 81% rename from ydb/core/viewer/json_render.h rename to ydb/core/viewer/viewer_render.h index 1e84eacac818..71ffc7f6e3ae 100644 --- a/ydb/core/viewer/json_render.h +++ b/ydb/core/viewer/viewer_render.h @@ -1,16 +1,12 @@ #pragma once -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "json_pipe_req.h" -#include "viewer_request.h" -#include "viewer.h" #include "log.h" +#include "viewer_request.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NMonitoring; @@ -18,8 +14,6 @@ using namespace NMonitoring; class TJsonRender : public TViewerPipeClient { using TThis = TJsonRender; using TBase = TViewerPipeClient; - IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; TEvViewer::TEvViewerRequest::TPtr ViewerRequest; ui32 Timeout = 0; std::vector Metrics; @@ -31,9 +25,8 @@ class TJsonRender : public TViewerPipeClient { bool Direct = false; bool MadeProxyRequest = false; public: - TJsonRender(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) - : Viewer(viewer) - , Event(ev) + TJsonRender(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev) + : TViewerPipeClient(viewer, ev) { const auto& params(Event->Get()->Request.GetParams()); @@ -196,22 +189,19 @@ class TJsonRender : public TViewerPipeClient { if (response.GetError()) { json["status"] = "error"; json["error"] = response.GetError(); - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false))); - return; + return ReplyAndPassAway(GetHTTPOKJSON(json)); } if (response.DataSize() != Metrics.size()) { json["status"] = "error"; json["error"] = "Invalid data size received"; - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false))); - return; + return ReplyAndPassAway(GetHTTPOKJSON(json)); } for (size_t nMetric = 0; nMetric < response.DataSize(); ++nMetric) { const auto& protoMetric(response.GetData(nMetric)); if (response.TimeSize() != protoMetric.ValuesSize()) { json["status"] = "error"; json["error"] = "Invalid value size received"; - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false))); - return; + return ReplyAndPassAway(GetHTTPOKJSON(json)); } } { // graphite @@ -237,7 +227,7 @@ class TJsonRender : public TViewerPipeClient { } } - ReplyAndPassAway(Viewer->GetHTTPOKJSON(Event->Get(), NJson::WriteJson(json, false))); + ReplyAndPassAway(GetHTTPOKJSON(json)); } else { TEvViewer::TEvViewerResponse* viewerResponse = new TEvViewer::TEvViewerResponse(); viewerResponse->Record.MutableRenderResponse()->CopyFrom(response); @@ -280,64 +270,52 @@ class TJsonRender : public TViewerPipeClient { void ReplyAndPassAway() override { } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: target - in: query - description: metrics comma delimited - required: true - type: string - - name: from - in: query - description: time in seconds - required: false - type: integer - - name: database - in: query - description: database name - required: false - type: string - - name: direct - in: query - description: force processing query on current node - required: false - type: boolean - - name: until - in: query - description: time in seconds - required: false - type: integer - - name: maxDataPoints - in: query - description: maximum number of data points - required: false - type: integer - - name: format - in: query - description: response format - required: false - type: string - )___"); - } -}; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Graph data"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Graph data", + .Description = "Returns graph data in graphite format", + }); + yaml.AddParameter({ + .Name = "target", + .Description = "metrics comma delimited", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "from", + .Description = "time in seconds", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "database", + .Description = "database name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "direct", + .Description = "force processing query on current node", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "until", + .Description = "time in seconds", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "maxDataPoints", + .Description = "maximum number of data points", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "format", + .Description = "response format", + .Type = "string", + }); + return yaml; } }; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns graph data in graphite format"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_request.cpp b/ydb/core/viewer/viewer_request.cpp index 32963a848c2f..6941b5321e86 100644 --- a/ydb/core/viewer/viewer_request.cpp +++ b/ydb/core/viewer/viewer_request.cpp @@ -1,16 +1,12 @@ -#include - #include "viewer_request.h" +#include "viewer_autocomplete.h" +#include "viewer_query_old.h" +#include "viewer_render.h" +#include "viewer_sysinfo.h" +#include "viewer_tabletinfo.h" #include "wb_req.h" -#include "json_tabletinfo.h" -#include "json_sysinfo.h" -#include "json_query_old.h" -#include "json_render.h" -#include "json_autocomplete.h" - -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; @@ -107,4 +103,3 @@ bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event) { } } -} diff --git a/ydb/core/viewer/viewer_request.h b/ydb/core/viewer/viewer_request.h index 6516dbb59d18..20fb126761fb 100644 --- a/ydb/core/viewer/viewer_request.h +++ b/ydb/core/viewer/viewer_request.h @@ -1,9 +1,7 @@ #pragma once - #include "viewer.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -41,4 +39,3 @@ IActor* CreateViewerRequestHandler(TEvViewer::TEvViewerRequest::TPtr& request); bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event); } -} diff --git a/ydb/core/viewer/json_storage.h b/ydb/core/viewer/viewer_storage.h similarity index 85% rename from ydb/core/viewer/json_storage.h rename to ydb/core/viewer/viewer_storage.h index fba5047a69e0..dc23e974e84c 100644 --- a/ydb/core/viewer/json_storage.h +++ b/ydb/core/viewer/viewer_storage.h @@ -1,8 +1,10 @@ #pragma once +#include "json_handlers.h" #include "json_storage_base.h" +#include "viewer_pdiskinfo.h" +#include "viewer_vdiskinfo.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; @@ -478,124 +480,105 @@ class TJsonStorage : public TJsonStorageBase { Send(Initiator, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), std::move(json.Str())), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: tenant - in: query - description: tenant name - required: false - type: string - - name: pool - in: query - description: storage pool name - required: false - type: string - - name: node_id - in: query - description: node id - required: false - type: integer - - name: pdisk_id - in: query - description: pdisk id - required: false - type: integer - - name: group_id - in: query - description: group id - required: false - type: integer - - name: need_groups - in: query - description: return groups information - required: false - type: boolean - default: true - - name: need_disks - in: query - description: return disks information - required: false - type: boolean - default: true - - name: with - in: query - description: filter groups by missing or space - required: false - type: string - - name: version - in: query - description: query version (v1, v2) - required: false - type: string - - name: usage_pace - in: query - description: bucket size as a percentage - required: false - type: integer - default: 5 - - name: usage_buckets - in: query - description: filter groups by usage buckets - required: false - type: integer - - name: sort - in: query - description: sort by (PoolName,Kind,MediaType,Erasure,Degraded,Usage,GroupId,Used,Limit,Read,Write) - required: false - type: string - - name: offset - in: query - description: skip N nodes - required: false - type: integer - - name: limit - in: query - description: limit to N nodes - required: false - type: integer - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Storage information", + .Description = "Returns information about storage" + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean" + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean" + }); + yaml.AddParameter({ + .Name = "tenant", + .Description = "tenant name", + .Type = "string" + }); + yaml.AddParameter({ + .Name = "pool", + .Description = "storage pool name", + .Type = "string" + }); + yaml.AddParameter({ + .Name = "node_id", + .Description = "node id", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "pdisk_id", + .Description = "pdisk id", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "group_id", + .Description = "group id", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "need_groups", + .Description = "return groups information", + .Type = "boolean", + .Default = "true" + }); + yaml.AddParameter({ + .Name = "need_disks", + .Description = "return disks information", + .Type = "boolean", + .Default = "true" + }); + yaml.AddParameter({ + .Name = "with", + .Description = "filter groups by missing or space", + .Type = "string" + }); + yaml.AddParameter({ + .Name = "version", + .Description = "query version (v1, v2)", + .Type = "string" + }); + yaml.AddParameter({ + .Name = "usage_pace", + .Description = "bucket size as a percentage", + .Type = "integer", + .Default = "5" + }); + yaml.AddParameter({ + .Name = "usage_buckets", + .Description = "filter groups by usage buckets", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "sort", + .Description = "sort by (PoolName,Kind,MediaType,Erasure,Degraded,Usage,GroupId,Used,Limit,Read,Write)", + .Type = "string" + }); + yaml.AddParameter({ + .Name = "offset", + .Description = "skip N nodes", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "limit", + .Description = "limit to N nodes", + .Type = "integer" + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer" + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Storage information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about storage"; - } -}; - -} } diff --git a/ydb/core/viewer/json_storage_usage.h b/ydb/core/viewer/viewer_storage_usage.h similarity index 59% rename from ydb/core/viewer/json_storage_usage.h rename to ydb/core/viewer/viewer_storage_usage.h index e759a72c3ecf..e1bad4fb2e1c 100644 --- a/ydb/core/viewer/json_storage_usage.h +++ b/ydb/core/viewer/viewer_storage_usage.h @@ -1,14 +1,14 @@ #pragma once +#include "json_handlers.h" #include "json_storage_base.h" +#include "viewer_pdiskinfo.h" +#include "viewer_vdiskinfo.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; -using ::google::protobuf::FieldDescriptor; - class TJsonStorageUsage : public TJsonStorageBase { using TBase = TJsonStorageBase; using TThis = TJsonStorageUsage; @@ -75,72 +75,53 @@ class TJsonStorageUsage : public TJsonStorageBase { Send(Initiator, new NMon::TEvHttpInfoRes(Viewer->GetHTTPOKJSON(Event->Get(), std::move(json.Str())), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - type: boolean - required: false - - name: ui64 - in: query - description: return ui64 as number - type: boolean - required: false - - name: tenant - in: query - description: tenant name - type: string - required: false - - name: pool - in: query - description: storage pool name - type: string - required: false - - name: node_id - in: query - description: node id - type: integer - required: false - - name: pace - in: query - description: bucket size as a percentage - type: integer - required: false - default: 5 - - name: timeout - in: query - description: timeout in ms - type: integer - required: false - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Storage groups statistics"; - } -}; -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns the distribution of groups by usage"; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Storage groups statistics", + .Description = "Returns the distribution of groups by usage", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "tenant", + .Description = "tenant name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "pool", + .Description = "storage pool name", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "node_id", + .Description = "node id", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "pace", + .Description = "bucket size as a percentage", + .Type = "integer", + .Default = "5", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; } -} diff --git a/ydb/core/viewer/json_sysinfo.h b/ydb/core/viewer/viewer_sysinfo.h similarity index 78% rename from ydb/core/viewer/json_sysinfo.h rename to ydb/core/viewer/viewer_sysinfo.h index 922f9566b917..f35c3a11fbc2 100644 --- a/ydb/core/viewer/json_sysinfo.h +++ b/ydb/core/viewer/viewer_sysinfo.h @@ -1,13 +1,7 @@ #pragma once -#include -#include -#include -#include -#include #include "json_wb_req.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template <> class TWhiteboardMerger { @@ -55,19 +49,4 @@ struct TWhiteboardInfo { using TJsonSysInfo = TJsonWhiteboardRequest; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "System information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns system information"; - } -}; - -} } diff --git a/ydb/core/viewer/json_tabletcounters.h b/ydb/core/viewer/viewer_tabletcounters.h similarity index 78% rename from ydb/core/viewer/json_tabletcounters.h rename to ydb/core/viewer/viewer_tabletcounters.h index 023552fdea3f..60b99eb49ee7 100644 --- a/ydb/core/viewer/json_tabletcounters.h +++ b/ydb/core/viewer/viewer_tabletcounters.h @@ -1,17 +1,13 @@ #pragma once -#include -#include +#include "json_handlers.h" +#include "viewer.h" +#include "wb_aggregate.h" #include #include -#include #include #include -#include -#include "viewer.h" -#include "wb_aggregate.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -165,66 +161,47 @@ class TJsonTabletCounters : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: false - type: string - - name: tablet_id - in: query - description: tablet identifier - required: false - type: integer - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: aggregate - in: query - description: aggregate tablet counters - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Tablet counters info", + .Description = "Returns information about tablet counters", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "tablet_id", + .Description = "tablet identifier", + .Type = "integer", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "aggregate", + .Description = "aggregate tablet counters", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Tablet counters information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about tablet counters"; - } -}; - -} } diff --git a/ydb/core/viewer/json_tabletinfo.h b/ydb/core/viewer/viewer_tabletinfo.h similarity index 84% rename from ydb/core/viewer/json_tabletinfo.h rename to ydb/core/viewer/viewer_tabletinfo.h index aac8fabe01a5..b61a757e98d4 100644 --- a/ydb/core/viewer/json_tabletinfo.h +++ b/ydb/core/viewer/viewer_tabletinfo.h @@ -1,21 +1,8 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "json_pipe_req.h" #include "json_wb_req.h" -#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template<> struct TWhiteboardInfo { @@ -362,111 +349,6 @@ class TJsonTabletInfo : public TJsonWhiteboardRequest -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: node_id - in: query - description: node identifier - required: false - type: integer - - name: path - in: query - description: schema path - required: false - type: string - - name: merge - in: query - description: merge information from nodes - required: false - type: boolean - - name: group - in: query - description: group information by field - required: false - type: string - - name: all - in: query - description: return all possible key combinations (for enums only) - required: false - type: boolean - - name: filter - in: query - description: filter information by field - required: false - type: string - - name: alive - in: query - description: request from alive (connected) nodes only - required: false - type: boolean - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - - name: retries - in: query - description: number of retries - required: false - type: integer - - name: retry_period - in: query - description: retry period in ms - required: false - type: integer - default: 500 - - name: static - in: query - description: request from static nodes only - required: false - type: boolean - - name: since - in: query - description: filter by update time - required: false - type: string - )___"); - } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Tablet information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about tablets"; - } -}; - -} } diff --git a/ydb/core/viewer/json_tenantinfo.h b/ydb/core/viewer/viewer_tenantinfo.h similarity index 92% rename from ydb/core/viewer/json_tenantinfo.h rename to ydb/core/viewer/viewer_tenantinfo.h index 7826103538c4..30789adce2d3 100644 --- a/ydb/core/viewer/json_tenantinfo.h +++ b/ydb/core/viewer/viewer_tenantinfo.h @@ -1,29 +1,19 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" -#include "wb_aggregate.h" -#include "wb_merge.h" #include "log.h" +#include "viewer.h" #include "viewer_request.h" +#include "viewer_tabletinfo.h" +#include "wb_aggregate.h" +#include "wb_merge.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; +NKikimrViewer::EFlag GetViewerFlag(Ydb::Monitoring::StatusFlag::Status flag); + class TJsonTenantInfo : public TViewerPipeClient { using TThis = TJsonTenantInfo; using TBase = TViewerPipeClient; @@ -384,8 +374,7 @@ class TJsonTenantInfo : public TViewerPipeClient { void Handle(NNodeWhiteboard::TEvWhiteboard::TEvTabletStateResponse::TPtr& ev) { ui32 nodeId = ev.Get()->Cookie; - BLOG_TRACE("Received TEvTabletStateResponse from " << nodeId << " with " - << TWhiteboardInfo::GetElementsCount(ev->Get()->Record) << " tablets"); + BLOG_TRACE("Received TEvTabletStateResponse from " << nodeId); auto tenantId = NodeIdsToTenant[nodeId]; WhiteboardTabletStateResponse[tenantId][nodeId] = std::move(ev->Get()->Record); RequestDone(); @@ -418,9 +407,7 @@ class TJsonTenantInfo : public TViewerPipeClient { auto tenantId = NodeIdsToTenant[nodeId]; switch (ev->Get()->Record.GetResponseCase()) { case NKikimrViewer::TEvViewerResponse::kTabletResponse: - BLOG_TRACE("Received TEvViewerResponse from " << nodeId << " with " - << TWhiteboardInfo::GetElementsCount(ev->Get()->Record.GetTabletResponse()) - << " tablets"); + BLOG_TRACE("Received TEvViewerResponse from " << nodeId); OffloadMergedTabletStateResponse[tenantId] = std::move(ev->Get()->Record); RequestDone(); break; @@ -863,96 +850,77 @@ class TJsonTenantInfo : public TViewerPipeClient { Result.AddErrors("Timeout occurred"); ReplyAndPassAway(); } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Tenant info (detailed)", + .Description = "Returns information about tenants", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "user", + .Description = "tenant owner", + .Type = "string", + }); + yaml.AddParameter({ + .Name = "followers", + .Description = "return followers", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "metrics", + .Description = "return tablet metrics", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "tablets", + .Description = "return tablets", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "system_tablets", + .Description = "return system tablets", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "offload_merge", + .Description = "use offload merge", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "storage", + .Description = "return storage info", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "nodes", + .Description = "return nodes info", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: false - type: string - - name: user - in: query - description: tenant owner - required: false - type: string - - name: followers - in: query - description: return followers - required: false - type: boolean - - name: metrics - in: query - description: return tablet metrics - required: false - type: boolean - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: tablets - in: query - description: return tablets - required: false - type: boolean - - name: system_tablets - in: query - description: return system tablets - required: false - type: boolean - - name: offload_merge - in: query - description: use offload merge - required: false - type: boolean - - name: storage - in: query - description: return storage info - required: false - type: boolean - - name: nodes - in: query - description: return nodes info - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); - } -}; - -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "\"Tenant info (detailed)\""; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "\"Returns information about tenants\""; - } -}; - -} } diff --git a/ydb/core/viewer/json_tenants.h b/ydb/core/viewer/viewer_tenants.h similarity index 67% rename from ydb/core/viewer/json_tenants.h rename to ydb/core/viewer/viewer_tenants.h index 4397565566a5..d0c2baa1c637 100644 --- a/ydb/core/viewer/json_tenants.h +++ b/ydb/core/viewer/viewer_tenants.h @@ -1,17 +1,9 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include "json_handlers.h" #include "json_pipe_req.h" #include "wb_aggregate.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -95,57 +87,38 @@ class TJsonTenants : public TViewerPipeClient { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: state - in: query - description: return tenant state - required: false - type: boolean - default: true - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Tenant info (brief)", + .Description = "Returns list of tenants", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "state", + .Description = "return tenant state", + .Type = "boolean", + .Default = "true", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Tenant info (brief)"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns list of tenants"; - } -}; - -} } diff --git a/ydb/core/viewer/json_topicinfo.h b/ydb/core/viewer/viewer_topicinfo.h similarity index 64% rename from ydb/core/viewer/json_topicinfo.h rename to ydb/core/viewer/viewer_topicinfo.h index d5880859ff16..9172624d667a 100644 --- a/ydb/core/viewer/json_topicinfo.h +++ b/ydb/core/viewer/viewer_topicinfo.h @@ -1,14 +1,10 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include "json_handlers.h" #include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -90,69 +86,51 @@ class TJsonTopicInfo : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; - -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { - return TProtoToYaml::ProtoToYamlSchema(); - } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return YAML::Load(R"___( - - name: path - in: query - description: schema path - required: true - type: string - - name: client - in: query - description: client name - required: false - type: string - default: total - - name: enums - in: query - description: convert enums to strings - required: false - type: boolean - - name: all - in: query - description: return all topics and all clients - required: false - type: boolean - default: false - - name: ui64 - in: query - description: return ui64 as number - required: false - type: boolean - - name: timeout - in: query - description: timeout in ms - required: false - type: integer - default: 10000 - )___"); + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Topic information", + .Description = "Information about topic", + }); + yaml.AddParameter({ + .Name = "path", + .Description = "schema path", + .Type = "string", + .Required = true, + }); + yaml.AddParameter({ + .Name = "client", + .Description = "client name", + .Type = "string", + .Default = "total", + }); + yaml.AddParameter({ + .Name = "enums", + .Description = "convert enums to strings", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "all", + .Description = "return all topics and all clients", + .Type = "boolean", + .Default = "false", + }); + yaml.AddParameter({ + .Name = "ui64", + .Description = "return ui64 as number", + .Type = "boolean", + }); + yaml.AddParameter({ + .Name = "timeout", + .Description = "timeout in ms", + .Type = "integer", + .Default = "10000", + }); + yaml.SetResponseSchema(TProtoToYaml::ProtoToYamlSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Topic information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Information about topic"; - } -}; - -} } diff --git a/ydb/core/viewer/viewer_ut.cpp b/ydb/core/viewer/viewer_ut.cpp index bbc2e5cf1938..f854bed5a06b 100644 --- a/ydb/core/viewer/viewer_ut.cpp +++ b/ydb/core/viewer/viewer_ut.cpp @@ -10,10 +10,9 @@ #include #include #include -#include "json_handlers.h" -#include "json_tabletinfo.h" -#include "json_vdiskinfo.h" -#include "json_pdiskinfo.h" +#include "viewer_tabletinfo.h" +#include "viewer_vdiskinfo.h" +#include "viewer_pdiskinfo.h" #include "query_autocomplete_helper.h" #include diff --git a/ydb/core/viewer/json_vdiskinfo.h b/ydb/core/viewer/viewer_vdiskinfo.h similarity index 80% rename from ydb/core/viewer/json_vdiskinfo.h rename to ydb/core/viewer/viewer_vdiskinfo.h index 0675c4cd407b..17c0bd740d42 100644 --- a/ydb/core/viewer/json_vdiskinfo.h +++ b/ydb/core/viewer/viewer_vdiskinfo.h @@ -1,10 +1,4 @@ #pragma once -#include -#include -#include -#include -#include -#include #include "json_wb_req.h" namespace std { @@ -43,8 +37,7 @@ struct hash { } -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { template <> struct TWhiteboardInfo { @@ -78,19 +71,4 @@ struct TWhiteboardInfo { using TJsonVDiskInfo = TJsonWhiteboardRequest; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "VDisk information"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "VDisk information"; - } -}; - -} } diff --git a/ydb/core/viewer/json_whoami.h b/ydb/core/viewer/viewer_whoami.h similarity index 82% rename from ydb/core/viewer/json_whoami.h rename to ydb/core/viewer/viewer_whoami.h index 36e3715268fd..cf1a6eee7927 100644 --- a/ydb/core/viewer/json_whoami.h +++ b/ydb/core/viewer/viewer_whoami.h @@ -1,18 +1,13 @@ #pragma once -#include -#include +#include "json_handlers.h" +#include "viewer.h" +#include #include #include -#include -#include -#include -#include -#include -#include -#include "viewer.h" +#include +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; @@ -80,11 +75,8 @@ class TJsonWhoAmI : public TActorBootstrapped { ctx.Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(Event->Get()), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); Die(ctx); } -}; -template <> -struct TJsonRequestSchema { - static YAML::Node GetSchema() { + static YAML::Node GetSwaggerSchema() { return YAML::Load(R"___( type: object title: WhoAmI @@ -114,28 +106,17 @@ struct TJsonRequestSchema { description: Is user allowed to do unrestricted changes in the system )___"); } -}; -template <> -struct TJsonRequestParameters { - static YAML::Node GetParameters() { - return {}; + static YAML::Node GetSwagger() { + TSimpleYamlBuilder yaml({ + .Method = "get", + .Tag = "viewer", + .Summary = "Information about current user", + .Description = "Returns information about user token", + }); + yaml.SetResponseSchema(GetSwaggerSchema()); + return yaml; } }; -template <> -struct TJsonRequestSummary { - static TString GetSummary() { - return "Information about current user"; - } -}; - -template <> -struct TJsonRequestDescription { - static TString GetDescription() { - return "Returns information about user token"; - } -}; - -} } diff --git a/ydb/core/viewer/wb_aggregate.cpp b/ydb/core/viewer/wb_aggregate.cpp index 7f3d56d64b76..45e23a53a622 100644 --- a/ydb/core/viewer/wb_aggregate.cpp +++ b/ydb/core/viewer/wb_aggregate.cpp @@ -1,7 +1,6 @@ #include "wb_aggregate.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { void AggregateMessage(::google::protobuf::Message& protoTo, const ::google::protobuf::Message& protoFrom) { const Reflection& reflectionFrom = *protoFrom.GetReflection(); @@ -177,4 +176,3 @@ void AggregateMessage(::google::protobuf::Message& protoTo, const ::google::prot } } -} diff --git a/ydb/core/viewer/wb_aggregate.h b/ydb/core/viewer/wb_aggregate.h index 7d09f1565f6c..c9b589f32115 100644 --- a/ydb/core/viewer/wb_aggregate.h +++ b/ydb/core/viewer/wb_aggregate.h @@ -1,19 +1,17 @@ #pragma once -#include #include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; using namespace ::google::protobuf; -template +template struct TWhiteboardInfo; void AggregateMessage(::google::protobuf::Message& protoTo, const ::google::protobuf::Message& protoFrom); -template +template class TWhiteboardAggregator { public: using TResponseType = ResponseType; @@ -46,4 +44,3 @@ THolder AggregateWhiteboardResponses(TMap i32 TFieldProtoValueExtractor::ExtractValue(const Reflection& reflection, const Message& element) const { @@ -97,4 +96,3 @@ TMessageValue TFieldProtoValueExtractor::ExtractValue(const Refle } } -} diff --git a/ydb/core/viewer/wb_filter.h b/ydb/core/viewer/wb_filter.h index 64926899e70c..8222c58366c1 100644 --- a/ydb/core/viewer/wb_filter.h +++ b/ydb/core/viewer/wb_filter.h @@ -1,15 +1,14 @@ #pragma once +#include #include #include -#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; using namespace ::google::protobuf; -template +template struct TWhiteboardInfo; struct TEnumValue { @@ -552,4 +551,3 @@ void FilterWhiteboardResponses(ResponseType& response, const TString& filters) { } } -} diff --git a/ydb/core/viewer/wb_group.h b/ydb/core/viewer/wb_group.h index 731c5db9f4b1..2250a45daaf7 100644 --- a/ydb/core/viewer/wb_group.h +++ b/ydb/core/viewer/wb_group.h @@ -1,15 +1,14 @@ #pragma once +#include #include #include -#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; using namespace ::google::protobuf; -template +template struct TWhiteboardInfo; template @@ -304,4 +303,3 @@ void GroupWhiteboardResponses(ResponseType& response, const TString& fields, boo } } -} diff --git a/ydb/core/viewer/wb_merge.cpp b/ydb/core/viewer/wb_merge.cpp index cca5dc1d9deb..cc092ad4540a 100644 --- a/ydb/core/viewer/wb_merge.cpp +++ b/ydb/core/viewer/wb_merge.cpp @@ -1,7 +1,6 @@ #include "wb_merge.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; using namespace ::google::protobuf; @@ -216,4 +215,3 @@ void TWhiteboardMergerBase::ProtoMerge(google::protobuf::Message& protoTo, const } } -} diff --git a/ydb/core/viewer/wb_merge.h b/ydb/core/viewer/wb_merge.h index e9912de2ae6e..64d37d0bfd10 100644 --- a/ydb/core/viewer/wb_merge.h +++ b/ydb/core/viewer/wb_merge.h @@ -1,23 +1,21 @@ #pragma once +#include "wb_filter.h" +#include "wb_group.h" #include #include #include -#include "wb_filter.h" -#include "wb_group.h" -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NNodeWhiteboard; using namespace ::google::protobuf; -struct TWhiteboardDefaultInfo { -}; +struct TWhiteboardDefaultInfo {}; -template +template struct TWhiteboardInfo; -template +template struct TWhiteboardMergerComparator { bool operator ()(const ResponseType& a, const ResponseType& b) const { return a.GetChangeTime() < b.GetChangeTime(); @@ -304,4 +302,3 @@ void MergeWhiteboardResponses(ResponseType& result, TMap& re } } -} diff --git a/ydb/core/viewer/wb_req.h b/ydb/core/viewer/wb_req.h index bfd1ff8ba8a9..d808b9e4a063 100644 --- a/ydb/core/viewer/wb_req.h +++ b/ydb/core/viewer/wb_req.h @@ -1,25 +1,13 @@ #pragma once - -#pragma once -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include "viewer.h" #include "json_pipe_req.h" -#include "wb_merge.h" -#include "wb_group.h" -#include "wb_filter.h" #include "log.h" +#include "viewer.h" +#include "wb_filter.h" +#include "wb_group.h" +#include "wb_merge.h" +#include -namespace NKikimr { -namespace NViewer { +namespace NKikimr::NViewer { using namespace NActors; using namespace NNodeWhiteboard; @@ -297,4 +285,3 @@ class TWhiteboardRequest : public TViewerPipeClient { }; } -} diff --git a/ydb/core/viewer/ya.make b/ydb/core/viewer/ya.make index c47429d57b1a..8830cee29367 100644 --- a/ydb/core/viewer/ya.make +++ b/ydb/core/viewer/ya.make @@ -4,79 +4,95 @@ RECURSE_FOR_TESTS( LIBRARY() +IF(BUILD_TYPE == RELEASE OR BUILD_TYPE == RELWITHDEBINFO) + CXXFLAGS(-Oz) +ENDIF() + SRCS( browse_db.h - browse_pq.h + browse_events.h browse.h - check_access.h + browse_pq.h counters_hosts.h - json_acl.h - json_autocomplete.h - json_blobindexstat.h - json_browse.h - json_bscontrollerinfo.h - json_bsgroupinfo.h - json_cluster.h - json_compute.h - json_config.h - json_content.h - json_counters.h - json_describe.h - json_describe_consumer.h - json_describe_topic.h - json_local_rpc.h - json_getblob.h - json_graph.h + healthcheck_record.h + json_handlers.cpp + json_handlers.h + json_handlers_browse.cpp json_handlers_operation.cpp json_handlers_pdisk.cpp json_handlers_scheme.cpp json_handlers_storage.cpp json_handlers_vdisk.cpp json_handlers_viewer.cpp - json_healthcheck.h - json_hiveinfo.h - json_hotkeys.h - json_labeledcounters.h - json_metainfo.h - json_netinfo.h - json_nodeinfo.h - json_nodelist.h - json_nodes.h - json_pdiskinfo.h + json_handlers_pq.cpp + json_local_rpc.h json_pipe_req.cpp - json_query.h - json_query_old.h - json_render.h - json_storage.h - json_sysinfo.h - json_tabletcounters.h - json_tabletinfo.h - json_tenants.h - json_tenantinfo.h - json_topicinfo.h - json_pqconsumerinfo.h + json_pipe_req.h + json_storage_base.h json_vdisk_req.h - json_vdisk_evict.h - json_vdiskinfo.h - json_vdiskstat.h + json_wb_req.cpp json_wb_req.h - json_whoami.h log.h operation_cancel.h operation_forget.h operation_get.h operation_list.h pdisk_info.h + pdisk_restart.h pdisk_status.h - scheme_directory.h - storage_groups.cpp query_autocomplete_helper.h - viewer_capabilities.cpp + scheme_directory.h + storage_groups.h + vdisk_blobindexstat.h + vdisk_evict.h + vdisk_getblob.h + vdisk_vdiskstat.h + viewer_acl.h + viewer_autocomplete.h + viewer_browse.h + viewer_bscontrollerinfo.h + viewer_bsgroupinfo.h + viewer_capabilities.h + viewer_check_access.h + viewer_cluster.h + viewer_compute.h + viewer_config.h + viewer_content.h + viewer_counters.h + viewer_describe_consumer.h + viewer_describe.h + viewer_describe_topic.h + viewer_graph.h + viewer_healthcheck.h + viewer_helper.h + viewer_hiveinfo.h + viewer_hivestats.h + viewer_hotkeys.h + viewer_labeled_counters.h + viewer_metainfo.h + viewer_netinfo.h + viewer_nodeinfo.h + viewer_nodelist.h + viewer_nodes.h + viewer_pdiskinfo.h + viewer_pqconsumerinfo.h + viewer_query.h + viewer_query_old.h + viewer_render.h viewer_request.cpp viewer_request.h - viewer.cpp + viewer_storage.h + viewer_storage_usage.h + viewer_sysinfo.h + viewer_tabletcounters.h + viewer_tabletinfo.h + viewer_tenantinfo.h + viewer_tenants.h + viewer_topicinfo.h + viewer_vdiskinfo.h + viewer_whoami.h viewer.h - viewer_probes.cpp + viewer.cpp wb_aggregate.cpp wb_aggregate.h wb_filter.cpp @@ -84,6 +100,7 @@ SRCS( wb_group.h wb_merge.cpp wb_merge.h + wb_req.h ) IF (NOT EXPORT_CMAKE) diff --git a/ydb/core/viewer/yaml/yaml.cpp b/ydb/core/viewer/yaml/yaml.cpp index a23afaef2870..c2175e12858d 100644 --- a/ydb/core/viewer/yaml/yaml.cpp +++ b/ydb/core/viewer/yaml/yaml.cpp @@ -47,6 +47,9 @@ YAML::Node TProtoToYaml::ProtoToYamlSchema(const ::google::protobuf::Descriptor* int oneofFields = descriptor->oneof_decl_count(); for (int idx = 0; idx < oneofFields; ++idx) { const OneofDescriptor* fieldDescriptor = descriptor->oneof_decl(idx); + if (fieldDescriptor->name().StartsWith("_")) { + continue; + } properties[fieldDescriptor->name()]["type"] = "oneOf"; } for (int idx = 0; idx < fields; ++idx) { diff --git a/ydb/core/viewer/yaml/yaml.h b/ydb/core/viewer/yaml/yaml.h index 8e0869c46ed9..8415cce3c57e 100644 --- a/ydb/core/viewer/yaml/yaml.h +++ b/ydb/core/viewer/yaml/yaml.h @@ -1,9 +1,9 @@ #pragma once +#include +#include #include #include -#include #include -#include struct TEnumSettings { bool ConvertToLowerCase = false;