Skip to content

Conversation

@muncus
Copy link
Collaborator

@muncus muncus commented Nov 16, 2021

Sample function prints fields to the logs, and has been manually tested with GCS write audit logs.

This is the Go version of this canonical sample: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/2991f86146742d00725c4dd73bf3719bd25e809b/functions/v2/index.js#L65

Sample function prints fields, and has been tested with GCS write audit
logs.
@muncus muncus requested a review from grayside November 16, 2021 20:14
@snippet-bot
Copy link

snippet-bot bot commented Nov 16, 2021

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Nov 16, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 16, 2021
I removed a log statement that the tests were looking for 🤦
@muncus muncus marked this pull request as ready for review November 16, 2021 23:39
@muncus muncus requested a review from a team as a code owner November 16, 2021 23:39
Copy link
Contributor

@grayside grayside left a comment

Choose a reason for hiding this comment

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

This is a very good sample PR, thank you. I can tell a lot of care was taken to track existing practices & patterns.

Unfortunately the google-cloudevents-go library is not recommended for use, we need to try another way. You can see in https://github.com/GoogleCloudPlatform/golang-samples/blob/main/functions/functionsv2/hellopubsub/hello_pubsub_test.go we created an ad hoc struct. We hope to switch to that library in the future.

"log"

"github.com/cloudevents/sdk-go/v2/event"
auditevents "github.com/googleapis/google-cloudevents-go/cloud/audit/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

blocking: Unfortunately this library is not GA and we shouldn't use it yet. I'm curious how you found your way to this library, and what we might do to prevent others for deciding to use it?

Copy link
Collaborator Author

@muncus muncus Nov 19, 2021

Choose a reason for hiding this comment

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

Thanks for bringing this to my attention. I've removed use of this library in favor of some minimal structs.

As for finding the library:
There is a documentation page that appears to conflate the two things called "cloud event": https://cloud.google.com/eventarc/docs/cloudevents#open-source
there are additional references in the Common Events section that link to protobufs, and the google-cloudevents repo docs.

payload auditevents.ProtoPayload
expectedLogs []string
}{
{"sample-output",
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: name declarations for longer struct definitions improve readability. I went looking for whether we have a standard on this, and I couldn't find one so it may just be opinion ;)

Since I'm curious if I'm missing something, @codyoss do you know?
I skimmed through https://golang.org/doc/effective_go and https://github.com/golang/go/wiki/CodeReviewComments

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

convention or not, i'm happy to add that. it seems like a reasonable practice, even if it is not standard. (will leave comment open for cody's input).

Copy link
Collaborator Author

@muncus muncus left a comment

Choose a reason for hiding this comment

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

I think i've addressed your comments, and this is ready for another round of review.
(some comments left open for your input, feel free to resolve if you're satisfied).

@muncus muncus requested a review from grayside November 24, 2021 18:36
@ace-n ace-n requested a review from tbpg November 30, 2021 01:39
@ace-n
Copy link
Contributor

ace-n commented Nov 30, 2021

@tbpg can you rubber-stamp this? (I don't think @grayside is an admin. 🤷 )


// AuditLogProtoPayload represents AuditLog within the LogEntry.protoPayload
// See https://cloud.google.com/logging/docs/reference/audit/auditlog/rest/Shared.Types/AuditLog
type AuditLogProtoPayload struct {
Copy link
Member

Choose a reason for hiding this comment

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

Should we me making use of generated proto stubs? https://github.com/googleapis/go-genproto/blob/4c6863e31247658eee07a5b0075340c04399d1d4/googleapis/cloud/audit/audit_log.pb.go#L43

Or does this even lib not work with those types?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey Cody, we're following a medium-term pattern of inlining the data structure. We're doing this both as a bridge to the future library dependency we plan to take (from https://github.com/googleapis/google-cloudevents libraries) and to cover a gap in documentation that's still being resolved.

I'm not strongly opposed to go using that reference, if you feel it's a reasonable thing for developers to take direct dependency. It would be a difference for this sample vs. the other GCF v2 samples.

Copy link
Member

Choose a reason for hiding this comment

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

The inline struct is fine by me, I just wanted to make sure this choice was intentional. Anyone that uses our client libraries would already have this dep in their tree.

@muncus muncus merged commit d42f3c2 into main Dec 1, 2021
@muncus muncus deleted the auditlog-sample branch December 1, 2021 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants