Skip to content

Commit e09d730

Browse files
author
ilgarsh
committed
feat dynamic-configs: add circuit overrides
add circuit overrides commit_hash:811234950b6d50264f81f25d58413535066aee44
1 parent 211dcb8 commit e09d730

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

core/include/userver/dynamic_config/client/client.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ClientConfig {
2525
bool append_path_to_url{true};
2626
std::string stage_name;
2727
bool is_prestable{false};
28+
std::string circuit;
2829
};
2930

3031
/// @ingroup userver_clients

core/src/clients/config/client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ formats::json::Value Client::FetchConfigs(
9595
body.Key("is_prestable");
9696
WriteToStream(true, body);
9797
}
98+
99+
if (!config_.circuit.empty()) {
100+
body.Key("circuit");
101+
WriteToStream(config_.circuit, body);
102+
}
98103
}
99104

100105
LOG_TRACE() << "request body: " << body.GetStringView();

core/src/dynamic_config/client/component.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,45 @@ std::string ReadStageName(const std::string& filepath) {
3131
}
3232

3333
#ifdef ARCADIA_ROOT
34-
bool IsClownductorPrestable() {
35-
constexpr std::string_view filepath = "/etc/clownductor_group";
34+
std::optional<std::string> ReadFile(std::string_view filepath) {
3635
auto& tp = engine::current_task::GetBlockingTaskProcessor();
36+
const std::string filepath_str{filepath};
37+
if (!fs::FileExists(tp, filepath_str)) {
38+
return std::nullopt;
39+
}
40+
41+
return fs::ReadFileContents(tp, filepath_str);
42+
}
3743

38-
if (!fs::FileExists(tp, std::string{filepath})) {
44+
bool IsClownductorPrestable() {
45+
auto content = ReadFile("/etc/clownductor_group");
46+
if (!content) {
3947
return false;
4048
}
41-
auto content = fs::ReadFileContents(tp, std::string{filepath});
42-
utils::text::Trim(content);
43-
return utils::text::EndsWith(content, "_pre_stable") || utils::text::EndsWith(content, "_prestable");
49+
50+
utils::text::Trim(*content);
51+
return utils::text::EndsWith(*content, "_pre_stable") || utils::text::EndsWith(*content, "_prestable");
52+
}
53+
54+
std::string ReadCircuit() {
55+
constexpr std::string_view kCircuitPrefix = "UPLATFORM_CIRCUIT=";
56+
57+
const auto content = ReadFile("/etc/uplatform_environment");
58+
if (!content) {
59+
return {};
60+
}
61+
62+
for (const auto line : utils::text::SplitIntoStringViewVector(*content, "\n")) {
63+
const auto trimmed_line = utils::text::TrimView(line);
64+
if (utils::text::StartsWith(trimmed_line, kCircuitPrefix)) {
65+
return std::string{trimmed_line.substr(kCircuitPrefix.size())};
66+
}
67+
}
68+
return {};
4469
}
4570
#else
4671
bool IsClownductorPrestable() { return false; }
72+
std::string ReadCircuit() { return {}; }
4773
#endif
4874

4975
} // namespace
@@ -67,6 +93,7 @@ DynamicConfigClient::DynamicConfigClient(const ComponentConfig& config, const Co
6793
}
6894
}
6995
client_config.is_prestable = IsClownductorPrestable();
96+
client_config.circuit = ReadCircuit();
7097
client_config.config_url = config["config-url"].As<std::string>();
7198

7299
if (!client_config.stage_name.empty() && client_config.get_configs_overrides_for_service) {

0 commit comments

Comments
 (0)