Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion golang/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (c *client) GetServerVersion() string {
err := c.getMetrics(URL, &appMetrics)
if err != nil {
log.Println(err)
return "unknown"
}
c.serverVersion = appMetrics.App.Version
if c.serverVersion[0:3] != wantServerVersion {
Expand All @@ -66,7 +67,7 @@ func New(config ClientConfig) (Client, error) {

func (c *client) getMetrics(url string, payload interface{}) error {
spaceClient := http.Client{
Timeout: time.Second * 30,
Timeout: time.Second * 5,
}

req, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
22 changes: 22 additions & 0 deletions src/CoreServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,28 @@ void CoreServer::_setup_routes(const PrometheusConfig &prom_config)
res.set_content(j.dump(), "text/json");
}
});
_svr.Delete(fmt::format("/api/v1/policies/({})", AbstractModule::MODULE_ID_REGEX).c_str(), [&](const httplib::Request &req, httplib::Response &res) {
json j;
auto name = req.matches[1];
if (!_registry.policy_manager()->module_exists(name)) {
res.status = 404;
j["error"] = "policy does not exists";
res.set_content(j.dump(), "text/json");
return;
}
try {
auto [policy, lock] = _registry.policy_manager()->module_get_locked(name);
policy->stop();
lock.unlock();
// TODO chance of race here
_registry.policy_manager()->module_remove(name);
res.set_content(j.dump(), "text/json");
} catch (const std::exception &e) {
res.status = 500;
j["error"] = e.what();
res.set_content(j.dump(), "text/json");
}
});
_svr.Get(fmt::format("/api/v1/policies/({})/metrics/bucket/(\\d+)", AbstractModule::MODULE_ID_REGEX).c_str(), [&](const httplib::Request &req, httplib::Response &res) {
json j;
auto name = req.matches[1];
Expand Down
26 changes: 26 additions & 0 deletions src/tests/test_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,30 @@ TEST_CASE("Policies", "[policies]")
REQUIRE(!registry.policy_manager()->module_exists("default_view"));
REQUIRE(!registry.input_manager()->module_exists("anycast-default_view"));
}
SECTION("Good Config, test stop()")
{
CoreRegistry registry(nullptr);
YAML::Node config_file = YAML::Load(policies_config);

CHECK(config_file["visor"]["policies"]);
CHECK(config_file["visor"]["policies"].IsMap());

REQUIRE_NOTHROW(registry.tap_manager()->load(config_file["visor"]["taps"], true));
REQUIRE_NOTHROW(registry.policy_manager()->load(config_file["visor"]["policies"]));

REQUIRE(registry.policy_manager()->module_exists("default_view"));
auto [policy, lock] = registry.policy_manager()->module_get_locked("default_view");
CHECK(policy->name() == "default_view");
CHECK(policy->input_stream()->running());
CHECK(policy->modules()[0]->running());
CHECK(policy->modules()[1]->running());
CHECK(policy->modules()[2]->running());
policy->stop();
CHECK(!policy->input_stream()->running());
CHECK(!policy->modules()[0]->running());
CHECK(!policy->modules()[1]->running());
CHECK(!policy->modules()[2]->running());
lock.unlock();
REQUIRE_NOTHROW(registry.policy_manager()->module_remove("default_view"));
}
}