Skip to content

Commit 4ec8fd4

Browse files
authored
Forbid new required fields in config (#1710)
* forbid new required fields in config
1 parent e67eb45 commit 4ec8fd4

File tree

7 files changed

+450
-0
lines changed

7 files changed

+450
-0
lines changed

ydb/core/config/ut/main.cpp

Lines changed: 338 additions & 0 deletions
Large diffs are not rendered by default.

ydb/core/config/ut/ya.make

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
UNITTEST()
2+
3+
SRCS(
4+
main.cpp
5+
)
6+
7+
PEERDIR(
8+
ydb/core/config/utils
9+
library/cpp/colorizer
10+
library/cpp/testing/unittest
11+
)
12+
13+
END()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "config_traverse.h"
2+
3+
#include <ydb/core/protos/config.pb.h>
4+
5+
#include <contrib/libs/protobuf/src/google/protobuf/descriptor.h>
6+
7+
#include <util/generic/deque.h>
8+
#include <util/generic/map.h>
9+
#include <util/generic/set.h>
10+
#include <util/generic/string.h>
11+
#include <util/generic/vector.h>
12+
#include <util/system/compiler.h>
13+
14+
namespace NKikimr::NConfig {
15+
16+
ssize_t FindLoop(TDeque<const Descriptor*>& typePath, const Descriptor* child) {
17+
for (ssize_t i = 0; i < (ssize_t)typePath.size(); ++i) {
18+
if (typePath[i] == child) {
19+
return i;
20+
}
21+
}
22+
return -1;
23+
}
24+
25+
void Traverse(const Descriptor* d, TDeque<const Descriptor*>& typePath, TDeque<const FieldDescriptor*>& fieldPath, const FieldDescriptor* field, TOnEntryFn onEntry) {
26+
ssize_t loop = FindLoop(typePath, d);
27+
28+
Y_ABORT_IF(!d && !field, "Either field or descriptor must be defined");
29+
30+
onEntry(d, typePath, fieldPath, field, loop);
31+
32+
if (!d || loop != -1) {
33+
return;
34+
}
35+
36+
typePath.push_back(d);
37+
38+
for (int i = 0; i < d->field_count(); ++i) {
39+
const FieldDescriptor* fieldDescriptor = d->field(i);
40+
fieldPath.push_back(fieldDescriptor);
41+
Traverse(fieldDescriptor->message_type(), typePath, fieldPath, fieldDescriptor, onEntry);
42+
fieldPath.pop_back();
43+
}
44+
45+
typePath.pop_back();
46+
}
47+
48+
void Traverse(TOnEntryFn onEntry) {
49+
auto& inst = NKikimrConfig::TAppConfig::default_instance();
50+
const Descriptor* descriptor = inst.GetDescriptor();
51+
52+
TDeque<const Descriptor*> typePath;
53+
TDeque<const FieldDescriptor*> fieldPath;
54+
fieldPath.push_back(nullptr);
55+
Traverse(descriptor, typePath, fieldPath, nullptr, onEntry);
56+
fieldPath.pop_back();
57+
}
58+
59+
} // namespace NKikimr::NConfig
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <util/generic/deque.h>
4+
5+
#include <functional>
6+
7+
namespace google::protobuf {
8+
class Descriptor;
9+
class FieldDescriptor;
10+
}
11+
12+
namespace NKikimr::NConfig {
13+
14+
using namespace google::protobuf;
15+
16+
using TOnEntryFn = std::function<void(const Descriptor*, const TDeque<const Descriptor*>&, const TDeque<const FieldDescriptor*>&, const FieldDescriptor*, ssize_t)>;
17+
18+
void Traverse(TOnEntryFn onEntry);
19+
20+
} // namespace NKikimr::NConfig

ydb/core/config/utils/ya.make

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LIBRARY()
2+
3+
SRCS(
4+
config_traverse.cpp
5+
)
6+
7+
PEERDIR(
8+
ydb/core/protos
9+
library/cpp/protobuf/json
10+
)
11+
12+
END()

ydb/core/config/ya.make

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RECURSE(
2+
utils
3+
)
4+
5+
RECURSE_FOR_TESTS(
6+
ut
7+
)

ydb/core/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RECURSE(
88
client
99
cms
1010
control
11+
config
1112
debug
1213
debug_tools
1314
discovery

0 commit comments

Comments
 (0)