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

Support gormio #825

Merged
merged 14 commits into from Oct 7, 2020
Merged

Support gormio #825

merged 14 commits into from Oct 7, 2020

Conversation

Deepak13245
Copy link

@Deepak13245 Deepak13245 commented Oct 4, 2020

Resolves #810

@cla-checker-service
Copy link

cla-checker-service bot commented Oct 4, 2020

💚 CLA has been signed

@apmmachine
Copy link
Collaborator

apmmachine commented Oct 4, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #825 updated]

  • Start Time: 2020-10-07T06:46:44.082+0000

  • Duration: 26 min 50 sec

Test stats 🧪

Test Results
Failed 0
Passed 7571
Skipped 182
Total 7753

@axw
Copy link
Member

axw commented Oct 5, 2020

@Deepak13245 thanks for the PR!

Looks pretty good, but I'm wondering if the callbacks are still necessary. If context is now first class, then perhaps we can instead just rely on apmsql to create the spans?

Also, I'd like to call this module apmgormv2 to be more in line with other modules.

@Deepak13245
Copy link
Author

@axw renamed to apmgormv2
regarding the creation of spans by apmsql, gorm doesn't accept *sql.DB directly in params. There is a workaround so I raised a separate PR Deepak13245#1. Please suggest if there is a better approach.

Thanks

@axw
Copy link
Member

axw commented Oct 5, 2020

A couple of things bother me about the plugin approach:

  • It closes and reopens the connection. Not the end of the world, just a bit annoying.
  • As it is at the moment, extractDsn forces a dependency on all the drivers. We could solve this by having the "_" dialect imports register a function though.

What do you think about providing "Open" functions inside the dialect packages instead? So instead of

import (
    "gorm.io/driver/sqlite"
    "gorm.io/gorm"         
)

db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})

you could write

import (
    "go.elastic.co/apm/module/apmgormv2/dialect/apmsqlite"
    "gorm.io/gorm"
)

db, err := gorm.Open(apmsqlite.Open("gorm.db"), &gorm.Config{})

Internally this would use the recently introduced support for custom drivers: go-gorm/sqlite#11

Basically just:

package apmsqlite // go.elastic.co/module/apmgormv2/dialect/apmsqlite

import (
    "gorm.io/driver/sqlite"
    "gorm.io/gorm"
    "go.elastic.co/module/apm/module/apmsql"
    _ "go.elastic.co/module/apm/module/apmsql/sqlite3"
)

func Open(dsn string) gorm.Dialector {
        return &sqlite.Dialector{
                DriverName: apmsql.DriverPrefix + sqlite.DriverName,
                DSN:        dsn,
        }
}

@Deepak13245
Copy link
Author

@axw creating dialect from with driver prefix makes it neat, updated the pr please check.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Thanks! I agree this looks much neater.

module/apmgormv2/driver/sqlite/init.go Outdated Show resolved Hide resolved
module/apmgormv2/driver/postgres/init.go Outdated Show resolved Hide resolved
@axw
Copy link
Member

axw commented Oct 6, 2020

jenkins run the tests please

@Deepak13245 Deepak13245 requested a review from axw October 6, 2020 11:06
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

@axw
Copy link
Member

axw commented Oct 7, 2020

jenkins run the tests please

@axw
Copy link
Member

axw commented Oct 7, 2020

[2020-10-07T02:40:59.696Z] ../../gorm.io/gorm/utils/utils.go:46:30: reflect.ValueOf(val).IsZero undefined (type reflect.Value has no field or method IsZero)

It looks like gorm v2 requires Go 1.13+, so we'll need to update the build constraint.

@Deepak13245 Deepak13245 requested a review from axw October 7, 2020 03:39
@axw
Copy link
Member

axw commented Oct 7, 2020

Looks good, I think the remaining test failures are fixed on master. Can you please merge master so we can make sure?

module/apmgormv2/doc.go Outdated Show resolved Hide resolved
Co-authored-by: Andrew Wilkins <axwalk@gmail.com>
@axw
Copy link
Member

axw commented Oct 7, 2020

CI looks happy. Thanks for another nice PR, and for bearing with my requests :)

@axw axw merged commit 372d026 into elastic:master Oct 7, 2020
@Deepak13245 Deepak13245 deleted the feature/module_gormio branch October 7, 2020 07:19
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.

Add instrumentation for gorm v2
3 participants