Skip to content

Commit

Permalink
Add edit main config in ui feature
Browse files Browse the repository at this point in the history
add edit main config in ui feature
  • Loading branch information
Enjection committed Nov 28, 2023
1 parent 5e35ed8 commit f7b4a06
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 7 deletions.
1 change: 1 addition & 0 deletions ydb/core/cms/console/configs_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const THashSet<ui32> DYNAMIC_KINDS({
(ui32)NKikimrConsole::TConfigItem::TableServiceConfigItem,
(ui32)NKikimrConsole::TConfigItem::TenantPoolConfigItem,
(ui32)NKikimrConsole::TConfigItem::TenantSlotBrokerConfigItem,
(ui32)NKikimrConsole::TConfigItem::AllowEditYamlInUiItem,
});

const THashSet<ui32> NON_YAML_KINDS({
Expand Down
9 changes: 9 additions & 0 deletions ydb/core/cms/console/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct TEvConsole {
EvReplaceYamlConfigRequest,
EvGetAllMetadataRequest,
EvGetNodeLabelsRequest,
EvIsYamlReadOnlyRequest,

// responses
EvCreateTenantResponse = EvCreateTenantRequest + 1024,
Expand Down Expand Up @@ -100,6 +101,8 @@ struct TEvConsole {
EvDisabled,
EvGenericError,

EvIsYamlReadOnlyResponse,

EvEnd
};

Expand Down Expand Up @@ -196,6 +199,12 @@ struct TEvConsole {
using TResponse = TEvGetAllConfigsResponse;
};

struct TEvIsYamlReadOnlyResponse : public TEventShortDebugPB<TEvIsYamlReadOnlyResponse, NKikimrConsole::TIsYamlReadOnlyResponse, EvIsYamlReadOnlyResponse> {};

struct TEvIsYamlReadOnlyRequest : public TEventShortDebugPB<TEvIsYamlReadOnlyRequest, NKikimrConsole::TIsYamlReadOnlyRequest, EvIsYamlReadOnlyRequest> {
using TResponse = TEvIsYamlReadOnlyResponse;
};

struct TEvGetAllMetadataResponse : public TEventShortDebugPB<TEvGetAllMetadataResponse, NKikimrConsole::TGetAllMetadataResponse, EvGetAllMetadataResponse> {};

struct TEvGetAllMetadataRequest : public TEventShortDebugPB<TEvGetAllMetadataRequest, NKikimrConsole::TGetAllMetadataRequest, EvGetAllMetadataRequest> {
Expand Down
22 changes: 22 additions & 0 deletions ydb/core/cms/console/console_configs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ void TConfigsManager::Bootstrap(const TActorContext &ctx)
false,
NKikimrServices::CMS_CONFIGS);
ConfigsProvider = ctx.Register(new TConfigsProvider(ctx.SelfID));

ui32 item = (ui32)NKikimrConsole::TConfigItem::AllowEditYamlInUiItem;
ctx.Send(MakeConfigsDispatcherID(SelfId().NodeId()),
new TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest(item));
}

void TConfigsManager::Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev,
const TActorContext &ctx)
{
auto &rec = ev->Get()->Record;

YamlReadOnly = !rec.GetConfig().GetAllowEditYamlInUi();

auto resp = MakeHolder<TEvConsole::TEvConfigNotificationResponse>(rec);
ctx.Send(ev->Sender, resp.Release(), 0, ev->Cookie);
}

void TConfigsManager::Detach()
Expand Down Expand Up @@ -627,6 +642,13 @@ void TConfigsManager::Handle(TEvConsole::TEvDropConfigRequest::TPtr &ev, const T
TxProcessor->ProcessTx(CreateTxDropYamlConfig(ev), ctx);
}

void TConfigsManager::Handle(TEvConsole::TEvIsYamlReadOnlyRequest::TPtr &ev, const TActorContext &ctx)
{
auto response = MakeHolder<TEvConsole::TEvIsYamlReadOnlyResponse>();
response->Record.SetReadOnly(YamlReadOnly);
ctx.Send(ev->Sender, response.Release());
}

void TConfigsManager::Handle(TEvConsole::TEvGetAllConfigsRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxGetYamlConfig(ev), ctx);
Expand Down
7 changes: 7 additions & 0 deletions ydb/core/cms/console/console_configs_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "logger.h"
#include "tx_processor.h"
#include "console_configs_provider.h"
#include "configs_dispatcher.h"

#include <ydb/core/actorlib_impl/long_timer.h>
#include <ydb/core/base/tablet_pipe.h>
Expand Down Expand Up @@ -133,6 +134,7 @@ class TConfigsManager : public TActorBootstrapped<TConfigsManager> {
void Handle(TEvConsole::TEvAddConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigNotificationResponse::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigureRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvListConfigValidatorsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvRemoveConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvRemoveConfigSubscriptionsRequest::TPtr &ev, const TActorContext &ctx);
Expand All @@ -142,6 +144,7 @@ class TConfigsManager : public TActorBootstrapped<TConfigsManager> {
void Handle(TEvConsole::TEvGetNodeLabelsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvResolveConfigRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvResolveAllConfigRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvIsYamlReadOnlyRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvGetAllConfigsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvGetAllMetadataRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvAddVolatileConfigRequest::TPtr &ev, const TActorContext &ctx);
Expand Down Expand Up @@ -182,6 +185,8 @@ class TConfigsManager : public TActorBootstrapped<TConfigsManager> {
HFuncTraced(TEvConsole::TEvConfigureRequest, Handle);
HFunc(TEvConsole::TEvResolveConfigRequest, Handle);
HFunc(TEvConsole::TEvResolveAllConfigRequest, Handle);
HFunc(TEvConsole::TEvConfigNotificationRequest, Handle);
HFunc(TEvConsole::TEvIsYamlReadOnlyRequest, Handle);
HFunc(TEvConsole::TEvGetAllConfigsRequest, HandleWithRights);
HFunc(TEvConsole::TEvGetNodeLabelsRequest, HandleWithRights);
HFunc(TEvConsole::TEvGetAllMetadataRequest, HandleWithRights);
Expand All @@ -206,6 +211,7 @@ class TConfigsManager : public TActorBootstrapped<TConfigsManager> {
FFunc(TEvConsole::EvConfigSubscriptionRequest, ForwardToConfigsProvider);
FFunc(TEvConsole::EvConfigSubscriptionCanceled, ForwardToConfigsProvider);
CFunc(TEvPrivate::EvCleanupLog, CleanupLog);
IgnoreFunc(TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse);

default:
Y_ABORT("TConfigsManager::StateWork unexpected event type: %" PRIx32 " event: %s",
Expand Down Expand Up @@ -257,6 +263,7 @@ class TConfigsManager : public TActorBootstrapped<TConfigsManager> {
ui32 YamlVersion = 0;
TString YamlConfig;
bool YamlDropped = false;
bool YamlReadOnly = true;
TMap<ui64, TString> VolatileYamlConfigs;
};

Expand Down
1 change: 1 addition & 0 deletions ydb/core/cms/console/console_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TConsole : public TActor<TConsole>
FFunc(TEvConsole::EvAlterTenantRequest, ForwardToTenantsManager);
FFunc(TEvConsole::EvCheckConfigUpdatesRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvConfigNotificationResponse, ForwardToConfigsManager);
FFunc(TEvConsole::EvIsYamlReadOnlyRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvConfigureRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvGetAllConfigsRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvGetAllMetadataRequest, ForwardToConfigsManager);
Expand Down
6 changes: 6 additions & 0 deletions ydb/core/cms/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ class TCmsHttp : public TActorBootstrapped<TCmsHttp> {
ApiHandlers["/api/console/yamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvGetAllConfigsRequest,
NConsole::TEvConsole::TEvGetAllConfigsResponse, true, true>>;

ApiHandlers["/api/console/readonly"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvIsYamlReadOnlyRequest,
NConsole::TEvConsole::TEvIsYamlReadOnlyResponse, true, true>>;

ApiHandlers["/api/console/removevolatileyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvRemoveVolatileConfigRequest,
NConsole::TEvConsole::TEvRemoveVolatileConfigResponse, true, true>>;

ApiHandlers["/api/console/configureyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvReplaceYamlConfigRequest,
NConsole::TEvConsole::TEvReplaceYamlConfigResponse, true, true>>;

ApiHandlers["/api/console/configurevolatileyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvAddVolatileConfigRequest,
NConsole::TEvConsole::TEvAddVolatileConfigResponse, true, true>>;

Expand Down
6 changes: 4 additions & 2 deletions ydb/core/cms/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ <h5 class="mb-0">
</h5>
</div>
<div id="yaml-collapse-one" class="collapse show" aria-labelledby="yaml-heading-one">
<div class="card-body">
<form style="flex:1 1 auto; margin-bottom: 0px;">
<div class="card-body clearfix">
<form style="flex:1 1 auto;">
<div class="yaml-sticky-btn-wrap link-yaml-config yaml-btn-4" id="link-yaml-config" title="copy to resolver">
<div class="yaml-sticky-btn"></div>
</div>
Expand All @@ -321,6 +321,8 @@ <h5 class="mb-0">
</div>
<div id="main-editor-container"></div>
</form>
<button type="button" class="btn btn-success float-right disabled" id="yaml-apply-button"
title="Set config field 'allow_edit_yaml_in_ui' to 'true' to enable this button">Apply</button>
</div>
</div>
</div>
Expand Down
72 changes: 67 additions & 5 deletions ydb/core/cms/ui/yaml_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,81 @@ class YamlConfigState {
constructor() {
this.fetchInterval = 5000;
this.url = 'cms/api/console/yamlconfig';
this.resolveUrl = 'cms/api/console/resolveyamlconfig'
this.resolveAllUrl = 'cms/api/console/resolveallyamlconfig'
this.readOnlyUrl = 'cms/api/console/readonly';
this.resolveUrl = 'cms/api/console/resolveyamlconfig';
this.resolveAllUrl = 'cms/api/console/resolveallyamlconfig';
this.removeVolatileUrl = 'cms/api/console/removevolatileyamlconfig';
this.applyUrl = 'cms/api/console/configurevolatileyamlconfig';
this.applyUrl = 'cms/api/console/configureyamlconfig';
this.applyVolatileUrl = 'cms/api/console/configurevolatileyamlconfig';
this.readOnly = true;
this.maxVolatileId = -1;
this.volatileConfigs = [];
this.codeMirrors = [];
this.initTab();
}

changeReadOnlyState(state) {
if (this.readOnly == state)
return;

this.readOnly = state;
var btn = $('#yaml-apply-button');

if (this.readOnly) {
btn.addClass("disabled");
btn.prop("onclick", null).off("click");
btn.attr("title", "Set config field 'allow_edit_yaml_in_ui' to 'true' to enable this button");
} else {
btn.removeClass("disabled");
btn.removeAttr("title");
var self = this;
btn.on('click', function(event) {
event.preventDefault();
showAck("Apply new config?", " ", "Yes", "No", self.setConfig.bind(self));
});
}

if (this.codeMirror) {
this.codeMirror.updateOptions({ readOnly: this.readOnly });
}
}

setConfig() {
var cmd = {
Request: {
config: this.codeMirror.getValue(),
},
};

$.post(this.applyUrl, JSON.stringify(cmd))
.done(this.onSetConfig.bind(this, true))
.fail(this.onSetConfig.bind(this, false));
}

onSetConfig(success, data) {
if (success) {
// ok, do nothing
} else {
var message = "";
if (data.hasOwnProperty('responseJSON')) {
message = data.responseJSON.issues;
} else {
message = data.responseText;
}
showToast("Error", "Can't set config\n" + message, 15000);
}
}

loadYaml() {
clearTimeout(this.loadYamlTimeout);
$.get(this.url).done(this.onYamlLoaded.bind(this, true)).fail(this.onYamlLoaded.bind(this, false));
$.get(this.readOnlyUrl).done(this.onReadOnlyLoaded.bind(this, true)).fail(this.onReadOnlyLoaded.bind(this, false));
}

onReadOnlyLoaded(success, data) {
if (success && data.hasOwnProperty('ReadOnly')) {
this.changeReadOnlyState(data.ReadOnly);
}
}

onYamlLoaded(success, data) {
Expand Down Expand Up @@ -264,7 +326,7 @@ class YamlConfigState {
},
};

$.post(this.applyUrl, JSON.stringify(cmd))
$.post(this.applyVolatileUrl, JSON.stringify(cmd))
.done(this.onVolatileConfigChanged.bind(this, true))
.fail(this.onVolatileConfigChanged.bind(this, false));

Expand Down Expand Up @@ -348,7 +410,7 @@ class YamlConfigState {

initTab() {
var self = this;
this.codeMirror = createEditor($("#main-editor-container").get(0), true, 1068);
this.codeMirror = createEditor($("#main-editor-container").get(0), this.readOnly, 1068);
this.config = "";
this.codeMirror.setValue(this.config);

Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ message TAppConfig {
optional TConveyorConfig CompConveyorConfig = 72;
optional TQueryServiceConfig QueryServiceConfig = 73;
optional TConveyorConfig InsertConveyorConfig = 74;
optional bool AllowEditYamlInUi = 75;

repeated TNamedConfig NamedConfigs = 100;
optional string ClusterYamlConfig = 101;
Expand Down
9 changes: 9 additions & 0 deletions ydb/core/protos/console_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ message TConfigItem {
CompConveyorConfigItem = 72;
QueryServiceConfigItem = 73;
InsertConveyorConfigItem = 74;
AllowEditYamlInUiItem = 75;

NamedConfigsItem = 100;
ClusterYamlConfigItem = 101;
Expand Down Expand Up @@ -285,6 +286,14 @@ message TGetAllConfigsResponse {
optional Ydb.DynamicConfig.GetConfigResult Response = 2;
}

message TIsYamlReadOnlyRequest {
optional bytes UserToken = 1;
}

message TIsYamlReadOnlyResponse {
optional bool ReadOnly = 1;
}

message TGetNodeLabelsRequest {
optional Ydb.DynamicConfig.GetNodeLabelsRequest Request = 1;
optional bytes UserToken = 2;
Expand Down

0 comments on commit f7b4a06

Please sign in to comment.