diff options
| author | Julie Qiu <julie@golang.org> | 2020-08-06 19:04:42 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-08-07 13:14:12 +0000 |
| commit | 49799e70c082d908fdba73648ed1ba792ba8f5f4 (patch) | |
| tree | 8075371030050c5169a76f9e06044ea797ec30e4 /internal/database/database.go | |
| parent | 21e796723ad444b9190cf9dbeb7e08eb3d07b7ac (diff) | |
| download | go-x-pkgsite-49799e70c082d908fdba73648ed1ba792ba8f5f4.tar.xz | |
internal/database: downgrade context canceled errors to debug level
There are many places in our logs when a query will be canceled, because
all unfinished search queries for a given request are canceled.
We don't want to log these as errors, because it makes the logs very
noisy. These are downgraded to a debug level log.
Change-Id: Iaddce240394cfb4eb79b03f384e5dabbd8e84ea5
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/247280
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'internal/database/database.go')
| -rw-r--r-- | internal/database/database.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/internal/database/database.go b/internal/database/database.go index 4c8aff18..bf11757f 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -510,7 +510,24 @@ func logQuery(ctx context.Context, query string, args []interface{}, instanceID log.Debug(ctx, entry) } else { entry.Error = (*errp).Error() - log.Error(ctx, entry) + // There are many places in our logs when a query will be + // canceled, because all unfinished search queries for a given + // request are canceled: + // https://github.com/golang/pkgsite/blob/03662129627796aa387a26b8f4f9251caf5d57fd/internal/postgres/search.go#L178 + // + // We don't want to log these as errors, because it makes the logs + // very noisy. Based on + // https://github.com/lib/pq/issues/577#issuecomment-298341053 + // it seems that ctx.Err() could return nil because this error + // is coming from postgres. github.com/lib/pq currently handles + // errors like these in their tests by hardcoding the string: + // https://github.com/lib/pq/blob/e53edc9b26000fec4c4e357122d56b0f66ace6ea/go18_test.go#L89 + logf := log.Error + if errors.Is(ctx.Err(), context.Canceled) || + strings.Contains(entry.Error, "pq: canceling statement due to user request") { + logf = log.Debug + } + logf(ctx, entry) } } } |
