-
Notifications
You must be signed in to change notification settings - Fork 697
Forbid new required fields in config #1710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Enjection
merged 5 commits into
ydb-platform:main
from
Enjection:feature/KIKIMR-21023/forbid-new-required-in-config
Feb 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
500fbf0
forbid new required fields in config
Enjection f74f992
Update ydb/core/config/utils/config_traverse.cpp
Enjection d4a2726
Update ydb/core/config/ya.make
Enjection b8aa5f9
optimize includes
Enjection 555f609
fix work with colors
Enjection File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
UNITTEST() | ||
|
||
SRCS( | ||
main.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/core/config/utils | ||
library/cpp/testing/unittest | ||
) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "config_traverse.h" | ||
|
||
#include <util/system/compiler.h> | ||
#include <util/generic/deque.h> | ||
#include <util/generic/vector.h> | ||
#include <util/generic/string.h> | ||
#include <util/generic/map.h> | ||
#include <util/generic/set.h> | ||
|
||
#include <ydb/core/protos/config.pb.h> | ||
|
||
namespace NKikimr::NConfig { | ||
|
||
ssize_t FindLoop(TDeque<const Descriptor*>& typePath, const Descriptor* child) { | ||
for (ssize_t i = 0; i < (ssize_t)typePath.size(); ++i) { | ||
if (typePath[i] == child) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
void Traverse(const Descriptor* d, TDeque<const Descriptor*>& typePath, TDeque<const FieldDescriptor*>& fieldPath, const FieldDescriptor* field, TOnEntryFn onEntry) { | ||
ssize_t loop = FindLoop(typePath, d); | ||
|
||
Y_ABORT_IF(!d && !field, "Either field or descriptor must be defined"); | ||
|
||
onEntry(d, typePath, fieldPath, field, loop); | ||
|
||
if (!d || loop != -1) { | ||
return; | ||
} | ||
|
||
typePath.push_back(d); | ||
|
||
for (int i = 0; i < d->field_count(); ++i) { | ||
const FieldDescriptor* fieldDescriptor = d->field(i); | ||
fieldPath.push_back(fieldDescriptor); | ||
Traverse(fieldDescriptor->message_type(), typePath, fieldPath, fieldDescriptor, onEntry); | ||
fieldPath.pop_back(); | ||
} | ||
|
||
typePath.pop_back(); | ||
} | ||
|
||
void Traverse(TOnEntryFn onEntry) { | ||
auto& inst = NKikimrConfig::TAppConfig::default_instance(); | ||
const Descriptor* descriptor = inst.GetDescriptor(); | ||
|
||
TDeque<const Descriptor*> typePath; | ||
TDeque<const FieldDescriptor*> fieldPath; | ||
fieldPath.push_back(nullptr); | ||
Traverse(descriptor, typePath, fieldPath, nullptr, onEntry); | ||
fieldPath.pop_back(); | ||
} | ||
|
||
} // namespace NKikimr::NConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <contrib/libs/protobuf/src/google/protobuf/descriptor.h> | ||
Enjection marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <util/generic/deque.h> | ||
|
||
#include <functional> | ||
|
||
namespace NKikimr::NConfig { | ||
|
||
using namespace NProtoBuf; | ||
|
||
using TOnEntryFn = std::function<void(const Descriptor*, const TDeque<const Descriptor*>&, const TDeque<const FieldDescriptor*>&, const FieldDescriptor*, ssize_t)>; | ||
|
||
void Traverse(TOnEntryFn onEntry); | ||
|
||
} // namespace NKikimr::NConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LIBRARY() | ||
|
||
SRCS( | ||
config_traverse.cpp | ||
) | ||
|
||
PEERDIR( | ||
ydb/core/protos | ||
library/cpp/protobuf/json | ||
) | ||
|
||
END() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RECURSE( | ||
utils | ||
ut | ||
) | ||
Enjection marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ RECURSE( | |
client | ||
cms | ||
control | ||
config | ||
debug | ||
debug_tools | ||
discovery | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.