hydra-queue-runner: make entire address configurable
This commit is contained in:
parent
33bc60b83c
commit
edf3c348f2
|
@ -39,7 +39,7 @@ std::string getEnvOrDie(const std::string & key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
State::State(std::optional<uint16_t> metricsPortOpt)
|
State::State(std::optional<std::string> metricsAddrOpt)
|
||||||
: config(std::make_unique<HydraConfig>())
|
: config(std::make_unique<HydraConfig>())
|
||||||
, maxUnsupportedTime(config->getIntOption("max_unsupported_time", 0))
|
, maxUnsupportedTime(config->getIntOption("max_unsupported_time", 0))
|
||||||
, dbPool(config->getIntOption("max_db_connections", 128))
|
, dbPool(config->getIntOption("max_db_connections", 128))
|
||||||
|
@ -47,15 +47,15 @@ State::State(std::optional<uint16_t> metricsPortOpt)
|
||||||
, maxLogSize(config->getIntOption("max_log_size", 64ULL << 20))
|
, maxLogSize(config->getIntOption("max_log_size", 64ULL << 20))
|
||||||
, uploadLogsToBinaryCache(config->getBoolOption("upload_logs_to_binary_cache", false))
|
, uploadLogsToBinaryCache(config->getBoolOption("upload_logs_to_binary_cache", false))
|
||||||
, rootsDir(config->getStrOption("gc_roots_dir", fmt("%s/gcroots/per-user/%s/hydra-roots", settings.nixStateDir, getEnvOrDie("LOGNAME"))))
|
, rootsDir(config->getStrOption("gc_roots_dir", fmt("%s/gcroots/per-user/%s/hydra-roots", settings.nixStateDir, getEnvOrDie("LOGNAME"))))
|
||||||
, metricsPort(config->getIntOption("queue_runner_metrics_port", 9198))
|
, metricsAddr(config->getStrOption("queue_runner_metrics_address", std::string{"127.0.0.1:9198"}))
|
||||||
, registry(std::make_shared<prometheus::Registry>())
|
, registry(std::make_shared<prometheus::Registry>())
|
||||||
{
|
{
|
||||||
hydraData = getEnvOrDie("HYDRA_DATA");
|
hydraData = getEnvOrDie("HYDRA_DATA");
|
||||||
|
|
||||||
logDir = canonPath(hydraData + "/build-logs");
|
logDir = canonPath(hydraData + "/build-logs");
|
||||||
|
|
||||||
if (metricsPortOpt.has_value()) {
|
if (metricsAddrOpt.has_value()) {
|
||||||
metricsPort = metricsPortOpt.value();
|
metricsAddr = metricsAddrOpt.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle deprecated store specification */
|
/* handle deprecated store specification */
|
||||||
|
@ -762,16 +762,15 @@ void State::run(BuildID buildOne)
|
||||||
if (!lock)
|
if (!lock)
|
||||||
throw Error("hydra-queue-runner is already running");
|
throw Error("hydra-queue-runner is already running");
|
||||||
|
|
||||||
std::cout << "Starting the Prometheus exporter on port " << metricsPort << std::endl;
|
std::cout << "Starting the Prometheus exporter on " << metricsAddr << std::endl;
|
||||||
|
|
||||||
/* Set up simple exporter, to show that we're still alive. */
|
/* Set up simple exporter, to show that we're still alive. */
|
||||||
std::string metricsAddress{"127.0.0.1"}; // FIXME: configurable
|
prometheus::Exposer promExposer{metricsAddr};
|
||||||
prometheus::Exposer promExposer{metricsAddress + ":" + std::to_string(metricsPort)};
|
|
||||||
auto exposerPort = promExposer.GetListeningPorts().front();
|
auto exposerPort = promExposer.GetListeningPorts().front();
|
||||||
promExposer.RegisterCollectable(registry);
|
promExposer.RegisterCollectable(registry);
|
||||||
|
|
||||||
std::cout << "Started the Prometheus exporter, listening on "
|
std::cout << "Started the Prometheus exporter, listening on "
|
||||||
<< "http://" << metricsAddress << ":" << exposerPort << "/metrics"
|
<< metricsAddr << "/metrics (port " << exposerPort << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
Store::Params localParams;
|
Store::Params localParams;
|
||||||
|
@ -884,7 +883,7 @@ int main(int argc, char * * argv)
|
||||||
bool unlock = false;
|
bool unlock = false;
|
||||||
bool status = false;
|
bool status = false;
|
||||||
BuildID buildOne = 0;
|
BuildID buildOne = 0;
|
||||||
std::optional<uint16_t> metricsPortOpt = std::nullopt;
|
std::optional<std::string> metricsAddrOpt = std::nullopt;
|
||||||
|
|
||||||
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
if (*arg == "--unlock")
|
if (*arg == "--unlock")
|
||||||
|
@ -896,16 +895,8 @@ int main(int argc, char * * argv)
|
||||||
buildOne = *b;
|
buildOne = *b;
|
||||||
else
|
else
|
||||||
throw Error("‘--build-one’ requires a build ID");
|
throw Error("‘--build-one’ requires a build ID");
|
||||||
} else if (*arg == "--port") {
|
} else if (*arg == "--prometheus-address") {
|
||||||
if (auto p = string2Int<int>(getArg(*arg, arg, end))) {
|
metricsAddrOpt = getArg(*arg, arg, end);
|
||||||
if (*p > std::numeric_limits<uint16_t>::max()) {
|
|
||||||
throw Error("'--port' has a maximum of 65535");
|
|
||||||
} else {
|
|
||||||
metricsPortOpt = *p;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw Error("'--port' requires a numeric port (0 for a random, usable port; max 65535)");
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -914,7 +905,7 @@ int main(int argc, char * * argv)
|
||||||
settings.verboseBuild = true;
|
settings.verboseBuild = true;
|
||||||
settings.lockCPU = false;
|
settings.lockCPU = false;
|
||||||
|
|
||||||
State state{metricsPortOpt};
|
State state{metricsAddrOpt};
|
||||||
if (status)
|
if (status)
|
||||||
state.showStatus();
|
state.showStatus();
|
||||||
else if (unlock)
|
else if (unlock)
|
||||||
|
|
|
@ -434,12 +434,12 @@ private:
|
||||||
via gc_roots_dir. */
|
via gc_roots_dir. */
|
||||||
nix::Path rootsDir;
|
nix::Path rootsDir;
|
||||||
|
|
||||||
uint16_t metricsPort;
|
std::string metricsAddr;;
|
||||||
|
|
||||||
std::shared_ptr<prometheus::Registry> registry;
|
std::shared_ptr<prometheus::Registry> registry;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
State(std::optional<uint16_t> metricsPortOpt);
|
State(std::optional<std::string> metricsAddrOpt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ write_file($ctx{'tmpdir'} . "/bar.conf", q|
|
||||||
|);
|
|);
|
||||||
|
|
||||||
is(getHydraConfig(), {
|
is(getHydraConfig(), {
|
||||||
queue_runner_metrics_port => 0,
|
queue_runner_metrics_address => "127.0.0.1:0",
|
||||||
foo => { bar => "baz" }
|
foo => { bar => "baz" }
|
||||||
}, "Nested includes work.");
|
}, "Nested includes work.");
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ sub new {
|
||||||
$ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";
|
$ENV{'HYDRA_CONFIG'} = "$dir/hydra.conf";
|
||||||
|
|
||||||
my $hydra_config = $opts{'hydra_config'} || "";
|
my $hydra_config = $opts{'hydra_config'} || "";
|
||||||
$hydra_config = "queue_runner_metrics_port = 0\n" . $hydra_config;
|
$hydra_config = "queue_runner_metrics_address = 127.0.0.1:0\n" . $hydra_config;
|
||||||
if ($opts{'use_external_destination_store'} // 1) {
|
if ($opts{'use_external_destination_store'} // 1) {
|
||||||
$hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;
|
$hydra_config = "store_uri = file:$dir/nix/dest-store\n" . $hydra_config;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue