-
Notifications
You must be signed in to change notification settings - Fork 887
chore: generate dbmetrics automatically when adding new queries #7999
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
Conversation
coderd/database/dbgen/dbgen.go
Outdated
@@ -525,3 +525,40 @@ func must[V any](v V, err error) V { | |||
} | |||
return v | |||
} | |||
|
|||
func takeFirstIP(values ...net.IPNet) net.IPNet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this came from a commit from a different PR/branch you were working on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I gotta merge in main
"github.com/dave/dst" | ||
"github.com/dave/dst/decorator" | ||
"github.com/dave/dst/decorator/resolver/goast" | ||
"github.com/dave/dst/decorator/resolver/guess" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice on Kyle!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I wanted to do, but had a hard time figuring out was if we could automatically sort our functions in these massive "db wrap" packages.
I think with how you have done it here, we could sort the func decls before writing.
We do not need to do it in this PR, but that would be really cool.
code := fmt.Sprintf(` | ||
package stub | ||
|
||
func stub() { | ||
start := time.Now() | ||
%s := m.s.%s(%s) | ||
m.queryLatencies.WithLabelValues("%s").Observe(time.Since(start).Seconds()) | ||
return %s | ||
} | ||
`, strings.Join(returns, ","), fn.Name, strings.Join(params, ","), fn.Name, strings.Join(returns, ",")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion, but up to you. The dave package said it retained comments, but not 100% if this works.
package stub
func stub() {
// Function generated by coderd/database/gen/metrics/main.go
// Manual edits are allowed and will be retained.
start := time.Now()
%s := m.s.%s(%s)
m.queryLatencies.WithLabelValues("%s").Observe(time.Since(start).Seconds())
return %s
}
The general idea is just to inform the developers where this code comes from. Especially if we run into any issues early on.
Your call though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work, but I think I'll exclude it for now... I don't make note that it's generated anyways, so I think people will feel free to edit it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair 👍
No description provided.