diff options
author | lastutf445 <lastutf445@yandex-team.ru> | 2022-02-10 16:50:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:41 +0300 |
commit | 613bcf44f93063d0d999c886a80eec7fb61afd97 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | 81dc2ca0088907db6b9b8e59b9722e0a610f02a8 (diff) | |
download | ydb-613bcf44f93063d0d999c886a80eec7fb61afd97.tar.gz |
Restoring authorship annotation for <lastutf445@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/actors/http/http.h | 2 | ||||
-rw-r--r-- | library/cpp/actors/http/http_proxy.cpp | 12 | ||||
-rw-r--r-- | library/cpp/actors/http/http_proxy.h | 2 | ||||
-rw-r--r-- | library/cpp/actors/http/http_proxy_acceptor.cpp | 10 | ||||
-rw-r--r-- | library/cpp/actors/http/http_proxy_incoming.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/http/http_proxy_ssl.h | 114 | ||||
-rw-r--r-- | ydb/core/protos/tx_datashard.proto | 4 | ||||
-rw-r--r-- | ydb/core/tx/datashard/datashard.cpp | 36 | ||||
-rw-r--r-- | ydb/core/viewer/json_hotkeys.h | 250 | ||||
-rw-r--r-- | ydb/core/viewer/json_query.h | 88 | ||||
-rw-r--r-- | ydb/core/viewer/viewer.cpp | 4 | ||||
-rw-r--r-- | ydb/core/viewer/ya.make | 2 | ||||
-rw-r--r-- | ydb/public/lib/value/value.cpp | 6 |
13 files changed, 266 insertions, 266 deletions
diff --git a/library/cpp/actors/http/http.h b/library/cpp/actors/http/http.h index dbf4715a98..96c5c1ec48 100644 --- a/library/cpp/actors/http/http.h +++ b/library/cpp/actors/http/http.h @@ -593,7 +593,7 @@ public: THttpConfig::SocketAddressType Address; TString WorkerName; THPTimer Timer; - bool Secure = false; + bool Secure = false; bool IsConnectionClose() const { if (Connection.empty()) { diff --git a/library/cpp/actors/http/http_proxy.cpp b/library/cpp/actors/http/http_proxy.cpp index 8a865e4df7..36c6855d93 100644 --- a/library/cpp/actors/http/http_proxy.cpp +++ b/library/cpp/actors/http/http_proxy.cpp @@ -172,21 +172,21 @@ protected: void Handle(TEvHttpProxy::TEvReportSensors::TPtr event, const NActors::TActorContext&) { const TEvHttpProxy::TEvReportSensors& sensors(*event->Get()); - const static TString urlNotFound = "not-found"; - const TString& url = (sensors.Status == "404" ? urlNotFound : sensors.Url); - + const static TString urlNotFound = "not-found"; + const TString& url = (sensors.Status == "404" ? urlNotFound : sensors.Url); + Sensors.Rate({ {"sensor", "count"}, {"direction", sensors.Direction}, {"peer", sensors.Host}, - {"url", url}, + {"url", url}, {"status", sensors.Status} })->Inc(); Sensors.HistogramRate({ {"sensor", "time_us"}, {"direction", sensors.Direction}, {"peer", sensors.Host}, - {"url", url}, + {"url", url}, {"status", sensors.Status} }, NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MicroSeconds()); @@ -194,7 +194,7 @@ protected: {"sensor", "time_ms"}, {"direction", sensors.Direction}, {"peer", sensors.Host}, - {"url", url}, + {"url", url}, {"status", sensors.Status} }, NMonitoring::ExplicitHistogram({1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 30000, 60000}))->Record(sensors.Time.MilliSeconds()); diff --git a/library/cpp/actors/http/http_proxy.h b/library/cpp/actors/http/http_proxy.h index 6a6b8a7fa5..afd0170997 100644 --- a/library/cpp/actors/http/http_proxy.h +++ b/library/cpp/actors/http/http_proxy.h @@ -49,7 +49,7 @@ struct TEvHttpProxy { bool Secure = false; TString CertificateFile; TString PrivateKeyFile; - TString SslCertificatePem; + TString SslCertificatePem; TEvAddListeningPort(TIpPort port) : Port(port) diff --git a/library/cpp/actors/http/http_proxy_acceptor.cpp b/library/cpp/actors/http/http_proxy_acceptor.cpp index 1b344ad2ce..9780541b71 100644 --- a/library/cpp/actors/http/http_proxy_acceptor.cpp +++ b/library/cpp/actors/http/http_proxy_acceptor.cpp @@ -52,11 +52,11 @@ protected: Endpoint.Secure = event->Get()->Secure; int err = 0; if (Endpoint.Secure) { - if (!event->Get()->SslCertificatePem.empty()) { - Endpoint.SecureContext = TSslHelpers::CreateServerContext(event->Get()->SslCertificatePem); - } else { - Endpoint.SecureContext = TSslHelpers::CreateServerContext(event->Get()->CertificateFile, event->Get()->PrivateKeyFile); - } + if (!event->Get()->SslCertificatePem.empty()) { + Endpoint.SecureContext = TSslHelpers::CreateServerContext(event->Get()->SslCertificatePem); + } else { + Endpoint.SecureContext = TSslHelpers::CreateServerContext(event->Get()->CertificateFile, event->Get()->PrivateKeyFile); + } if (Endpoint.SecureContext == nullptr) { err = -1; LOG_WARN_S(ctx, HttpLog, "Failed to construct server security context"); diff --git a/library/cpp/actors/http/http_proxy_incoming.cpp b/library/cpp/actors/http/http_proxy_incoming.cpp index 6d0cf07f77..80fe2af53d 100644 --- a/library/cpp/actors/http/http_proxy_incoming.cpp +++ b/library/cpp/actors/http/http_proxy_incoming.cpp @@ -113,7 +113,7 @@ protected: } CurrentRequest->Address = Address; CurrentRequest->WorkerName = Endpoint.WorkerName; - CurrentRequest->Secure = Endpoint.Secure; + CurrentRequest->Secure = Endpoint.Secure; } if (!CurrentRequest->EnsureEnoughSpaceAvailable()) { LOG_DEBUG_S(ctx, HttpLog, "(#" << TSocketImpl::GetRawSocket() << "," << Address << ") connection closed - not enough space available"); diff --git a/library/cpp/actors/http/http_proxy_ssl.h b/library/cpp/actors/http/http_proxy_ssl.h index d0894a0313..ffce12997f 100644 --- a/library/cpp/actors/http/http_proxy_ssl.h +++ b/library/cpp/actors/http/http_proxy_ssl.h @@ -17,14 +17,14 @@ struct TSslHelpers { SSL_free(ssl); } - static void Destroy(X509* cert) noexcept { - X509_free(cert); - } - - static void Destroy(EVP_PKEY* pkey) noexcept { - EVP_PKEY_free(pkey); - } - + static void Destroy(X509* cert) noexcept { + X509_free(cert); + } + + static void Destroy(EVP_PKEY* pkey) noexcept { + EVP_PKEY_free(pkey); + } + static void Destroy(BIO* bio) noexcept { BIO_free(bio); } @@ -67,55 +67,55 @@ struct TSslHelpers { return ctx; } - static bool LoadX509Chain(TSslHolder<SSL_CTX>& ctx, const TString& pem) { - TSslHolder<BIO> bio(BIO_new_mem_buf(pem.c_str(), pem.size())); - if (bio == nullptr) { - return false; - } - TSslHolder<X509> cert(PEM_read_bio_X509_AUX(bio.Get(), nullptr, nullptr, nullptr)); - if (cert == nullptr) { - return false; - } - if (SSL_CTX_use_certificate(ctx.Get(), cert.Release()) <= 0) { - return false; - } - SSL_CTX_clear_chain_certs(ctx.Get()); - while (true) { - TSslHolder<X509> ca(PEM_read_bio_X509(bio.Get(), nullptr, nullptr, nullptr)); - if (ca == nullptr) { - break; - } - if (!SSL_CTX_add0_chain_cert(ctx.Get(), ca.Release())) { - return false; - } - } - return true; - } - - static bool LoadPrivateKey(TSslHolder<SSL_CTX>& ctx, const TString& pem) { - TSslHolder<BIO> bio(BIO_new_mem_buf(pem.c_str(), pem.size())); - if (bio == nullptr) { - return false; - } - TSslHolder<EVP_PKEY> pkey(PEM_read_bio_PrivateKey(bio.Get(), nullptr, nullptr, nullptr)); - if (SSL_CTX_use_PrivateKey(ctx.Get(), pkey.Release()) <= 0) { - return false; - } - return true; - } - - static TSslHolder<SSL_CTX> CreateServerContext(const TString& pem) { - TSslHolder<SSL_CTX> ctx = CreateSslCtx(SSLv23_server_method()); - SSL_CTX_set_ecdh_auto(ctx.Get(), 1); - if (!LoadX509Chain(ctx, pem)) { - return nullptr; - } - if (!LoadPrivateKey(ctx, pem)) { - return nullptr; - } - return ctx; - } - + static bool LoadX509Chain(TSslHolder<SSL_CTX>& ctx, const TString& pem) { + TSslHolder<BIO> bio(BIO_new_mem_buf(pem.c_str(), pem.size())); + if (bio == nullptr) { + return false; + } + TSslHolder<X509> cert(PEM_read_bio_X509_AUX(bio.Get(), nullptr, nullptr, nullptr)); + if (cert == nullptr) { + return false; + } + if (SSL_CTX_use_certificate(ctx.Get(), cert.Release()) <= 0) { + return false; + } + SSL_CTX_clear_chain_certs(ctx.Get()); + while (true) { + TSslHolder<X509> ca(PEM_read_bio_X509(bio.Get(), nullptr, nullptr, nullptr)); + if (ca == nullptr) { + break; + } + if (!SSL_CTX_add0_chain_cert(ctx.Get(), ca.Release())) { + return false; + } + } + return true; + } + + static bool LoadPrivateKey(TSslHolder<SSL_CTX>& ctx, const TString& pem) { + TSslHolder<BIO> bio(BIO_new_mem_buf(pem.c_str(), pem.size())); + if (bio == nullptr) { + return false; + } + TSslHolder<EVP_PKEY> pkey(PEM_read_bio_PrivateKey(bio.Get(), nullptr, nullptr, nullptr)); + if (SSL_CTX_use_PrivateKey(ctx.Get(), pkey.Release()) <= 0) { + return false; + } + return true; + } + + static TSslHolder<SSL_CTX> CreateServerContext(const TString& pem) { + TSslHolder<SSL_CTX> ctx = CreateSslCtx(SSLv23_server_method()); + SSL_CTX_set_ecdh_auto(ctx.Get(), 1); + if (!LoadX509Chain(ctx, pem)) { + return nullptr; + } + if (!LoadPrivateKey(ctx, pem)) { + return nullptr; + } + return ctx; + } + static TSslHolder<SSL> ConstructSsl(SSL_CTX* ctx, BIO* bio) { TSslHolder<SSL> ssl(SSL_new(ctx)); diff --git a/ydb/core/protos/tx_datashard.proto b/ydb/core/protos/tx_datashard.proto index 0f8203fcc0..89863b2540 100644 --- a/ydb/core/protos/tx_datashard.proto +++ b/ydb/core/protos/tx_datashard.proto @@ -1125,8 +1125,8 @@ message TEvGetRSInfoResponse { } message TEvGetDataHistogramRequest { - optional uint32 CollectKeySampleMs = 1; - optional bool ActualData = 2; + optional uint32 CollectKeySampleMs = 1; + optional bool ActualData = 2; } message TEvGetDataHistogramResponse { diff --git a/ydb/core/tx/datashard/datashard.cpp b/ydb/core/tx/datashard/datashard.cpp index 34759e7f11..d86568b4a1 100644 --- a/ydb/core/tx/datashard/datashard.cpp +++ b/ydb/core/tx/datashard/datashard.cpp @@ -1128,10 +1128,10 @@ void TDataShard::EnableKeyAccessSampling(const TActorContext &ctx, TInstant unti CurrentKeySampler = EnabledKeySampler; StartedKeyAccessSamplingAt = AppData(ctx)->TimeProvider->Now(); LOG_NOTICE_S(ctx, NKikimrServices::TX_DATASHARD, "Started key access sampling at datashard: " << TabletID()); - } else { - LOG_NOTICE_S(ctx, NKikimrServices::TX_DATASHARD, "Extended key access sampling at datashard: " << TabletID()); + } else { + LOG_NOTICE_S(ctx, NKikimrServices::TX_DATASHARD, "Extended key access sampling at datashard: " << TabletID()); } - StopKeyAccessSamplingAt = until; + StopKeyAccessSamplingAt = until; } bool TDataShard::OnRenderAppHtmlPage(NMon::TEvRemoteHttpInfo::TPtr ev, const TActorContext &ctx) { @@ -2248,21 +2248,21 @@ void TDataShard::Handle(TEvDataShard::TEvGetDataHistogramRequest::TPtr &ev, { auto *response = new TEvDataShard::TEvGetDataHistogramResponse; response->Record.MutableStatus()->SetCode(Ydb::StatusIds::SUCCESS); - const auto& rec = ev->Get()->Record; - - if (rec.GetCollectKeySampleMs() > 0) { - EnableKeyAccessSampling(ctx, - AppData(ctx)->TimeProvider->Now() + TDuration::MilliSeconds(rec.GetCollectKeySampleMs())); - } - - if (rec.GetActualData()) { - if (CurrentKeySampler == DisabledKeySampler) { - // datashard stores expired stats - ctx.Send(ev->Sender, response); - return; - } - } - + const auto& rec = ev->Get()->Record; + + if (rec.GetCollectKeySampleMs() > 0) { + EnableKeyAccessSampling(ctx, + AppData(ctx)->TimeProvider->Now() + TDuration::MilliSeconds(rec.GetCollectKeySampleMs())); + } + + if (rec.GetActualData()) { + if (CurrentKeySampler == DisabledKeySampler) { + // datashard stores expired stats + ctx.Send(ev->Sender, response); + return; + } + } + auto ® = *AppData(ctx)->TypeRegistry; for (const auto &pr : TableInfos) { const auto &tinfo = *pr.second; diff --git a/ydb/core/viewer/json_hotkeys.h b/ydb/core/viewer/json_hotkeys.h index f2b2116197..290e385a9b 100644 --- a/ydb/core/viewer/json_hotkeys.h +++ b/ydb/core/viewer/json_hotkeys.h @@ -1,164 +1,164 @@ -#pragma once -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/mon.h> +#pragma once +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/mon.h> #include <ydb/core/base/tablet_pipe.h> #include <ydb/core/protos/services.pb.h> #include <ydb/core/tx/schemeshard/schemeshard.h> #include <ydb/core/tx/datashard/datashard.h> #include <ydb/core/tx/tx_proxy/proxy.h> -#include <util/generic/hash.h> -#include <util/generic/fwd.h> -#include "viewer.h" -#include "json_pipe_req.h" - -namespace NKikimr { -namespace NViewer { - -using namespace NActors; +#include <util/generic/hash.h> +#include <util/generic/fwd.h> +#include "viewer.h" +#include "json_pipe_req.h" + +namespace NKikimr { +namespace NViewer { + +using namespace NActors; using NSchemeShard::TEvSchemeShard; - -class TJsonHotkeys : public TViewerPipeClient<TJsonHotkeys> { - static const bool WithRetry = false; - using TBase = TViewerPipeClient<TJsonHotkeys>; + +class TJsonHotkeys : public TViewerPipeClient<TJsonHotkeys> { + static const bool WithRetry = false; + using TBase = TViewerPipeClient<TJsonHotkeys>; IViewer* Viewer; - NMon::TEvHttpInfo::TPtr Event; + NMon::TEvHttpInfo::TPtr Event; TAutoPtr<TEvSchemeShard::TEvDescribeSchemeResult> DescribeResult; ui32 Timeout = 0; ui32 Limit = 0; float PollingFactor = 0.0; bool EnableSampling = false; - - struct KeysComparator { - bool operator ()(const std::pair<ui64, TVector<TString>>& a, const std::pair<ui64, TVector<TString>>& b) const { - return a.first > b.first; - }; - }; - - TMultiSet<std::pair<ui64, TVector<TString>>, KeysComparator> Keys; - -public: - static constexpr NKikimrServices::TActivity::EType ActorActivityType() { - return NKikimrServices::TActivity::VIEWER_HANDLER; - } - + + struct KeysComparator { + bool operator ()(const std::pair<ui64, TVector<TString>>& a, const std::pair<ui64, TVector<TString>>& b) const { + return a.first > b.first; + }; + }; + + TMultiSet<std::pair<ui64, TVector<TString>>, KeysComparator> Keys; + +public: + static constexpr NKikimrServices::TActivity::EType ActorActivityType() { + return NKikimrServices::TActivity::VIEWER_HANDLER; + } + TJsonHotkeys(IViewer* viewer, NMon::TEvHttpInfo::TPtr &ev) : Viewer(viewer) , Event(ev) - {} - + {} + void FillParams(NKikimrSchemeOp::TDescribePath* record, const TCgiParameters& params) { - if (params.Has("path")) { - record->SetPath(params.Get("path")); - } - record->MutableOptions()->SetReturnPartitionStats(true); - } - + if (params.Has("path")) { + record->SetPath(params.Get("path")); + } + record->MutableOptions()->SetReturnPartitionStats(true); + } + void Bootstrap() { - const auto& params(Event->Get()->Request.GetParams()); - Timeout = FromStringWithDefault<ui32>(params.Get("timeout"), 10000); - Limit = FromStringWithDefault<ui32>(params.Get("limit"), 10); - PollingFactor = std::max(0.0f, std::min(FromStringWithDefault<float>(params.Get("polling_factor"), 0.2), 1.0f)); - EnableSampling = FromStringWithDefault<bool>(params.Get("enable_sampling"), false); - InitConfig(params); - - THolder<TEvTxUserProxy::TEvNavigate> request = MakeHolder<TEvTxUserProxy::TEvNavigate>(); - FillParams(request->Record.MutableDescribePath(), params); - request->Record.SetUserToken(Event->Get()->UserToken); + const auto& params(Event->Get()->Request.GetParams()); + Timeout = FromStringWithDefault<ui32>(params.Get("timeout"), 10000); + Limit = FromStringWithDefault<ui32>(params.Get("limit"), 10); + PollingFactor = std::max(0.0f, std::min(FromStringWithDefault<float>(params.Get("polling_factor"), 0.2), 1.0f)); + EnableSampling = FromStringWithDefault<bool>(params.Get("enable_sampling"), false); + InitConfig(params); + + THolder<TEvTxUserProxy::TEvNavigate> request = MakeHolder<TEvTxUserProxy::TEvNavigate>(); + FillParams(request->Record.MutableDescribePath(), params); + request->Record.SetUserToken(Event->Get()->UserToken); SendRequest(MakeTxProxyID(), request.Release()); - + Become(&TThis::StateRequestedDescribe, TDuration::MilliSeconds(Timeout), new TEvents::TEvWakeup()); - } - + } + STATEFN(StateRequestedDescribe) { - switch (ev->GetTypeRewrite()) { + switch (ev->GetTypeRewrite()) { hFunc(TEvSchemeShard::TEvDescribeSchemeResult, Handle); hFunc(TEvDataShard::TEvGetDataHistogramResponse, Handle); hFunc(TEvTabletPipe::TEvClientConnected, TBase::Handle); cFunc(TEvents::TSystem::Wakeup, HandleTimeout); - } - } - + } + } + void Handle(TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev) { - DescribeResult = ev->Release(); - const auto& pathDescription = DescribeResult->GetRecord().GetPathDescription(); - const auto& partitions = pathDescription.GetTablePartitions(); - const auto& metrics = pathDescription.GetTablePartitionMetrics(); - TVector<std::pair<ui64, int>> tabletsOrder; - - for (int i = 0; i < metrics.size(); ++i) { - tabletsOrder.emplace_back(metrics.Get(i).GetCPU(), i); - } - - Sort(tabletsOrder, std::greater<std::pair<ui64, int>>()); + DescribeResult = ev->Release(); + const auto& pathDescription = DescribeResult->GetRecord().GetPathDescription(); + const auto& partitions = pathDescription.GetTablePartitions(); + const auto& metrics = pathDescription.GetTablePartitionMetrics(); + TVector<std::pair<ui64, int>> tabletsOrder; + + for (int i = 0; i < metrics.size(); ++i) { + tabletsOrder.emplace_back(metrics.Get(i).GetCPU(), i); + } + + Sort(tabletsOrder, std::greater<std::pair<ui64, int>>()); ui32 tablets = (ui32) std::max(1, (int) std::ceil(PollingFactor * tabletsOrder.size())); - + for (ui32 i = 0; i < tablets; ++i) { - THolder<TEvDataShard::TEvGetDataHistogramRequest> request = MakeHolder<TEvDataShard::TEvGetDataHistogramRequest>(); - if (EnableSampling) { - request->Record.SetCollectKeySampleMs(30000); // 30 sec - } - request->Record.SetActualData(true); - ui64 datashardId = partitions.Get(tabletsOrder[i].second).GetDatashardId(); + THolder<TEvDataShard::TEvGetDataHistogramRequest> request = MakeHolder<TEvDataShard::TEvGetDataHistogramRequest>(); + if (EnableSampling) { + request->Record.SetCollectKeySampleMs(30000); // 30 sec + } + request->Record.SetActualData(true); + ui64 datashardId = partitions.Get(tabletsOrder[i].second).GetDatashardId(); SendRequestToPipe(ConnectTabletPipe(datashardId), request.Release()); - } - } - + } + } + void Handle(TEvDataShard::TEvGetDataHistogramResponse::TPtr& ev) { - const auto& rec = ev->Get()->Record; - for (const auto& i: rec.GetTableHistograms()) { - for (const auto& item: i.GetKeyAccessSample().GetItems()) { - TVector<TString> keys(item.GetKeyValues().begin(), item.GetKeyValues().end()); - Keys.emplace(item.GetValue(), std::move(keys)); - if (Keys.size() > Limit) { - Keys.erase(--Keys.end()); - } - } - } - + const auto& rec = ev->Get()->Record; + for (const auto& i: rec.GetTableHistograms()) { + for (const auto& item: i.GetKeyAccessSample().GetItems()) { + TVector<TString> keys(item.GetKeyValues().begin(), item.GetKeyValues().end()); + Keys.emplace(item.GetValue(), std::move(keys)); + if (Keys.size() > Limit) { + Keys.erase(--Keys.end()); + } + } + } + RequestDone(); - } - - NJson::TJsonValue BuildResponse() { - NJson::TJsonValue root; - if (DescribeResult != nullptr) { - NJson::TJsonValue& hotkeys = root["hotkeys"]; - for (const auto &i: Keys) { - NJson::TJsonValue entry; - NJson::TJsonValue keyValues; - for (const auto &j: i.second) { - keyValues.AppendValue(j); - } - entry["accessSample"] = i.first; - entry["keyValues"] = std::move(keyValues); - hotkeys.AppendValue(std::move(entry)); - } - } - return root; - } - + } + + NJson::TJsonValue BuildResponse() { + NJson::TJsonValue root; + if (DescribeResult != nullptr) { + NJson::TJsonValue& hotkeys = root["hotkeys"]; + for (const auto &i: Keys) { + NJson::TJsonValue entry; + NJson::TJsonValue keyValues; + for (const auto &j: i.second) { + keyValues.AppendValue(j); + } + entry["accessSample"] = i.first; + entry["keyValues"] = std::move(keyValues); + hotkeys.AppendValue(std::move(entry)); + } + } + return root; + } + void ReplyAndPassAway() { TString headers = Viewer->GetHTTPOKJSON(); - if (DescribeResult != nullptr) { - switch (DescribeResult->GetRecord().GetStatus()) { + if (DescribeResult != nullptr) { + switch (DescribeResult->GetRecord().GetStatus()) { case NKikimrScheme::StatusAccessDenied: - headers = HTTPFORBIDDENJSON; - break; - default: - break; - } - } - NJson::TJsonValue root = BuildResponse(); - TString json = NJson::WriteJson(root, false); - + headers = HTTPFORBIDDENJSON; + break; + default: + break; + } + } + NJson::TJsonValue root = BuildResponse(); + TString json = NJson::WriteJson(root, false); + Send(Event->Sender, new NMon::TEvHttpInfoRes(headers + json, 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); - } - + } + void HandleTimeout() { Send(Event->Sender, new NMon::TEvHttpInfoRes(Viewer->GetHTTPGATEWAYTIMEOUT(), 0, NMon::IEvHttpInfoRes::EContentType::Custom)); PassAway(); - } -}; + } +}; -} -} +} +} diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/json_query.h index 2344506578..600d8088e1 100644 --- a/ydb/core/viewer/json_query.h +++ b/ydb/core/viewer/json_query.h @@ -29,7 +29,7 @@ class TJsonQuery : public TActorBootstrapped<TJsonQuery> { ui32 Timeout = 0; TVector<Ydb::ResultSet> ResultSets; TString Action; - TString Stats; + TString Stats; public: static constexpr NKikimrServices::TActivity::EType ActorActivityType() { @@ -67,7 +67,7 @@ public: Timeout = FromStringWithDefault<ui32>(params.Get("timeout"), 60000); TString query = params.Get("query"); TString database = params.Get("database"); - Stats = params.Get("stats"); + Stats = params.Get("stats"); Action = params.Get("action"); if (query.empty() && Event->Get()->Request.GetMethod() == HTTP_METHOD_POST) { TStringBuf content = Event->Get()->Request.GetPostContent(); @@ -83,7 +83,7 @@ public: if (success) { query = requestData["query"].GetStringSafe({}); database = requestData["database"].GetStringSafe({}); - Stats = requestData["stats"].GetStringSafe({}); + Stats = requestData["stats"].GetStringSafe({}); Action = requestData["action"].GetStringSafe({}); } } @@ -107,9 +107,9 @@ public: request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN); request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML); } - if (Stats == "profile") { + if (Stats == "profile") { request.SetStatsMode(NYql::NDqProto::DQ_STATS_MODE_PROFILE); - } + } if (database) { request.SetDatabase(database); } @@ -185,16 +185,16 @@ private: case NYdb::TTypeParser::ETypeKind::Optional: valueParser.OpenOptional(); - if (valueParser.IsNull()) { - return NJson::JSON_NULL; - } - switch(valueParser.GetKind()) { - case NYdb::TTypeParser::ETypeKind::Primitive: + if (valueParser.IsNull()) { + return NJson::JSON_NULL; + } + switch(valueParser.GetKind()) { + case NYdb::TTypeParser::ETypeKind::Primitive: return ColumnPrimitiveValueToJsonValue(valueParser); - case NYdb::TTypeParser::ETypeKind::Decimal: - return valueParser.GetDecimal().ToString(); - default: - return NJson::JSON_UNDEFINED; + case NYdb::TTypeParser::ETypeKind::Decimal: + return valueParser.GetDecimal().ToString(); + default: + return NJson::JSON_UNDEFINED; } default: @@ -208,10 +208,10 @@ private: if (record.GetYdbStatus() == Ydb::StatusIds::SUCCESS) { const auto& response = record.GetResponse(); out << Viewer->GetHTTPOKJSON(); - if (!Stats.empty()) { - out << "{\"result\":"; - } - if (response.ResultsSize() > 0) { + if (!Stats.empty()) { + out << "{\"result\":"; + } + if (response.ResultsSize() > 0) { const auto &result = response.GetResults(); if (result.empty()) { out << "[]"; @@ -231,43 +231,43 @@ private: } } } else if (ResultSets.size() > 0) { - out << "["; - bool comma = false; + out << "["; + bool comma = false; for (auto it = ResultSets.begin(); it != ResultSets.end(); ++it) { NYdb::TResultSet resultSet(*it); const auto& columnsMeta = resultSet.GetColumnsMeta(); NYdb::TResultSetParser rsParser(resultSet); while (rsParser.TryNextRow()) { - if (comma) { - out << ","; - } - out << "{"; + if (comma) { + out << ","; + } + out << "{"; for (size_t columnNum = 0; columnNum < columnsMeta.size(); ++columnNum) { const NYdb::TColumn& columnMeta = columnsMeta[columnNum]; - out << "\"" << TProtoToJson::EscapeJsonString(columnMeta.Name) << "\":"; - out << NJson::WriteJson(ColumnValueToJsonValue(rsParser.ColumnParser(columnNum)), false); - if (columnNum + 1 < columnsMeta.size()) { - out << ","; - } + out << "\"" << TProtoToJson::EscapeJsonString(columnMeta.Name) << "\":"; + out << NJson::WriteJson(ColumnValueToJsonValue(rsParser.ColumnParser(columnNum)), false); + if (columnNum + 1 < columnsMeta.size()) { + out << ","; + } } - out << "}"; - comma = true; + out << "}"; + comma = true; } } - out << ']'; - } else if (response.HasQueryPlan()) { - if (Action == "explain-ast") { - out << "{\"ast\":\"" << TProtoToJson::EscapeJsonString(response.GetQueryAst()) << "\"}"; - } else { - out << response.GetQueryPlan(); - } + out << ']'; + } else if (response.HasQueryPlan()) { + if (Action == "explain-ast") { + out << "{\"ast\":\"" << TProtoToJson::EscapeJsonString(response.GetQueryAst()) << "\"}"; + } else { + out << response.GetQueryPlan(); + } + } + if (!Stats.empty()) { + out << ",\"stats\":"; + TStringStream json; + TProtoToJson::ProtoToJson(json, response.GetQueryStats(), JsonSettings); + out << json.Str() << "}"; } - if (!Stats.empty()) { - out << ",\"stats\":"; - TStringStream json; - TProtoToJson::ProtoToJson(json, response.GetQueryStats(), JsonSettings); - out << json.Str() << "}"; - } } else { out << "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n"; diff --git a/ydb/core/viewer/viewer.cpp b/ydb/core/viewer/viewer.cpp index 37bb376139..f1124115bf 100644 --- a/ydb/core/viewer/viewer.cpp +++ b/ydb/core/viewer/viewer.cpp @@ -21,7 +21,7 @@ #include "json_vdiskinfo.h" #include "json_pdiskinfo.h" #include "json_describe.h" -#include "json_hotkeys.h" +#include "json_hotkeys.h" #include "json_sysinfo.h" #include "json_tabletinfo.h" #include "json_hiveinfo.h" @@ -180,7 +180,7 @@ public: JsonHandlers["/json/vdiskinfo"] = new TJsonHandler<TJsonVDiskInfo>; JsonHandlers["/json/pdiskinfo"] = new TJsonHandler<TJsonPDiskInfo>; JsonHandlers["/json/describe"] = new TJsonHandler<TJsonDescribe>; - JsonHandlers["/json/hotkeys"] = new TJsonHandler<TJsonHotkeys>; + JsonHandlers["/json/hotkeys"] = new TJsonHandler<TJsonHotkeys>; JsonHandlers["/json/sysinfo"] = new TJsonHandler<TJsonSysInfo>; JsonHandlers["/json/tabletinfo"] = new TJsonHandler<TJsonTabletInfo>; JsonHandlers["/json/hiveinfo"] = new TJsonHandler<TJsonHiveInfo>; diff --git a/ydb/core/viewer/ya.make b/ydb/core/viewer/ya.make index 24da8f02b0..214e3b6726 100644 --- a/ydb/core/viewer/ya.make +++ b/ydb/core/viewer/ya.make @@ -25,7 +25,7 @@ SRCS( json_describe.h json_healthcheck.h json_hiveinfo.h - json_hotkeys.h + json_hotkeys.h json_labeledcounters.h json_metainfo.h json_netinfo.h diff --git a/ydb/public/lib/value/value.cpp b/ydb/public/lib/value/value.cpp index bc3f5db6cd..0ed8b82689 100644 --- a/ydb/public/lib/value/value.cpp +++ b/ydb/public/lib/value/value.cpp @@ -419,10 +419,10 @@ TString TValue::GetDataText() const { return ToString(Value.GetUint64()); case NScheme::NTypeIds::Interval: return ToString(Value.GetInt64()); - case NScheme::NTypeIds::JsonDocument: - return "\"<JsonDocument>\""; + case NScheme::NTypeIds::JsonDocument: + return "\"<JsonDocument>\""; } - return TStringBuilder() << "\"<unknown type " << Type.GetData().GetScheme() << ">\""; + return TStringBuilder() << "\"<unknown type " << Type.GetData().GetScheme() << ">\""; } template <> TString TValue::GetTypeText<TFormatCxx>(const TFormatCxx& format) const { |