Added configMutex around connector check in Prometheus output
This commit is contained in:
parent
421b77dacd
commit
91262767d3
1 changed files with 50 additions and 47 deletions
|
@ -1721,55 +1721,58 @@ void Controller::handlePrometheus(HTTP::Parser & H, Socket::Connection & conn, i
|
||||||
resp["conf_streams"].append(sIt.key());
|
resp["conf_streams"].append(sIt.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Loop over connectors
|
{
|
||||||
const JSON::Value &caps = capabilities["connectors"];
|
tthread::lock_guard<tthread::mutex> guard(Controller::configMutex);
|
||||||
jsonForEachConst(Storage["config"]["protocols"], prtcl){
|
//Loop over connectors
|
||||||
const std::string &cName = (*prtcl)["connector"].asStringRef();
|
const JSON::Value &caps = capabilities["connectors"];
|
||||||
if ((*prtcl)["online"].asInt() != 1){continue;}
|
jsonForEachConst(Storage["config"]["protocols"], prtcl){
|
||||||
if (!caps.isMember(cName)){continue;}
|
const std::string &cName = (*prtcl)["connector"].asStringRef();
|
||||||
const JSON::Value & capa = caps[cName];
|
if ((*prtcl)["online"].asInt() != 1){continue;}
|
||||||
if (!capa.isMember("optional") || !capa["optional"].isMember("port")){continue;}
|
if (!caps.isMember(cName)){continue;}
|
||||||
//We now know it's configured, online and has a listening port
|
const JSON::Value & capa = caps[cName];
|
||||||
HTTP::URL outURL("HOST");
|
if (!capa.isMember("optional") || !capa["optional"].isMember("port")){continue;}
|
||||||
//get the default port if none is set
|
//We now know it's configured, online and has a listening port
|
||||||
if (prtcl->isMember("port")){
|
HTTP::URL outURL("HOST");
|
||||||
outURL.port = (*prtcl)["port"].asString();
|
//get the default port if none is set
|
||||||
}
|
if (prtcl->isMember("port")){
|
||||||
if (!outURL.port.size()){
|
outURL.port = (*prtcl)["port"].asString();
|
||||||
outURL.port = capa["optional"]["port"]["default"].asString();
|
}
|
||||||
}
|
if (!outURL.port.size()){
|
||||||
//set the protocol
|
outURL.port = capa["optional"]["port"]["default"].asString();
|
||||||
if (capa.isMember("protocol")){
|
}
|
||||||
outURL.protocol = capa["protocol"].asString();
|
//set the protocol
|
||||||
}else{
|
if (capa.isMember("protocol")){
|
||||||
if (capa.isMember("methods") && capa["methods"][0u].isMember("handler")){
|
outURL.protocol = capa["protocol"].asString();
|
||||||
outURL.protocol = capa["methods"][0u]["handler"].asStringRef();
|
}else{
|
||||||
|
if (capa.isMember("methods") && capa["methods"][0u].isMember("handler")){
|
||||||
|
outURL.protocol = capa["methods"][0u]["handler"].asStringRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outURL.protocol.find(':') != std::string::npos){
|
||||||
|
outURL.protocol.erase(outURL.protocol.find(':'));
|
||||||
|
}
|
||||||
|
//set the public access, if needed
|
||||||
|
if (prtcl->isMember("pubaddr") && (*prtcl)["pubaddr"].asString().size()){
|
||||||
|
HTTP::URL altURL((*prtcl)["pubaddr"].asString());
|
||||||
|
outURL.protocol = altURL.protocol;
|
||||||
|
if (altURL.host.size()){outURL.host = altURL.host;}
|
||||||
|
outURL.port = altURL.port;
|
||||||
|
outURL.path = altURL.path;
|
||||||
|
}
|
||||||
|
//Add the URL, if present
|
||||||
|
if (capa.isMember("url_rel")){
|
||||||
|
resp["outputs"][cName] = outURL.link("./"+capa["url_rel"].asStringRef()).getUrl();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (outURL.protocol.find(':') != std::string::npos){
|
|
||||||
outURL.protocol.erase(outURL.protocol.find(':'));
|
|
||||||
}
|
|
||||||
//set the public access, if needed
|
|
||||||
if (prtcl->isMember("pubaddr") && (*prtcl)["pubaddr"].asString().size()){
|
|
||||||
HTTP::URL altURL((*prtcl)["pubaddr"].asString());
|
|
||||||
outURL.protocol = altURL.protocol;
|
|
||||||
if (altURL.host.size()){outURL.host = altURL.host;}
|
|
||||||
outURL.port = altURL.port;
|
|
||||||
outURL.path = altURL.path;
|
|
||||||
}
|
|
||||||
//Add the URL, if present
|
|
||||||
if (capa.isMember("url_rel")){
|
|
||||||
resp["outputs"][cName] = outURL.link("./"+capa["url_rel"].asStringRef()).getUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
//if this connector can be depended upon by other connectors, loop over the rest
|
//if this connector can be depended upon by other connectors, loop over the rest
|
||||||
if (capa.isMember("provides")){
|
if (capa.isMember("provides")){
|
||||||
const std::string &cProv = capa["provides"].asStringRef();
|
const std::string &cProv = capa["provides"].asStringRef();
|
||||||
jsonForEachConst(Storage["config"]["protocols"], chld){
|
jsonForEachConst(Storage["config"]["protocols"], chld){
|
||||||
const std::string &child = (*chld)["connector"].asStringRef();
|
const std::string &child = (*chld)["connector"].asStringRef();
|
||||||
if (!caps.isMember(child) || !caps[child].isMember("deps")){continue;}
|
if (!caps.isMember(child) || !caps[child].isMember("deps")){continue;}
|
||||||
if (caps[child].isMember("deps") && caps[child]["deps"].asStringRef() == cProv && caps[child].isMember("url_rel")){
|
if (caps[child].isMember("deps") && caps[child]["deps"].asStringRef() == cProv && caps[child].isMember("url_rel")){
|
||||||
resp["outputs"][child] = outURL.link("./"+caps[child]["url_rel"].asStringRef()).getUrl();
|
resp["outputs"][child] = outURL.link("./"+caps[child]["url_rel"].asStringRef()).getUrl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue