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: set http output contenttype to text/plain when json output is disabled #1829

Merged
merged 1 commit into from
Jan 10, 2022

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Dec 22, 2021

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area engine

What this PR does / why we need it:
The PR sets the http output Content-type header to a more meaningful value (text/plain) when json_output is disabled.

Which issue(s) this PR fixes:

Fixes #1824

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix: set http output contenttype to text/plain when json output is disabled

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

Hey @FedeDP

Thank you for this PR! We really need to fix that.
However, we shouldn't pass the formatter to the output channels. Moreover, if I understood correctly, your implementation won't work with internal messages (because they don't get a formatter). See my comment below.

I propose instead to propagate m_json_ouput to the output channels during init.

@@ -51,6 +51,7 @@ struct message
std::string source;
map<std::string, std::string> fields;
std::set<std::string> tags;
gen_event_formatter::output_format format;
Copy link
Member

Choose a reason for hiding this comment

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

Could we avoid passing the formatter in the message?

This approach cannot work with internal messages, that do not have a formatter 👇

void falco_outputs::handle_msg(uint64_t ts,
falco_common::priority_type priority,
std::string &msg,
std::string &rule,
std::map<std::string, std::string> &output_fields)
{
falco_outputs::ctrl_msg cmsg = {};
cmsg.ts = ts;
cmsg.priority = priority;
cmsg.source = "internal";
cmsg.rule = rule;
cmsg.fields = output_fields;
if(m_json_output)
{

Moreover, the JSON formatting option is a global setting (not a per-message setting) and the message already contains the formatted text. So I believe the formatter does not really belong to the message.

I would rather pass the m_json_output's value to each output via the init function 👇

oo->init(oc, m_buffered, m_hostname);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much simpler, you're right! Thanks ;)

… text/plain when json output is disabled

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>

Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link

poiana commented Jan 10, 2022

LGTM label has been added.

Git tree hash: efa6e71a68f1ba9ee93f1fae8d2e682838f0737a

@leogr
Copy link
Member

leogr commented Jan 10, 2022

/milestone 0.31.0

@poiana poiana added this to the 0.31.0 milestone Jan 10, 2022
Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

Thanks @FedeDP! ❤️

/approve

@poiana
Copy link

poiana commented Jan 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, jasondellaluce, leogr

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [jasondellaluce,leogr]

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

@poiana poiana merged commit 475ed0d into falcosecurity:master Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http_output always uses "Content-Type: application/json" even if json formatting is disabled
4 participants