hydra-queue-runner: get the listening port from the exposer itself

Otherwise, when the port is randomly chosen (e.g. by specifying no port,
or a port of 0), it will just show that the port is 0 and not the port
that is actually serving the metrics.
This commit is contained in:
Cole Helbling 2022-03-14 08:41:45 -07:00
parent 52a29d43e6
commit c0f826b92d

View file

@ -760,12 +760,13 @@ void State::run(BuildID buildOne)
throw Error("hydra-queue-runner is already running");
/* Set up simple exporter, to show that we're still alive. */
std::string metricsAddress{"127.0.0.1:" + std::to_string(metricsPort)};
prometheus::Exposer exposer{metricsAddress};
std::string metricsAddress{"127.0.0.1"};
prometheus::Exposer exposer{metricsAddress + ":" + std::to_string(metricsPort)};
auto exposerPort = exposer.GetListeningPorts().front();
exposer.RegisterCollectable(registry);
std::cout << "Starting the Prometheus exporter, listening on "
<< "http://" << metricsAddress << "/metrics"
<< "http://" << metricsAddress << ":" << exposerPort << "/metrics"
<< std::endl;
Store::Params localParams;