Skip to content

Commit 0402fc0

Browse files
authored
Mark options that are allowed to be used in the database configuration (#14761)
1 parent a48e948 commit 0402fc0

File tree

7 files changed

+90
-5
lines changed

7 files changed

+90
-5
lines changed

ydb/core/cms/console/console_configs_manager.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,30 @@ void TConfigsManager::ValidateDatabaseConfig(TUpdateDatabaseConfigOpContext& opC
148148
currentConfig = it->second.Config;
149149
}
150150
if (opCtx.UpdatedConfig != currentConfig) {
151-
auto tree = NFyaml::TDocument::Parse(MainYamlConfig);
152151
auto databaseTree = NFyaml::TDocument::Parse(opCtx.UpdatedConfig);
153-
NYamlConfig::AppendDatabaseConfig(tree, databaseTree);
154-
auto resolved = NYamlConfig::ResolveAll(tree);
152+
auto databaseConfig = NYamlConfig::ParseConfig(databaseTree);
155153

156154
TSimpleSharedPtr<NYamlConfig::TBasicUnknownFieldsCollector> unknownFieldsCollector = new NYamlConfig::TBasicUnknownFieldsCollector;
157155

156+
auto databaseCfg = NYamlConfig::YamlToProto(
157+
databaseConfig.Config,
158+
true,
159+
false,
160+
unknownFieldsCollector);
161+
158162
std::vector<TString> errors;
163+
NKikimr::NConfig::EValidationResult result = NKikimr::NConfig::ValidateDatabaseConfig(databaseCfg, errors);
164+
if (result == NKikimr::NConfig::EValidationResult::Error) {
165+
ythrow yexception() << errors.front();
166+
}
167+
168+
// TODO: validate databaseConfig.AllowedLabels & databaseConfig.Selectors too
169+
170+
auto tree = NFyaml::TDocument::Parse(MainYamlConfig);
171+
NYamlConfig::AppendDatabaseConfig(tree, databaseTree);
172+
auto resolved = NYamlConfig::ResolveAll(tree);
173+
174+
errors.clear();
159175
for (auto& [_, config] : resolved.Configs) {
160176
auto cfg = NYamlConfig::YamlToProto(
161177
config.second,

ydb/core/config/protos/marker.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ extend google.protobuf.FieldOptions {
5050
repeated string CopyTo = 82001;
5151
repeated string AsMap = 82002;
5252
repeated TAdvancedCopyTo AdvancedCopyTo = 82003;
53+
54+
// **Top-level** options marked with that label are allowed to be used in the database configuration.
55+
optional bool AllowInDatabaseConfig = 82004;
5356
}
5457

ydb/core/config/validation/validators.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "validators.h"
22

3+
#include <ydb/core/config/protos/marker.pb.h>
34
#include <ydb/core/protos/blobstorage.pb.h>
45
#include <ydb/core/protos/blobstorage_disk.pb.h>
56

7+
#include <library/cpp/protobuf/json/util.h>
8+
9+
#include <util/string/builder.h>
10+
611
#include <map>
712
#include <set>
813

@@ -161,6 +166,37 @@ EValidationResult ValidateStaticGroup(const NKikimrConfig::TAppConfig& current,
161166
return EValidationResult::Ok;
162167
}
163168

169+
EValidationResult ValidateDatabaseConfig(const NKikimrConfig::TAppConfig& config, std::vector<TString>& msg) {
170+
const auto* desc = config.GetDescriptor();
171+
const auto* reflection = config.GetReflection();
172+
173+
for (int i = 0; i < desc->field_count(); i++) {
174+
const auto* field = desc->field(i);
175+
176+
if (field->options().GetExtension(NKikimrConfig::NMarkers::AllowInDatabaseConfig)) {
177+
continue;
178+
}
179+
180+
if (!field->is_repeated()) {
181+
if (!reflection->HasField(config, field)) {
182+
continue;
183+
}
184+
} else {
185+
if (!reflection->FieldSize(config, field)) {
186+
continue;
187+
}
188+
}
189+
190+
auto fieldName = field->name();
191+
NProtobufJson::ToSnakeCaseDense(&fieldName);
192+
msg.push_back(TStringBuilder() << "'" << fieldName << "' "
193+
<< "is not allowed to be used in the database configuration");
194+
return EValidationResult::Error;
195+
}
196+
197+
return EValidationResult::Ok;
198+
}
199+
164200
EValidationResult ValidateConfig(const NKikimrConfig::TAppConfig& config, std::vector<TString>& msg) {
165201
if (config.HasAuthConfig()) {
166202
NKikimr::NConfig::EValidationResult result = NKikimr::NConfig::ValidateAuthConfig(config.GetAuthConfig(), msg);

ydb/core/config/validation/validators.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ EValidationResult ValidateColumnShardConfig(
4646
const NKikimrConfig::TColumnShardConfig& columnShardConfig,
4747
std::vector<TString>& msg);
4848

49+
EValidationResult ValidateDatabaseConfig(
50+
const NKikimrConfig::TAppConfig& config,
51+
std::vector<TString>& msg);
52+
4953
EValidationResult ValidateConfig(
5054
const NKikimrConfig::TAppConfig& config,
5155
std::vector<TString>& msg);

ydb/core/config/validation/validators_ut.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <ydb/core/protos/blobstorage.pb.h>
44
#include <ydb/core/protos/blobstorage_disk.pb.h>
5+
#include <ydb/core/protos/feature_flags.pb.h>
6+
#include <ydb/core/protos/table_service_config.pb.h>
57

68
#include <library/cpp/testing/unittest/registar.h>
79

@@ -406,3 +408,26 @@ Y_UNIT_TEST_SUITE(ConfigValidation) {
406408
UNIT_ASSERT_EQUAL(res, EValidationResult::Error);
407409
}
408410
}
411+
412+
Y_UNIT_TEST_SUITE(DatabaseConfigValidation) {
413+
Y_UNIT_TEST(AllowedFields) {
414+
NKikimrConfig::TAppConfig config;
415+
config.MutableFeatureFlags()->SetEnablePgSyntax(true);
416+
config.MutableTableServiceConfig()->SetEnableStreamWrite(true);
417+
418+
std::vector<TString> err;
419+
auto res = ValidateDatabaseConfig(config, err);
420+
UNIT_ASSERT_VALUES_EQUAL(err.size(), 0);
421+
UNIT_ASSERT_EQUAL(res, EValidationResult::Ok);
422+
}
423+
424+
Y_UNIT_TEST(NotAllowedFields) {
425+
auto [config, _] = PrepareStaticStorageTest();
426+
427+
std::vector<TString> err;
428+
auto res = ValidateDatabaseConfig(config, err);
429+
UNIT_ASSERT_VALUES_EQUAL(err.size(), 1);
430+
UNIT_ASSERT_VALUES_EQUAL(err[0], "'blob_storage_config' is not allowed to be used in the database configuration");
431+
UNIT_ASSERT_EQUAL(res, EValidationResult::Error);
432+
}
433+
}

ydb/core/config/validation/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SRCS(
1010
PEERDIR(
1111
ydb/core/protos
1212
ydb/core/formats/arrow/serializer
13+
library/cpp/protobuf/json
1314
)
1415

1516
END()

ydb/core/protos/config.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ message TAppConfig {
21732173
//optional TLocalConfig LocalConfig = 23; DEPRECATED
21742174
optional TDynamicNodeConfig DynamicNodeConfig = 24;
21752175
optional NKikimrCms.TCmsConfig CmsConfig = 25;
2176-
optional TFeatureFlags FeatureFlags = 26;
2176+
optional TFeatureFlags FeatureFlags = 26 [(NMarkers.AllowInDatabaseConfig) = true];
21772177
optional TSqsConfig SqsConfig = 27;
21782178
optional NKikimrPQ.TPQConfig PQConfig = 28;
21792179
optional NKikimrTenantPool.TTenantPoolConfig TenantPoolConfig = 29;
@@ -2184,7 +2184,7 @@ message TAppConfig {
21842184
optional NKikimrProto.TKeyConfig KeyConfig = 35;
21852185
optional NKikimrProto.TKeyConfig PDiskKeyConfig = 51;
21862186
optional NKikimrNodeBroker.TConfig NodeBrokerConfig = 36;
2187-
optional TTableServiceConfig TableServiceConfig = 37;
2187+
optional TTableServiceConfig TableServiceConfig = 37 [(NMarkers.AllowInDatabaseConfig) = true];
21882188
optional NKikimrSharedCache.TSharedCacheConfig SharedCacheConfig = 38; // dynamic configuration via cms
21892189
optional TImmediateControlsConfig ImmediateControlsConfig = 39;
21902190
optional TAllocatorConfig AllocatorConfig = 40;

0 commit comments

Comments
 (0)