Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions runtime-light/state/component-state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ void ComponentState::parse_runtime_config_arg(std::string_view value_view) noexc
runtime_config = *std::move(opt_config);
}

void ComponentState::parse_cluster_name(std::string_view value_view) noexcept {
cluster_name = string{value_view.data(), static_cast<string::size_type>(value_view.size())};
}

void ComponentState::parse_args() noexcept {
for (auto i = 0; i < argc; ++i) {
const auto [arg_key, arg_value]{k2::arg_fetch(i)};
Expand All @@ -88,6 +92,8 @@ void ComponentState::parse_args() noexcept {
parse_kml_arg(value_view);
} else if (key_view == RUNTIME_CONFIG_ARG) [[likely]] {
parse_runtime_config_arg(value_view);
} else if (key_view == CLUSTER_NAME_ARG) [[likely]] {
parse_cluster_name(value_view);
} else {
kphp::log::warning("unexpected argument format: {}", key_view);
}
Expand Down
7 changes: 7 additions & 0 deletions runtime-light/state/component-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct ComponentState final : private vk::not_copyable {
array<string> ini_opts{array_size{argc, false}};
array<mixed> env{array_size{envc, false}};
mixed runtime_config;
string cluster_name{DEFAULT_CLUSTER_NAME.data(), DEFAULT_CLUSTER_NAME.size()};

ComponentState() noexcept {
parse_env();
Expand All @@ -38,6 +39,8 @@ struct ComponentState final : private vk::not_copyable {
kphp::core::is_reference_counter_recursive(env, ExtraRefCnt::for_global_const)));
kphp::log::assertion((kphp::core::set_reference_counter_recursive(runtime_config, ExtraRefCnt::for_global_const),
kphp::core::is_reference_counter_recursive(runtime_config, ExtraRefCnt::for_global_const)));
kphp::log::assertion((kphp::core::set_reference_counter_recursive(cluster_name, ExtraRefCnt::for_global_const),
kphp::core::is_reference_counter_recursive(cluster_name, ExtraRefCnt::for_global_const)));
}

static const ComponentState& get() noexcept {
Expand All @@ -52,6 +55,8 @@ struct ComponentState final : private vk::not_copyable {
static constexpr std::string_view INI_ARG_PREFIX = "ini ";
static constexpr std::string_view KML_DIR_ARG = "kml-dir";
static constexpr std::string_view RUNTIME_CONFIG_ARG = "runtime-config";
static constexpr std::string_view CLUSTER_NAME_ARG = "cluster-name";
static constexpr std::string_view DEFAULT_CLUSTER_NAME = "default";
static constexpr auto INIT_COMPONENT_ALLOCATOR_SIZE = static_cast<size_t>(1024U * 1024U); // 1MB

void parse_env() noexcept;
Expand All @@ -63,4 +68,6 @@ struct ComponentState final : private vk::not_copyable {
void parse_kml_arg(std::string_view) noexcept;

void parse_runtime_config_arg(std::string_view) noexcept;

void parse_cluster_name(std::string_view value_view) noexcept;
};
3 changes: 2 additions & 1 deletion runtime-light/stdlib/system/system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "runtime-light/coroutine/io-scheduler.h"
#include "runtime-light/coroutine/task.h"
#include "runtime-light/k2-platform/k2-api.h"
#include "runtime-light/state/component-state.h"
#include "runtime-light/state/image-state.h"
#include "runtime-light/stdlib/diagnostics/contextual-logger.h"
#include "runtime-light/stdlib/diagnostics/logs.h"
Expand Down Expand Up @@ -251,7 +252,7 @@ inline string f$get_engine_version() noexcept {
}

inline string f$get_kphp_cluster_name() noexcept {
return string{"adm512"};
return ComponentState::get().cluster_name;
}

inline void f$kphp_turn_on_host_tag_in_inner_statshouse_metrics_toggle() noexcept {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ components:
args:
ini hello: "world"
runtime-config: ${RUNTIME_CONFIG_PATH}
cluster-name: "custom_cluster_name"
links: {}
2 changes: 2 additions & 0 deletions tests/python/tests/http_server/php/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ public function work(string $output) {
return;
}
});
} else if ($_SERVER["PHP_SELF"] === "/test_get_cluster_name") {
echo get_kphp_cluster_name();
} else {
if ($_GET["hints"] === "yes") {
send_http_103_early_hints(["Content-Type: text/plain or application/json", "Link: </script.js>; rel=preload; as=script"]);
Expand Down
14 changes: 14 additions & 0 deletions tests/python/tests/http_server/test_get_cluster_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.lib.testcase import WebServerAutoTestCase

class TestClusterName(WebServerAutoTestCase):
@classmethod
def extra_class_setup(cls):
if not cls.should_use_k2():
cls.web_server.update_options({
"--server-config": "data/server-config.yml"
})

def test_get_cluster_name(self):
resp = self.web_server.http_request(uri="/test_get_cluster_name")
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content.decode("utf-8"), "custom_cluster_name")
Loading