|
13 | 13 | #include <contrib/ydb/core/base/auth.h> |
14 | 14 | #include <contrib/ydb/core/cms/console/console.h> |
15 | 15 | #include <contrib/ydb/core/cms/console/configs_dispatcher.h> |
| 16 | +#include <contrib/ydb/library/services/services.pb.h> |
| 17 | + |
| 18 | +namespace { |
| 19 | + |
| 20 | +TString DescribeConfigIdentity(const Ydb::DynamicConfig::ConfigIdentity& id) |
| 21 | +{ |
| 22 | + TStringBuilder descr; |
| 23 | + |
| 24 | + switch (id.type_case()) { |
| 25 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::kCluster: |
| 26 | + descr << "cluster=" << id.cluster(); |
| 27 | + break; |
| 28 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::kDatabase: |
| 29 | + descr << "database=" << id.database(); |
| 30 | + break; |
| 31 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::TYPE_NOT_SET: |
| 32 | + descr << "<TYPE_NOT_SET>"; |
| 33 | + break; |
| 34 | + default: |
| 35 | + descr << "<unknown-type:" << static_cast<int>(id.type_case()) << ">"; |
| 36 | + break; |
| 37 | + } |
| 38 | + |
| 39 | + descr << ";version=" << id.version(); |
| 40 | + |
| 41 | + return descr; |
| 42 | +} |
| 43 | + |
| 44 | +bool ConvertGetConfigToFetchConfigResult( |
| 45 | + const Ydb::DynamicConfig::GetConfigResult &from, |
| 46 | + Ydb::Config::FetchConfigResult &to, |
| 47 | + TString& error) |
| 48 | +{ |
| 49 | + const auto identityCount = from.identity_size(); |
| 50 | + const auto configCount = from.config_size(); |
| 51 | + |
| 52 | + error.clear(); |
| 53 | + |
| 54 | + // Reject Ydb::DynamicConfig::GetConfigResult invariant violation |
| 55 | + if (identityCount < configCount) { |
| 56 | + TStringBuilder descr; |
| 57 | + descr << (configCount - identityCount) |
| 58 | + << " extra 'config' field with no corresponding 'identity' field"; |
| 59 | + error = descr; |
| 60 | + return false; |
| 61 | + } |
| 62 | + if (identityCount > configCount) { |
| 63 | + TStringBuilder descr; |
| 64 | + descr << "no 'config' fields for 'identity' fields ["; |
| 65 | + for (int i = configCount; i < identityCount; i++) { |
| 66 | + if (i > configCount) { |
| 67 | + descr << ", "; |
| 68 | + } |
| 69 | + descr << "'" << DescribeConfigIdentity(from.identity(i)) << "'"; |
| 70 | + } |
| 71 | + descr << "]"; |
| 72 | + error = descr; |
| 73 | + return false; |
| 74 | + } |
| 75 | + |
| 76 | + // Reject TYPE_NOT_SET upfront so the error path leaves 'to' untouched |
| 77 | + { |
| 78 | + TStringBuilder descr; |
| 79 | + int unsetCount = 0; |
| 80 | + |
| 81 | + descr << "'identity' fields with no type set at indices ["; |
| 82 | + for (int i = 0; i < identityCount; i++) { |
| 83 | + if (from.identity(i).type_case() |
| 84 | + == Ydb::DynamicConfig::ConfigIdentity::TypeCase::TYPE_NOT_SET) |
| 85 | + { |
| 86 | + if (unsetCount > 0) { |
| 87 | + descr << ", "; |
| 88 | + } |
| 89 | + descr << "#" << i << " - " << "'" << DescribeConfigIdentity(from.identity(i)) << "'"; |
| 90 | + ++unsetCount; |
| 91 | + } |
| 92 | + } |
| 93 | + descr << "]"; |
| 94 | + |
| 95 | + if (unsetCount > 0) { |
| 96 | + error = descr; |
| 97 | + return false; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + for (int i = 0; i < identityCount; i++) { |
| 102 | + const auto& srcIdentity = from.identity(i); |
| 103 | + switch (srcIdentity.type_case()) { |
| 104 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::kCluster: { |
| 105 | + auto dstEntry = to.add_config(); |
| 106 | + auto dstIdentity = dstEntry->mutable_identity(); |
| 107 | + dstIdentity->set_version(srcIdentity.version()); |
| 108 | + dstIdentity->set_cluster(srcIdentity.cluster()); |
| 109 | + dstIdentity->mutable_main(); |
| 110 | + dstEntry->set_config(from.config(i)); |
| 111 | + break; |
| 112 | + } |
| 113 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::kDatabase: { |
| 114 | + auto dstEntry = to.add_config(); |
| 115 | + auto dstIdentity = dstEntry->mutable_identity(); |
| 116 | + dstIdentity->set_version(srcIdentity.version()); |
| 117 | + dstIdentity->mutable_database()->set_database(srcIdentity.database()); |
| 118 | + dstEntry->set_config(from.config(i)); |
| 119 | + break; |
| 120 | + } |
| 121 | + case Ydb::DynamicConfig::ConfigIdentity::TypeCase::TYPE_NOT_SET: |
| 122 | + // TYPE_NOT_SET is rejected with error by pre-validation above |
| 123 | + break; |
| 124 | + default: |
| 125 | + // Any other value comes from a newer Console is skipped with a warning |
| 126 | + // so we don't fail on forward-compatible additions |
| 127 | + ALOG_NOTICE(NKikimrServices::GRPC_SERVER, |
| 128 | + "Convert Ydb::DynamicConfig::ConfigIdentity to Ydb::Config::FetchConfigResult: " |
| 129 | + << "skipped unknown config identity '" << DescribeConfigIdentity(srcIdentity) << "'" ); |
| 130 | + break; |
| 131 | + } |
| 132 | + } |
| 133 | + return true; |
| 134 | +} |
| 135 | + |
| 136 | +} // namespace |
16 | 137 |
|
17 | 138 | namespace NKikimr::NGRpcService { |
18 | 139 |
|
@@ -403,6 +524,8 @@ class TFetchStorageConfigRequest : public TBSConfigRequestGrpc<TFetchStorageConf |
403 | 524 | self->OnBootstrap(); |
404 | 525 |
|
405 | 526 | if (self->Request_->GetDatabaseName()) { |
| 527 | + // Database YAML config (Ydb::DynamicConfig::ConfigIdentity::TypeCase::kDatabase) |
| 528 | + // is requested directly from Console (like legacy API) |
406 | 529 | SendRequestToConsole(); |
407 | 530 | return; |
408 | 531 | } |
@@ -513,7 +636,19 @@ class TFetchStorageConfigRequest : public TBSConfigRequestGrpc<TFetchStorageConf |
513 | 636 | } |
514 | 637 |
|
515 | 638 | void Handle(NConsole::TEvConsole::TEvGetAllConfigsResponse::TPtr& ev) { |
516 | | - ReplyWithResult(Ydb::StatusIds::SUCCESS, ev->Get()->Record.GetResponse(), ActorContext()); |
| 639 | + Ydb::Config::FetchConfigResult result; |
| 640 | + TString error; |
| 641 | + |
| 642 | + bool succeed = ConvertGetConfigToFetchConfigResult(ev->Get()->Record.GetResponse(), result, error); |
| 643 | + if (succeed) { |
| 644 | + ReplyWithResult(Ydb::StatusIds::SUCCESS, result, ActorContext()); |
| 645 | + } |
| 646 | + else { |
| 647 | + // The malformed payload comes from the Console tablet (server-side), |
| 648 | + // not from the gRPC client — so this is an internal-error condition. |
| 649 | + Reply(Ydb::StatusIds::INTERNAL_ERROR, error, |
| 650 | + NKikimrIssues::TIssuesIds::DEFAULT_ERROR, ActorContext()); |
| 651 | + } |
517 | 652 | } |
518 | 653 | }; |
519 | 654 |
|
|
0 commit comments