From 928b3b8268fc2f1d2534f1cf7e524d05803105fd Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 29 Mar 2022 10:42:07 -0700 Subject: [PATCH] hydra-queue-runner: fix priority of flag over config file --- src/hydra-queue-runner/hydra-queue-runner.cc | 14 +++++++++----- src/hydra-queue-runner/state.hh | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index c7d3b9b2..3834f625 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -39,7 +39,7 @@ std::string getEnvOrDie(const std::string & key) } -State::State(uint16_t metricsPort) +State::State(std::optional metricsPortOpt) : config(std::make_unique()) , maxUnsupportedTime(config->getIntOption("max_unsupported_time", 0)) , dbPool(config->getIntOption("max_db_connections", 128)) @@ -47,13 +47,17 @@ State::State(uint16_t metricsPort) , maxLogSize(config->getIntOption("max_log_size", 64ULL << 20)) , 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")))) - , metricsPort(config->getIntOption("queue_runner_metrics_port", metricsPort)) + , metricsPort(config->getIntOption("queue_runner_metrics_port", 9099)) , registry(std::make_shared()) { hydraData = getEnvOrDie("HYDRA_DATA"); logDir = canonPath(hydraData + "/build-logs"); + if (metricsPortOpt.has_value()) { + metricsPort = metricsPortOpt.value(); + } + /* handle deprecated store specification */ if (config->getStrOption("store_mode") != "") throw Error("store_mode in hydra.conf is deprecated, please use store_uri"); @@ -880,7 +884,7 @@ int main(int argc, char * * argv) bool unlock = false; bool status = false; BuildID buildOne = 0; - uint16_t metricsPort = 0; + std::optional metricsPortOpt = std::nullopt; parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--unlock") @@ -897,7 +901,7 @@ int main(int argc, char * * argv) if (*p > std::numeric_limits::max()) { throw Error("'--port' has a maximum of 65535"); } else { - metricsPort = *p; + metricsPortOpt = *p; } } else { throw Error("'--port' requires a numeric port (0 for a random, usable port; max 65535)"); @@ -910,7 +914,7 @@ int main(int argc, char * * argv) settings.verboseBuild = true; settings.lockCPU = false; - State state{metricsPort}; + State state{metricsPortOpt}; if (status) state.showStatus(); else if (unlock) diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 5299edea..63112c16 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -439,7 +439,7 @@ private: std::shared_ptr registry; public: - State(uint16_t metricsPort); + State(std::optional metricsPortOpt); private: