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

logging tweaks to improve usability #1235

Merged
merged 3 commits into from
Dec 13, 2022

Conversation

bobcallaway
Copy link
Member

  • Changes HTTP Responses with codes >= 500 as Errors, any response < 500 as Warn
  • Removes / edits some rather noisy log statements
  • More aggressively use zap structured logging aligned with GCP logging norms
  • reimplements panic recovery so that log messages have correlated request ID for aided debugging

Signed-off-by: Bob Callaway bcallaway@google.com

Signed-off-by: Bob Callaway <bcallaway@google.com>
@bobcallaway bobcallaway requested a review from a team as a code owner December 10, 2022 12:17
@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2022

Codecov Report

Merging #1235 (d1306a3) into main (d0b8b83) will decrease coverage by 1.07%.
The diff coverage is 21.62%.

@@            Coverage Diff             @@
##             main    #1235      +/-   ##
==========================================
- Coverage   64.23%   63.16%   -1.08%     
==========================================
  Files          82       82              
  Lines        7628     7658      +30     
==========================================
- Hits         4900     4837      -63     
- Misses       2100     2208     +108     
+ Partials      628      613      -15     
Flag Coverage Δ
e2etests 47.79% <21.62%> (-1.07%) ⬇️
unittests 41.97% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/api/entries.go 63.99% <0.00%> (ø)
pkg/api/public_key.go 37.50% <ø> (-3.68%) ⬇️
pkg/log/log.go 47.61% <18.51%> (-22.66%) ⬇️
pkg/api/error.go 58.69% <50.00%> (-1.08%) ⬇️
pkg/types/jar/jar.go 37.03% <0.00%> (-29.63%) ⬇️
pkg/types/tuf/tuf.go 37.03% <0.00%> (-29.63%) ⬇️
pkg/types/tuf/v0.0.1/entry.go 49.79% <0.00%> (-12.25%) ⬇️
pkg/types/jar/v0.0.1/entry.go 47.57% <0.00%> (-10.20%) ⬇️
pkg/types/alpine/v0.0.1/entry.go 72.35% <0.00%> (-1.22%) ⬇️
pkg/types/rekord/v0.0.1/entry.go 68.42% <0.00%> (+0.65%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Bob Callaway <bcallaway@google.com>
enc.AddString("responseSize", h.responseSize)
enc.AddString("userAgent", h.userAgent)
enc.AddString("remoteIP", h.remoteIP)
enc.AddString("latency", h.latency)
Copy link
Contributor

Choose a reason for hiding this comment

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

enc.AddDuration("latency", h.latency)

Copy link
Member Author

Choose a reason for hiding this comment

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

https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest wants this represented as a string in units of seconds, so that's why I formatted it the way I did

fields = append(fields, zap.Any("extra", extra))
}

log.ContextLogger(z.r.Context()).With(fields...).Info("completed request")
Copy link
Contributor

Choose a reason for hiding this comment

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

If the fields were declared as []zapcore.Field then this can be
log.ContextLogger(z.r.Context()).With(fields).Info("completed request")

Copy link
Member Author

Choose a reason for hiding this comment

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

With([]interface{}) is how this is defined, and the logger doesn't work if you more strongly type this.

Signed-off-by: Bob Callaway <bcallaway@google.com>
status: status,
responseSize: bytes,
userAgent: z.r.Header.Get("User-Agent"),
remoteIP: z.r.RemoteAddr,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to log IP? Some PII risk of being able to correlate requests across artifacts, gather usage data, etc

@bobcallaway bobcallaway merged commit 1add455 into sigstore:main Dec 13, 2022
@github-actions github-actions bot added this to the v1.1.0 milestone Dec 13, 2022
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.

5 participants