Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(userspace/falco): fix outputs_http timeout #3523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions falco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ http_output:
echo: false
compress_uploads: false
keep_alive: false
# Maximum consecutive timeouts of libcurl to ignore
max_consecutive_timeouts: 5

# [Stable] `program_output`
#
Expand Down
3 changes: 3 additions & 0 deletions userspace/falco/config_json_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ const char config_schema_string[] = LONG_STRING_CONST(
},
"keep_alive": {
"type": "boolean"
},
"max_consecutive_timeouts:" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"max_consecutive_timeouts:" {
"max_consecutive_timeouts": {

:P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fix the CI @benierc !

"type": "integer"
}
},
"minProperties": 1,
Expand Down
5 changes: 5 additions & 0 deletions userspace/falco/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ void falco_configuration::load_yaml(const std::string &config_name) {
keep_alive = m_config.get_scalar<bool>("http_output.keep_alive", false);
http_output.options["keep_alive"] = keep_alive ? std::string("true") : std::string("false");

uint8_t max_consecutive_timeouts;
max_consecutive_timeouts =
m_config.get_scalar<uint8_t>("http_output.max_consecutive_timeouts", 5);
http_output.options["max_consecutive_timeouts"] = std::to_string(max_consecutive_timeouts);

m_outputs.push_back(http_output);
}

Expand Down
13 changes: 12 additions & 1 deletion userspace/falco/outputs_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bool falco::outputs::output_http::init(const config &oc,

m_curl = nullptr;
m_http_headers = nullptr;
m_max_consecutive_timeouts =
static_cast<uint8_t>(std::stoi(m_oc.options["max_consecutive_timeouts"]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to be extra careful:

Suggested change
static_cast<uint8_t>(std::stoi(m_oc.options["max_consecutive_timeouts"]));
static_cast<uint8_t>(std::stoi(m_oc.options["max_consecutive_timeouts"]) & 0xFF);

CURLcode res = CURLE_FAILED_INIT;

m_curl = curl_easy_init();
Expand Down Expand Up @@ -103,7 +105,16 @@ bool falco::outputs::output_http::init(const config &oc,

void falco::outputs::output_http::output(const message *msg) {
CURLcode res = curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, msg->msg.c_str());
CHECK_RES(curl_easy_perform(m_curl));
uint32_t curl_easy_platform_calls = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since m_max_consecutive_timeouts is 8bit no need for uint32_t here.

Suggested change
uint32_t curl_easy_platform_calls = 0;
uint8_t curl_easy_platform_calls = 0;


if(res == CURLE_OK) {
do {
res = curl_easy_perform(m_curl);
curl_easy_platform_calls++;
} while(res == CURLE_OPERATION_TIMEDOUT &&
curl_easy_platform_calls <= m_max_consecutive_timeouts);
}

if(res != CURLE_OK) {
falco_logger::log(
falco_logger::level::ERR,
Expand Down
1 change: 1 addition & 0 deletions userspace/falco/outputs_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class output_http : public abstract_output {
private:
CURL *m_curl;
struct curl_slist *m_http_headers;
uint8_t m_max_consecutive_timeouts;
};

} // namespace outputs
Expand Down
Loading