Skip to content

Commit

Permalink
Added environment to StatsHouse and engine.stat (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDet authored Jun 18, 2024
1 parent ec22ec8 commit f469845
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion server/php-master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,11 @@ std::string php_master_prepare_stats(bool add_worker_pids) {
// engine_tag may be ended with "["
oss << "kphp_version\t" << atoll(engine_tag) << "\n";
}
oss << "cluster_name\t" << vk::singleton<ServerConfig>::get().get_cluster_name() << "\n"
const auto &config = vk::singleton<ServerConfig>::get();
if (!config.get_environment().empty()) {
oss << "environment\t" << config.get_environment() << "\n";
}
oss << "cluster_name\t" << config.get_cluster_name() << "\n"
<< "master_name\t" << vk::singleton<MasterName>::get().get_master_name() << "\n"
<< "min_worker_uptime\t" << min_uptime << "\n"
<< "max_worker_uptime\t" << max_uptime << "\n"
Expand Down
3 changes: 3 additions & 0 deletions server/server-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ int ServerConfig::init_from_config(const char *config_path) noexcept {
if (auto err_msg = set_cluster_name(cluster_name.data(), false)) {
throw std::runtime_error(err_msg);
}
if (auto environment = node["environment"]) {
environment_ = environment.as<std::string>();
}
} catch (const std::exception &e) {
kprintf("--server-config, incorrect server config: '%s'\n%s\n", config_path, e.what());
return -1;
Expand Down
6 changes: 6 additions & 0 deletions server/server-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <array>
#include <climits>
#include <string>
#include <yaml-cpp/yaml.h>

#include "common/mixin/not_copyable.h"
Expand All @@ -21,6 +22,10 @@ class ServerConfig : vk::not_copyable {
return statsd_prefix_.data();
}

const std::string &get_environment() const {
return environment_;
}

const char *set_cluster_name(const char *cluster_name, bool deprecated) noexcept;

int init_from_config(const char *config_path) noexcept;
Expand All @@ -34,4 +39,5 @@ class ServerConfig : vk::not_copyable {

std::array<char, NAME_MAX> cluster_name_;
std::array<char, NAME_MAX> statsd_prefix_;
std::string environment_;
};
4 changes: 4 additions & 0 deletions server/statshouse/statshouse-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class StatsHouseClient {

statshouse::TransportUDPBase::MetricBuilder metric(std::string_view name, bool force_tag_host = false);

void set_environment(const std::string &env) {
transport.set_default_env(env);
}

void set_tag_cluster(std::string_view cluster) {
tag_cluster = cluster;
}
Expand Down
6 changes: 5 additions & 1 deletion server/statshouse/statshouse-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ StatsHouseManager::StatsHouseManager(const std::string &ip, int port)
: client(ip, port){};

void StatsHouseManager::set_common_tags() {
client.set_tag_cluster(vk::singleton<ServerConfig>::get().get_cluster_name());
const auto &config = vk::singleton<ServerConfig>::get();
if (!config.get_environment().empty()) {
client.set_environment(config.get_environment());
}
client.set_tag_cluster(config.get_cluster_name());
client.set_tag_host(kdb_gethostname());
}

Expand Down

0 comments on commit f469845

Please sign in to comment.