Repository navigation
implement configuration by file. - #595
Ahmed-Elsaka-JC wants to merge 2 commits into
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
|
Documentation preview for this pull request is available at: |
a358d13 to
417bc2b
Compare
417bc2b to
308a7d9
Compare
arkjedrz
left a comment
There was a problem hiding this comment.
Review to internal/ files is not thorough yet, since many raised points relate to design.
| #include <optional> | ||
|
|
||
| /* | ||
| * This header declares the abstraction over deployment-time "configuration by file" discovery and |
There was a problem hiding this comment.
Since this is generated - ask Your LLM of choice to rework docs and comments. Following rules seem to be a good first step.
- Be concise, use short sentences.
- One sentence per line.
- If a sentence is too long, try to rephrase it first.
- This one's interesting, but turned out to be the most effective. Write as if it was written for an impatient developer that is not using English as a native language.
This is required, because otherwise those docs needlessly meander.
| namespace score::mw::per::kvs | ||
| { | ||
|
|
||
| class IKvsConfigParser |
There was a problem hiding this comment.
Please use non-prefixed name for interface, and then suffix Impl for concrete implementation.
This is the already-required approach in baselibs, already followed by logging.
| #include <cstddef> | ||
| #include <optional> | ||
|
|
||
| /* |
There was a problem hiding this comment.
Follow new docs format. /// for docs, Doxygen-style @xyz keywords, // for comments.
| * input: the `InstanceId::id` of the KVS instance about to be opened. | ||
| * behavior: Discovers whether a configuration-by-file document applies at all, and if so | ||
| * parses and strictly validates it in full before looking for an entry matching | ||
| * `instance_id`. Performs no mutation; intended to be called once per |
There was a problem hiding this comment.
Performs no mutation -> then the function should be marked as const, and docs require no additional statement.
| * input: the `InstanceId::id` of the KVS instance about to be opened. | ||
| * behavior: Discovers whether a configuration-by-file document applies at all, and if so | ||
| * parses and strictly validates it in full before looking for an entry matching | ||
| * `instance_id`. Performs no mutation; intended to be called once per |
There was a problem hiding this comment.
intended to be called once per -> additional request to LLM, do not state what is the expected usage and even where it is used, this is just a fluff.
| (void)value; | ||
| const std::string_view key_view = key.GetAsStringView(); | ||
| bool found = false; | ||
| for (const auto& allowed_key : allowed) |
There was a problem hiding this comment.
std::any_of, return false quickly if not satisfied.
Do not use single point of return rule.
| score::Unexpected KvsConfigParser::fail(ErrorCode code, std::string_view user_message) const | ||
| { | ||
| const auto error = MakeError(code, user_message); | ||
| logger_->LogError() << "KVS config:" << error.Message() << error.UserMessage(); |
There was a problem hiding this comment.
logger_ can become an object placed in anonymous namespace, then this function can be in anonymous function as well. Or a KVS-wide internal object, because it's using the same code.
There was a problem hiding this comment.
This is already done upstream, please use global logger.
| return fail(ErrorCode::InvalidConfiguration, "unknown need_* value"); | ||
| } | ||
|
|
||
| /* |
There was a problem hiding this comment.
cpp is not a place for docs.
|
|
||
| /* | ||
| * Determine the directory containing the currently running binary. | ||
| * Used only as part of the fallback configuration file lookup; exposed for unit testing. |
There was a problem hiding this comment.
No fallback or candidates. It's a known path or an error.
EDIT: took a look at communication, here it's a default constructor or given path, but the overall approach is different - RuntimeConfiguration is created first, then provided to Initialize function. This is incompatible with persistency approach, but as mentioned in other comment - maybe other places in persistency component need a redesign too.
There was a problem hiding this comment.
Dropping most of the comment, I don't think it should be there but the reasoning is now different - will explain in place.
| * Determine the directory containing the currently running binary. | ||
| * Used only as part of the fallback configuration file lookup; exposed for unit testing. | ||
| */ | ||
| std::optional<std::string> running_binary_directory() const; |
There was a problem hiding this comment.
Do not pollute public API. I disagree this is needed, but if it is - move to anonymous namespace, and recreate in unit tests.
tizava
left a comment
There was a problem hiding this comment.
My proposal is to use the flatbuffes instead of parsing the json files on target.
Benefits:
- Smaller memory footprint
- No parsing overhead
- More performant (Binary file is smaller)
- Schema evolution / Verisoning
|
Writing down my point from the meeting. I believe that an init step is missing from the KVS, and it's not specific to this change. Each KVS instance consumer is required to obtain the instance using same set of parameters as for the first time. This approach is not convenient (keeping track of parameters), might be a source of issues what is the expected configuration, since it initializes lazily - might be an issue to ensure allocations are done in the init phase.
|
|
Regarding flatbuffers - please hold on until it's no longer experimental. JSON is the way to go for now. |
|
|
||
| /* Fixed filename of the configuration-by-file document, used standalone or appended to a | ||
| * directory named by the environment variable or to the binary-relative fallback directory. */ | ||
| inline constexpr std::string_view kKvsConfigFileName = "key_value_storage_configs.json"; |
There was a problem hiding this comment.
Maybe to keep parity with com -> per_config.json, kvs_config.json?
| { | ||
|
|
||
| /* Name of the environment variable naming the configuration directory or file. */ | ||
| inline constexpr std::string_view kStorageConfigPathEnvVar = "STORAGE_CONFIG_PATH"; |
There was a problem hiding this comment.
PER_CONFIG_PATH, KVS_CONFIG_PATH?
| /// @brief Specifies whether the KVS should be opened in read-only mode. | ||
| /// @param flag True to open read-only; false (default) for read-write. | ||
| /// @return Reference to this builder (for chaining). | ||
| KvsBuilder& read_only_flag(bool flag) noexcept; |
There was a problem hiding this comment.
Please do split read-only into a separate PR to be merged first.
You can also add a component requirement for that.
Instead of using bool please use AccessMode enum with ReadWrite and ReadOnly modes.
| * (`ErrorCode::FileNotFound`, `ErrorCode::KvsFileReadError`, `ErrorCode::JsonParserError`, | ||
| * or `ErrorCode::InvalidConfiguration`), or any error from `Kvs::open()`. | ||
| */ | ||
| score::Result<Kvs> KvsBuilder::build() noexcept |
There was a problem hiding this comment.
I stand by my point here.
- An application that requires its data (
need_kvs_flag(Required)) starts with an empty store if the file says"optional". - An application that opens a store with
read_only_flag(true)can write to it if the file says"read_write". - A partial entry, for example only
storage_path, combines file values and code values.
Neither the integrator (who sees only the file) nor the developer (who sees only the code) sees the effective configuration.
BTW communication handles that by allowing only an add, otherwise it's an abort.
| * (`ErrorCode::FileNotFound`, `ErrorCode::KvsFileReadError`, `ErrorCode::JsonParserError`, | ||
| * or `ErrorCode::InvalidConfiguration`), or any error from `Kvs::open()`. | ||
| */ | ||
| score::Result<Kvs> KvsBuilder::build() noexcept |
There was a problem hiding this comment.
Keep const, store resolved variables in function scope.
|
|
||
| /* | ||
| * Determine the directory containing the currently running binary. | ||
| * Used only as part of the fallback configuration file lookup; exposed for unit testing. |
There was a problem hiding this comment.
Dropping most of the comment, I don't think it should be there but the reasoning is now different - will explain in place.
| { | ||
|
|
||
| /* Entry keys accepted inside a `key_value_storage_list` element. */ | ||
| constexpr std::array<std::string_view, 7> kAllowedEntryKeys{"instance_id", |
There was a problem hiding this comment.
Can a schema for JSON be used instead, like in communication?
| score::Unexpected KvsConfigParser::fail(ErrorCode code, std::string_view user_message) const | ||
| { | ||
| const auto error = MakeError(code, user_message); | ||
| logger_->LogError() << "KVS config:" << error.Message() << error.UserMessage(); |
There was a problem hiding this comment.
This is already done upstream, please use global logger.
| return std::optional<std::string>{std::nullopt}; | ||
| } | ||
|
|
||
| const score::filesystem::Path candidate = score::filesystem::Path{bin_dir.value()} / ".." / "etc" / |
There was a problem hiding this comment.
Please align to communication, use <cwd>/etc/<config file>.
adding new support to config by file
#411