Skip to content

Commit eddfef2

Browse files
authored
Merge 9574784 into 3dd67fb
2 parents 3dd67fb + 9574784 commit eddfef2

File tree

7 files changed

+88
-2
lines changed

7 files changed

+88
-2
lines changed

ydb/core/viewer/json_handlers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ class TJsonHandler : public TJsonHandlerBase {
5252
struct TJsonHandlers {
5353
std::vector<TString> JsonHandlersList;
5454
THashMap<TString, std::shared_ptr<TJsonHandlerBase>> JsonHandlersIndex;
55+
std::map<TString, int> Capabilities;
5556

56-
void AddHandler(const TString& name, TJsonHandlerBase* handler) {
57+
void AddHandler(const TString& name, TJsonHandlerBase* handler, int version = 1) {
5758
JsonHandlersList.push_back(name);
5859
JsonHandlersIndex[name] = std::shared_ptr<TJsonHandlerBase>(handler);
60+
Capabilities[name] = version;
5961
}
6062

6163
TJsonHandlerBase* FindHandler(const TString& name) const {

ydb/core/viewer/json_handlers_viewer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444

4545
namespace NKikimr::NViewer {
4646

47+
void InitViewerCapabilitiesJsonHandler(TJsonHandlers& jsonHandlers);
48+
4749
void InitViewerJsonHandlers(TJsonHandlers& jsonHandlers) {
50+
InitViewerCapabilitiesJsonHandler(jsonHandlers);
4851
jsonHandlers.AddHandler("/viewer/nodelist", new TJsonHandler<TJsonNodeList>);
4952
jsonHandlers.AddHandler("/viewer/nodeinfo", new TJsonHandler<TJsonNodeInfo>);
5053
jsonHandlers.AddHandler("/viewer/sysinfo", new TJsonHandler<TJsonSysInfo>);

ydb/core/viewer/storage_groups.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ YAML::Node TJsonRequestSwagger<TStorageGroups>::GetSwagger() {
17001700
YAML::Node node = YAML::Load(R"___(
17011701
post:
17021702
tags:
1703-
- viewer
1703+
- storage
17041704
summary: Storage groups
17051705
description: Information about storage groups
17061706
parameters:

ydb/core/viewer/viewer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
355355
return {};
356356
}
357357

358+
NJson::TJsonValue GetCapabilities() override {
359+
std::lock_guard guard(JsonHandlersMutex);
360+
NJson::TJsonValue capabilities(NJson::JSON_MAP);
361+
for (const auto& [name, version] : JsonHandlers.Capabilities) {
362+
capabilities[name] = version;
363+
}
364+
return capabilities;
365+
}
366+
358367
void RegisterVirtualHandler(
359368
NKikimrViewer::EObjectType parentObjectType,
360369
TVirtualHandlerType handler) override {
@@ -385,6 +394,7 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
385394

386395
private:
387396
TJsonHandlers JsonHandlers;
397+
std::mutex JsonHandlersMutex;
388398
std::unordered_map<TString, TString> Redirect307;
389399
const TKikimrRunConfig KikimrRunConfig;
390400
std::unordered_multimap<NKikimrViewer::EObjectType, TVirtualHandler> VirtualHandlersByParentType;

ydb/core/viewer/viewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class IViewer {
206206
virtual void AddRunningQuery(const TString& queryId, const TActorId& actorId) = 0;
207207
virtual void EndRunningQuery(const TString& queryId, const TActorId& actorId) = 0;
208208
virtual TActorId FindRunningQuery(const TString& queryId) = 0;
209+
210+
virtual NJson::TJsonValue GetCapabilities() = 0;
209211
};
210212

211213
void SetupPQVirtualHandlers(IViewer* viewer);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <unordered_map>
2+
#include <ydb/library/actors/core/actor_bootstrapped.h>
3+
#include <library/cpp/json/json_writer.h>
4+
#include "viewer.h"
5+
#include "json_handlers.h"
6+
#include "json_pipe_req.h"
7+
8+
namespace NKikimr {
9+
namespace NViewer {
10+
11+
using namespace NActors;
12+
13+
class TViewerCapabilities : public TViewerPipeClient<TViewerCapabilities> {
14+
public:
15+
using TBase = TViewerPipeClient<TViewerCapabilities>;
16+
17+
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
18+
return NKikimrServices::TActivity::VIEWER_HANDLER;
19+
}
20+
21+
TViewerCapabilities(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
22+
: TBase(viewer, ev)
23+
{}
24+
25+
void Bootstrap() {
26+
ReplyAndPassAway();
27+
}
28+
29+
void ReplyAndPassAway() {
30+
NJson::TJsonValue json;
31+
json["Capabilities"] = Viewer->GetCapabilities();
32+
TBase::ReplyAndPassAway(GetHTTPOKJSON(NJson::WriteJson(json, false)));
33+
}
34+
};
35+
36+
template <>
37+
YAML::Node TJsonRequestSwagger<TViewerCapabilities>::GetSwagger() {
38+
YAML::Node node = YAML::Load(R"___(
39+
post:
40+
tags:
41+
- viewer
42+
summary: Viewer capabilities
43+
description: Viewer capabilities
44+
responses:
45+
200:
46+
description: OK
47+
content:
48+
application/json:
49+
schema:
50+
type: object
51+
description: format depends on schema parameter
52+
400:
53+
description: Bad Request
54+
403:
55+
description: Forbidden
56+
504:
57+
description: Gateway Timeout
58+
)___");
59+
return node;
60+
}
61+
62+
63+
void InitViewerCapabilitiesJsonHandler(TJsonHandlers& jsonHandlers) {
64+
jsonHandlers.AddHandler("/viewer/capabilities", new TJsonHandler<TViewerCapabilities>());
65+
}
66+
67+
} // namespace NViewer
68+
} // namespace NKikimr

ydb/core/viewer/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SRCS(
7070
scheme_directory.h
7171
storage_groups.cpp
7272
query_autocomplete_helper.h
73+
viewer_capabilities.cpp
7374
viewer_request.cpp
7475
viewer_request.h
7576
viewer.cpp

0 commit comments

Comments
 (0)