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

Conversation

benierc
Copy link

@benierc benierc commented Apr 3, 2025

libcurl timeout prevent to send alert through http keep trying to send the alert

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

/kind release

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area engine

/area tests

/area proposals

/area CI

What this PR does / why we need it:

this PR ignore http_output libcurl timeout when network is not available,
it allows to send the alert when network is back and to not lost it

Which issue(s) this PR fixes:

Fixes #3522

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link
Contributor

poiana commented Apr 3, 2025

Welcome @benierc! It looks like this is your first PR to falcosecurity/falco 🎉

@poiana poiana added the size/XS label Apr 3, 2025
@poiana poiana requested a review from FedeDP April 3, 2025 09:50
@poiana
Copy link
Contributor

poiana commented Apr 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: benierc
Once this PR has been reviewed and has the lgtm label, please assign mstemm for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana requested a review from Kaizhe April 3, 2025 09:50
Comment on lines 108 to 110
do {
res = curl_easy_perform(m_curl);
} while(res == CURLE_OPERATION_TIMEDOUT);
Copy link
Contributor

Choose a reason for hiding this comment

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

The change is fine but we'd better avoid a (possibly) infinite loop here. What about making the number of loops configurable through the Falco config file?
Eg: http_output.max_consecutive_timeouts (https://github.com/falcosecurity/falco/blob/master/falco.yaml#L726); a value like 5/10 by default is enough i think.

Copy link
Author

Choose a reason for hiding this comment

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

yes good point i will try to add it

@FedeDP
Copy link
Contributor

FedeDP commented Apr 3, 2025

Thanks for the PR! I left a comment to avoid the unbound loop ;)
/milestone 0.41.0

@FedeDP
Copy link
Contributor

FedeDP commented Apr 7, 2025

Hi @benierc ! Great job! You need to update config json schema too with the new config key: https://github.com/falcosecurity/falco/blob/master/userspace/falco/config_json_schema.h

@benierc benierc force-pushed the master branch 3 times, most recently from 0dc7fbf to ae3dd2f Compare April 7, 2025 08:00
@@ -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");

uint32_t max_consecutive_timeouts;
max_consecutive_timeouts =
m_config.get_scalar<uint32_t>("http_output.max_consecutive_timeouts", 5);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't m_max_consecutive_timeouts be enclosed in a range to avoid having an "almost" infinite loop if someone inputs a high value ?

Maybe also use a type smaller than unit32 to store it.

Copy link
Author

Choose a reason for hiding this comment

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

ok i see, so an uint16_t or uint8_t should be better @sgaist ?

Copy link
Contributor

Choose a reason for hiding this comment

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

unit8's max being 255, I think it should already cover most use cases.

If there's a need in the future to have more than that number of retries, it's always possible to update at this time.

Copy link
Contributor

Choose a reason for hiding this comment

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

uint8_t makes sense IMHO!

libcurl timeout prevent to send alert through http
keep trying to send the alert

Signed-off-by: Clément Bénier <[email protected]>
@@ -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 !

Copy link
Contributor

@sgaist sgaist left a comment

Choose a reason for hiding this comment

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

Sorry, I just saw that my review wasn't submitted !

We're on the right track :-)

@@ -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;

@@ -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);

@github-project-automation github-project-automation bot moved this from Todo to In progress in Falco Roadmap Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

alert lost with http_output because of libcurl timeout
4 participants