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

Add mysql driver support for Sqlmetrics #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SwatiModi
Copy link

@SwatiModi SwatiModi commented Jun 13, 2022

  • Add support for mysql driver for sql metrics with unit tests
  • Add new label for statement of the query to emitted labels

snapshot of sample app with sqlmetrics emitted with the above changes

func storeConnInfo(conn *proxy.Conn, dsn string) error {
info, err := parseDSN(dsn)
func storeConnInfo(conn *proxy.Conn, driverName, dsn string) error {
info, err := parseDSN(driverName, dsn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use dburl package to derive this. Every dsn that connects already has this information. If it doesn't. It may not connect eirher.

@@ -51,8 +51,29 @@ func loadConnInfo(conn *proxy.Conn) *connInfo {
return info.(*connInfo)
}

func parseDSN(dsn string) (*connInfo, error) {
u, err := dburl.Parse(dsn)
// Note: the DB Url library expects a scheme in the DSN for
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a correct way to handle this. Sql package supports magnitudes of queriersz we cannot switch case for all. Let the expected dan contain the scheme.

func getStatementName(driver, q string) string {

switch strings.Split(driver, ":")[0] {
case "postgres":
Copy link
Contributor

Choose a reason for hiding this comment

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

Promote these strings as module global constants. Strings don't auto complete, variables do.

@@ -52,21 +52,23 @@ func TestPq(t *testing.T) {
srv := tests.MakeServer(mux)
defer srv.Close()

driverName := "postgres"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the same module level constants here.

@meson10
Copy link
Contributor

meson10 commented Jun 13, 2022

Btw you might hve to change the harness too since you changed the wait_postgres to wait_db

@@ -145,7 +145,7 @@ func RegisterDriverWithLabelMaker(d Options, fn LabelMaker) (string, error) {
dc := ctx.(*dbCtx)

if err := emitDuration(
fn(dc.query).Merge(
fn(name, dc.query).Merge(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a scalable design you see. Imagine from the consumer who is overriding this. You may have to take a switch based on driver name. Others may do so on other basis. Best way is to return the Options struct itself in the function argument.

Also, don't use d.GetName() for switch case, use d.Name which is the original unmangled name.

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