Skip to content

Commit

Permalink
Merge pull request #568 from noironetworks/inspect-timeout
Browse files Browse the repository at this point in the history
Make inspect timeout configurable
  • Loading branch information
mchalla committed May 31, 2024
2 parents 0630c4b + e0197fb commit 5954a93
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
9 changes: 8 additions & 1 deletion agent-ovs/cmd/gbp_inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void sighandler(int sig) {
LOG(INFO) << "Got " << strsignal(sig) << " signal";
}
#define DEF_SOCKET LOCALSTATEDIR"/run/opflex-agent-inspect.sock"
#define DEF_INSPECT_QUERY_TIMEOUT 5000

int main(int argc, char** argv) {
signal(SIGPIPE, SIG_IGN);
Expand All @@ -70,6 +71,9 @@ int main(int argc, char** argv) {
("syslog", "Log to syslog instead of file or standard out")
("socket", po::value<string>()->default_value(DEF_SOCKET),
"Connect to the specified UNIX domain socket (default " DEF_SOCKET ")")
("timeout,i",
po::value<long>()->default_value(DEF_INSPECT_QUERY_TIMEOUT),
"Timeout value for policy query in ms (default 5000 ms)")
("query,q", po::value<std::vector<string> >(),
"Query for a specific object with subjectname,uri or all objects "
"of a specific type with subjectname")
Expand Down Expand Up @@ -107,6 +111,7 @@ int main(int argc, char** argv) {
bool recursive = false;
bool followRefs = false;
int truncate = 0;
long timeout = DEF_INSPECT_QUERY_TIMEOUT;
bool unresolved = false;
bool excludeObservables = false;
po::variables_map vm;
Expand Down Expand Up @@ -141,6 +146,7 @@ int main(int argc, char** argv) {
if (vm.count("syslog")) {
log_to_syslog = true;
}
timeout = vm["timeout"].as<long>();
socket = vm["socket"].as<string>();
out_file = vm["output"].as<string>();
load_file = vm["load"].as<string>();
Expand Down Expand Up @@ -176,7 +182,8 @@ int main(int argc, char** argv) {
try {
unique_ptr<InspectorClient>
client(InspectorClient::newInstance(socket,
modelgbp::getMetadata()));
modelgbp::getMetadata(),
timeout));
client->setRecursive(recursive);
client->setFollowRefs(followRefs);
client->setExcludeObservables(excludeObservables);
Expand Down
6 changes: 4 additions & 2 deletions libopflex/engine/InspectorClientConn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ namespace internal {
using yajr::Peer;

InspectorClientConn::InspectorClientConn(HandlerFactory& handlerFactory,
const std::string& name_)
const std::string& name_,
long timeout)
: OpflexConnection(handlerFactory), name(name_), peer(NULL) {
client_loop = {};
query_timeout = timeout;
timer = {};
}

Expand All @@ -41,7 +43,7 @@ void InspectorClientConn::connect() {

timer.data = this;
uv_timer_init(&client_loop, &timer);
uv_timer_start(&timer, on_timer, 5000, 5000);
uv_timer_start(&timer, on_timer, query_timeout, query_timeout);

peer = yajr::Peer::create(name,
on_state_change,
Expand Down
10 changes: 6 additions & 4 deletions libopflex/engine/InspectorClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ namespace ofcore {

InspectorClient*
InspectorClient::newInstance(const std::string& name,
const modb::ModelMetadata& model) {
return new engine::InspectorClientImpl(name, model);
const modb::ModelMetadata& model,
long timeout) {
return new engine::InspectorClientImpl(name, model, timeout);
}

}
Expand All @@ -50,8 +51,9 @@ using internal::OpflexConnection;
using internal::OpflexMessage;

InspectorClientImpl::InspectorClientImpl(const std::string& name_,
const modb::ModelMetadata& model)
: conn(*this, name_), db(threadManager),
const modb::ModelMetadata& model,
long timeout)
: conn(*this, name_, timeout), db(threadManager),
serializer(&db, this), pendingRequests(0),
followRefs(false), recursive(false), unresolved(false),
excludeObservables(false) {
Expand Down
4 changes: 3 additions & 1 deletion libopflex/engine/include/opflex/engine/InspectorClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class InspectorClientImpl : public ofcore::InspectorClient,
*
* @param name the unix socket name
* @param model the model metadata object
* @param timeout the time to wait for query completion
*/
InspectorClientImpl(const std::string& name,
const modb::ModelMetadata& model);
const modb::ModelMetadata& model,
long timeout);

/**
* Destroy the inspector client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class InspectorClientConn : public OpflexConnection {
* @param handlerFactory a factory that can allocate a handler for
* the connection
* @param name A path name for the unix socket
* @param timeout Time to wait for query completion
*/
InspectorClientConn(HandlerFactory& handlerFactory,
const std::string& name);
const std::string& name,
long timeout);
virtual ~InspectorClientConn();

// ****************
Expand All @@ -55,6 +57,7 @@ class InspectorClientConn : public OpflexConnection {

private:
const std::string& name;
long query_timeout;

yajr::Peer* peer;

Expand Down
4 changes: 3 additions & 1 deletion libopflex/include/opflex/ofcore/InspectorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class InspectorClient : private boost::noncopyable {
*
* @param name A path name for the unix socket
* @param model the model metadata object
* @param timeout time to wait for query completion
*/
static InspectorClient* newInstance(const std::string& name,
const modb::ModelMetadata& model);
const modb::ModelMetadata& model,
long timeout);

/**
* Follow references for retrieved objects
Expand Down
2 changes: 1 addition & 1 deletion libopflex/ofcore/test/Inspector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const string SOCK_NAME("/tmp/inspector_test.sock");
class InspectorFixture : public BaseFixture {
public:
InspectorFixture()
: BaseFixture(), inspector(&db), client(SOCK_NAME, md) {
: BaseFixture(), inspector(&db), client(SOCK_NAME, md, 5000) {
inspector.setSocketName(SOCK_NAME);
inspector.start();
}
Expand Down

0 comments on commit 5954a93

Please sign in to comment.