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

[DDO-3268] Improve logging/metrics for Gin responses #338

Merged
merged 5 commits into from
Oct 27, 2023

Conversation

jack-r-warren
Copy link
Contributor

Adds metrics for response latency/count, by Gin's matched route.

Also touches up logging. Normal internal log messages are staying the same, but the Gin ones now take full advantage of Zerolog's JSON fields. Things like the status code, client IP, latency, etc are no longer logged in just a big string, they're logged as fields with Zerolog.

This makes the Gin logging slightly worse locally, but way, way better through GCP. It's a balancing act and I think the Gin logs are primarily useful through GCP anyway, so I think it's okay. This also helps avoid logging things to console that we only need on GCP, like the client IP.

Before:
Screenshot 2023-10-27 at 3 32 40 PM
After:
Screenshot 2023-10-27 at 3 52 42 PM

Testing

Screenshots above; visited /metrics to validate that part.

Risk

Very low, no functionality changing, just logs

@jack-r-warren jack-r-warren requested a review from a team as a code owner October 27, 2023 19:54
@github-actions
Copy link

No API changes detected

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #338 (a591e4e) into main (cb2b83c) will decrease coverage by 0.02%.
Report is 1 commits behind head on main.
The diff coverage is 56.25%.

@@            Coverage Diff             @@
##             main     #338      +/-   ##
==========================================
- Coverage   63.23%   63.21%   -0.02%     
==========================================
  Files         147      147              
  Lines        8671     8683      +12     
==========================================
+ Hits         5483     5489       +6     
- Misses       2813     2819       +6     
  Partials      375      375              
Files Coverage Δ
sherlock/internal/boot/router.go 97.56% <100.00%> (+0.26%) ⬆️
sherlock/internal/config/config.go 35.61% <36.36%> (-1.31%) ⬇️

@github-actions
Copy link

github-actions bot commented Oct 27, 2023

Published image from a591e4e (merge 96b6216):

us-central1-docker.pkg.dev/dsp-artifact-registry/sherlock/sherlock:v0.2.21-96b6216

Copy link
Contributor

@mikeflinn mikeflinn left a comment

Choose a reason for hiding this comment

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

One question, otherwise looks straightforward to me!

Comment on lines +89 to +95
output.FormatCaller = func(i interface{}) string {
if i == nil {
return ""
} else {
return fmt.Sprintf("%-50s |", strings.TrimPrefix(fmt.Sprintf("%s", i), "/build/sherlock/internal"))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious what this is for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can set log.caller: true in the config and then this function formats out the call-site of the log message:

Screenshot 2023-10-27 at 4 09 26 PM

Added a comment to the function to explain that in-line

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jack-r-warren jack-r-warren merged commit a9707fa into main Oct 27, 2023
15 checks passed
@jack-r-warren jack-r-warren deleted the DDO-3268-latency-metrics branch October 27, 2023 20:17
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