-
Notifications
You must be signed in to change notification settings - Fork 812
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
mysql: pass TLS config directly to MySQL's config #3348
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"net/url" | ||
"strings" | ||
"sync" | ||
"sync/atomic" | ||
|
||
"contrib.go.opencensus.io/integrations/ocsql" | ||
"github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/proxy" | ||
|
@@ -97,12 +98,8 @@ | |
if uo.CertSource == nil { | ||
return nil, fmt.Errorf("gcpmysql: URLOpener CertSource is nil") | ||
} | ||
// TODO(light): Avoid global registry once https://github.com/go-sql-driver/mysql/issues/771 is fixed. | ||
dialerCounter.mu.Lock() | ||
dialerNum := dialerCounter.n | ||
dialerCounter.mu.Unlock() | ||
Comment on lines
-101
to
-103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No increment, it always zero |
||
dialerName := fmt.Sprintf("gocloud.dev/mysql/gcpmysql/%d", dialerNum) | ||
|
||
dialerName := fmt.Sprintf("gocloud.dev/mysql/gcpmysql/%d", | ||
atomic.AddUint32(&dialerCounter, 1)) | ||
cfg, err := configFromURL(u, dialerName) | ||
if err != nil { | ||
return nil, fmt.Errorf("gcpmysql: open config %v", err) | ||
|
@@ -112,7 +109,7 @@ | |
Port: 3307, | ||
Certs: uo.CertSource, | ||
} | ||
mysql.RegisterDial(dialerName, client.Dial) | ||
mysql.RegisterDialContext(dialerName, client.DialContext) | ||
|
||
db := sql.OpenDB(connector{cfg.FormatDSN(), uo.TraceOpts}) | ||
return db, nil | ||
|
@@ -161,10 +158,7 @@ | |
return parts[0] + ":" + parts[1] + ":" + parts[2], parts[3], nil | ||
} | ||
|
||
var dialerCounter struct { | ||
mu sync.Mutex | ||
n int | ||
} | ||
var dialerCounter uint32 | ||
|
||
type connector struct { | ||
dsn string | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you explain why this TODO can be addressed while the issue referenced is still open?
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.
For this part, it really doesnt have another solution, and the package itself will not support to change this to a custom dialer function. So, I think the current implement is correct and no need to change in future. The package sql-cloud-proxy also used this way without comment
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.
It would help if you would explain what problem you are trying to solve. Does the current code not work? Or are you trying to simplify it?
Our testing for this part of the codebase is not good, and I am hesitant to make changes that I don't fully understand without any rationale, especially when there's a TODO in the code that hasn't been addressed.
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.
Hey, hello again.
I was checked the source code of
awsmysql
andazuremysql
and notice about TLSConfig's todo. I checked mysql driver on the upstream repository and it was supported to replace withTLS
fieldhttps://github.com/go-sql-driver/mysql/blob/master/dsn.go#L125-L142
for the
gcpmysql
, the todo comment wasn't correct, because this package useDial
function to make the connection, which no replacement in the feature.This is another example that use the same approach for
Dial
:https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/blob/main/mysql/mysql/mysql.go#L40-L49
And the package
gcpmysql
also have a bug for generate driver name, it used same name for all connection.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.
It would help if you would explain what problem you are trying to solve. Does the current code not work? Or are you trying to simplify 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.
Simplify, and fix one bug.