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

log full body only on slow requests and only 10 per day #3215

Draft
wants to merge 1 commit into
base: log-req-body-core-189
Choose a base branch
from

Conversation

gvelez17
Copy link
Contributor

@gvelez17 gvelez17 commented Apr 24, 2024

Description

to be combined with the PR for logging full body of requests, do so only for slow requests and limit how many

How Has This Been Tested?

Describe the tests that you ran to verify your changes. Provide instructions for reproduction.

  • Test A (e.g. Test A - New test that ... ran in local, docker, and dev unstable.)
  • Test B

PR checklist

Before submitting this PR, please make sure:

  • I have tagged the relevant reviewers and interested parties
  • I have updated the READMEs of affected packages
  • I have made corresponding changes to the documentation

References:

Please list relevant documentation (e.g. tech specs, articles, related work etc.) relevant to this change, and note if the documentation has been updated.

@gvelez17 gvelez17 force-pushed the feat/log-slow-requests-daily branch from c978c75 to 759234d Compare April 24, 2024 01:04
Copy link
Contributor

@stbrody stbrody left a comment

Choose a reason for hiding this comment

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

hmm... I feel like ideally the slow request log would apply to all types of requests (whereas this handler for "body" only applies to POST requests, not GETs), would cause the query to be logged even when we otherwise aren't logging http requests, and would have a more custom message specifying explicitly that this is a slow query.

Then in the regular case when logging http requests normally, we would still log the body, but maybe not expand sub-objects, so you only get the top-level fields and sub-objects print as [object object] (which they were doing before I added the code to check if the value is an object with multiple keys and if so call JSON.stringify on it).

That said, doing all of that sounds tricky and just doing this is strictly better than where things are today, so I don't think we should hold this up too much to make it perfect.

Maybe one thing we could do is use the logSlowRequest variable to control whether we expand out sub-objects or not, but always include at least the top-level fields. What do you think?

@@ -2,10 +2,38 @@ import { LoggerProvider } from '@ceramicnetwork/common'
import { Request, Response } from 'express'
import morgan from 'morgan'

const EXPECTED_RESPONSE_TIME_MS = 2000
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the default threshold for what's considered a "slow" request should probably be higher. Maybe 15 seconds?

Also might be nice to make this threshold configurable.

@@ -2,10 +2,38 @@ import { LoggerProvider } from '@ceramicnetwork/common'
import { Request, Response } from 'express'
import morgan from 'morgan'

const EXPECTED_RESPONSE_TIME_MS = 2000
const MAX_DAILY_SLOW_REQUESTS_TO_LOG = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

What about only logging one slow query per minute instead? I think that will still be infrequent enough to not flood the logs, while making the slow queries a lot more visible if they are happening often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants