Skip to content

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

Merged
merged 3 commits into from
Jun 13, 2023

Conversation

kylecarbs
Copy link
Member

No description provided.

@kylecarbs kylecarbs requested a review from johnstcn June 13, 2023 14:12
@kylecarbs kylecarbs self-assigned this Jun 13, 2023
@@ -525,3 +525,40 @@ func must[V any](v V, err error) V {
}
return v
}

func takeFirstIP(values ...net.IPNet) net.IPNet {
Copy link
Member

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

Copy link
Member Author

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

Comment on lines +11 to +14
"github.com/dave/dst"
"github.com/dave/dst/decorator"
"github.com/dave/dst/decorator/resolver/goast"
"github.com/dave/dst/decorator/resolver/guess"
Copy link
Member

Choose a reason for hiding this comment

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

Interesting package

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed

@kylecarbs kylecarbs changed the title chore: automatically generate dbmetrics when new queries are added chore: generate dbmetrics automatically when adding new queries Jun 13, 2023
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Nice on Kyle!

Copy link
Member

@Emyrk Emyrk left a 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.

Comment on lines +83 to +92
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, ","))
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Fair 👍

@kylecarbs kylecarbs merged commit 794a551 into main Jun 13, 2023
@kylecarbs kylecarbs deleted the dbmetricsgen branch June 13, 2023 17:35
@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants