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
[Audit Logging] Stdout logger implementation #33026
Conversation
Automated fix for refs/heads/stdout-logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a few comments
constexpr absl::string_view kName = "stdout_logger"; | ||
const char kLogFormat[] = | ||
"{\"grpc_audit_log\":{\"timestamp\":%d,\"rpc_method\":\"%s\",\"principal\":" | ||
"\"%s\",\"policy_name\":\"%s\",\"matched_rule\":\"%s\",\"authorized\":%s}}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this have implicit newlines, and if so do we want a multi-line log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I meant to add a newline to flush the buffer but forgot. Added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually meant the other way around, do we want any newlines here at all, or one big single line that is the audit log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you also saw in the Go PR, we want one log entry to be one-liner.
EXPECT_TRUE(AuditLoggerRegistry::FactoryExists(kName)); | ||
EXPECT_FALSE(AuditLoggerRegistry::FactoryExists("unknown_logger")); | ||
} | ||
|
||
// | ||
// StdoutLoggerTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth having StdOutLoggerTest in it's own file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stdout logger is added to the same library target in the BUILD file. I think it's easier to have things in the same test target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM other than the question about multi-line vs. single-line logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good overall! Comments are relatively minor.
Please let me know if you have any questions. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. I addressed the comments as I can for now. Will ask for another look once the timestamp format is finalized.
Automated fix for refs/heads/stdout-logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a couple of minor nits remaining. Feel free to merge after addressing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
In one recent build, the invocation of
I changed it back to |
The logger uses `absl::FPrintF` to write to stdout. After reading a number of sources online, I got the impression that `std::fwrite` which is used by `absl::FPrintF` is atomic so there is no locking required here. --------- Co-authored-by: rockspore <rockspore@users.noreply.github.com>
The logger uses `absl::FPrintF` to write to stdout. After reading a number of sources online, I got the impression that `std::fwrite` which is used by `absl::FPrintF` is atomic so there is no locking required here. --------- Co-authored-by: rockspore <rockspore@users.noreply.github.com>
The logger uses
absl::FPrintF
to write to stdout. After reading a number of sources online, I got the impression thatstd::fwrite
which is used byabsl::FPrintF
is atomic so there is no locking required here.