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: skip writing RequestLogEntry for Cloud Run with flag enabled #821

Merged
merged 2 commits into from
Oct 24, 2023

Conversation

cindy-peng
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #795 🦕

This is a fix similar to the fix in nodejs-logging-bunyan to skip writting parent request log entries for cloud run.

To avoid breaking changes on the existing applications on Cloud Run, we introduce a optional parameter "skipParentEntryForCloudRun" to control the behavior. Right now the default behavior is still to create an request log entry unless "skipParentEntryForCloudRun" is set to be true specifically. We can change the default behavior in the next major release.

@generated-files-bot
Copy link

Warning: This pull request is touching the following templated files:

@product-auto-label product-auto-label bot added size: s Pull request size is small. api: logging Issues related to the googleapis/nodejs-logging-winston API. labels Oct 20, 2023
@cindy-peng cindy-peng changed the title Fix to skip writing RequestLogEntry for Cloud Run Skip writing RequestLogEntry for Cloud Run with flag Oct 20, 2023
@cindy-peng cindy-peng changed the title Skip writing RequestLogEntry for Cloud Run with flag fix: skip writing RequestLogEntry for Cloud Run with flag enabled Oct 20, 2023
@@ -35,15 +35,18 @@ type Middleware = ReturnType<typeof commonMiddleware.express.makeMiddleware>;

export async function makeMiddleware(
logger: winston.Logger,
transport: LoggingWinston
transport: LoggingWinston,
skipParentEntryForCloudRun?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this new parameter fully optional? (That is, could this break existing code?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Daniel, this new parameter is fully optional.

@@ -303,6 +303,8 @@ decrease logging record loss upon execution termination - since all logs are wri
would be picked up by the Cloud Logging Agent running in Google Cloud managed environment.
Note that there is also a `useMessageField` option which controls if "message" field is used to store
structured, non-text data inside `jsonPayload` field when `redirectToStdout` is set. By default `useMessageField` is always `true`.
Set the `skipParentEntryForCloudRun` option to skip creating an entry for the request itself as Cloud Run already automatically creates
such log entries. This might become the default behaviour in a next major version.
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I don't really like this as a solution, but since this was already implemented in nodejs-logging-bunyan, it does make sense to duplicate the fix as-is here.

It seems like this fix was meant to be temporary until the next major revision, when we can do a breaking change. Do you know if a bug is opened to track that? (I usually like to keep a milestone open in the issues list with changes that are waiting for the next breakinc change)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree, I wish I could find a more cleaner solution to this.
Regarding the tracking bug for the breaking change, I didn't find any in either this repo or in nodejs-logging-bunyan. Do you think we should open one in both repos to track it for the major release?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I like to use issue milestones to track major versions - and you can even have a branch for the next major version going when you're ready to start building changes for it.

But it's up to you how you want to organize things, just a suggestion!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I like to use issue milestones to track major versions - and you can even have a branch for the next major version going when you're ready to start building changes for it.

But it's up to you how you want to organize things, just a suggestion!

Makes sense! Thanks Daniel! For now I created this issue here to track the default behavior change for the major release: #824
Will explore how I can use milestones to track issues at different phases.

Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

mostly looks good, I just want to verify that the makeMiddleware changes wouldn't be considered breaking

@daniel-sanche daniel-sanche added the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 23, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 23, 2023
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@cindy-peng cindy-peng merged commit 7a0ec6f into googleapis:main Oct 24, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging-winston API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible replication of bug from nodejs-logging-bunyan
2 participants