-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… (#3017) * PMM-13145 Fix for older clients. * PMM-13145 Small changes. * PMM-13145 Lint. * PMM-13145 Lint. * PMM-13145 Logic fix. * PMM-13145 Refactor. * PMM-13145 Fix after refactor. * Update managed/models/agent_model.go * Update managed/models/agent_model.go --------- Co-authored-by: Nurlan Moldomurov <[email protected]>
- Loading branch information
1 parent
7221d3e
commit 74e5752
Showing
11 changed files
with
83 additions
and
48 deletions.
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 |
---|---|---|
|
@@ -66,15 +66,15 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
|
||
t.Run("MongoDBNoDatabase", func(t *testing.T) { | ||
agent.AgentType = models.MongoDBExporterType | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true", agent.DSN(service, models.DSNParams{}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true", agent.DSN(service, models.DSNParams{}, nil, nil)) | ||
}) | ||
}) | ||
|
||
|
@@ -94,7 +94,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
}) | ||
|
@@ -113,7 +113,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
}) | ||
|
@@ -159,7 +159,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
|
||
|
@@ -169,8 +169,8 @@ func TestAgent(t *testing.T) { | |
agent.MongoDBOptions.TLSCertificateKeyFilePassword = "" | ||
agent.MongoDBOptions.AuthenticationMechanism = "" | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil, nil)) | ||
expectedFiles := map[string]string{ | ||
"caFilePlaceholder": "cert", | ||
"certificateKeyFilePlaceholder": "key", | ||
|
@@ -185,8 +185,8 @@ func TestAgent(t *testing.T) { | |
agent.MongoDBOptions.AuthenticationMechanism = "MONGO-X509" | ||
agent.MongoDBOptions.AuthenticationDatabase = "$external" | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil, nil)) | ||
expectedFiles := map[string]string{ | ||
"caFilePlaceholder": "cert", | ||
"certificateKeyFilePlaceholder": "key", | ||
|
@@ -217,15 +217,15 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
|
||
t.Run("MongoDBNoDatabase", func(t *testing.T) { | ||
agent.AgentType = models.MongoDBExporterType | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{}, nil, nil)) | ||
}) | ||
}) | ||
} | ||
|
@@ -255,13 +255,13 @@ func TestPostgresAgentTLS(t *testing.T) { | |
t.Run(name, func(t *testing.T) { | ||
agent.TLS = testCase.tls | ||
agent.TLSSkipVerify = testCase.tlsSkipVerify | ||
assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
t.Run(fmt.Sprintf("AutodiscoveryLimit set TLS:%v/TLSSkipVerify:%v", testCase.tls, testCase.tlsSkipVerify), func(t *testing.T) { | ||
agent.TLS = testCase.tls | ||
agent.TLSSkipVerify = testCase.tlsSkipVerify | ||
agent.PostgreSQLOptions = &models.PostgreSQLOptions{AutoDiscoveryLimit: 10} | ||
assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
} | ||
|
@@ -278,7 +278,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/var/run/postgres"), | ||
} | ||
expect := "postgres://username@/database?connect_timeout=1&host=%2Fvar%2Frun%2Fpostgres&sslmode=verify-ca" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
|
||
t.Run("empty-user-password", func(t *testing.T) { | ||
|
@@ -289,7 +289,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/var/run/postgres"), | ||
} | ||
expect := "postgres:///database?connect_timeout=1&host=%2Fvar%2Frun%2Fpostgres&sslmode=disable" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
|
||
t.Run("dir-with-symbols", func(t *testing.T) { | ||
|
@@ -300,7 +300,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-`), | ||
} | ||
expect := "postgres:///database?connect_timeout=1&host=%2Ftmp%2F123%5C+A0m%5C%25%5C%24%5C%40%5C8%5C%2C%5C%2B%5C-&sslmode=disable" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
|
||
|
@@ -316,7 +316,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/tmp/mongodb-27017.sock"), | ||
} | ||
expect := "mongodb://username@%2Ftmp%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
|
||
t.Run("empty-user-password", func(t *testing.T) { | ||
|
@@ -327,7 +327,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/tmp/mongodb-27017.sock"), | ||
} | ||
expect := "mongodb://%2Ftmp%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
|
||
t.Run("dir-with-symbols", func(t *testing.T) { | ||
|
@@ -338,7 +338,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-/mongodb-27017.sock`), | ||
} | ||
expect := "mongodb://%2Ftmp%2F123%5C%20A0m%5C%25%5C$%5C%40%5C8%5C,%5C+%5C-%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000" | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil, nil)) | ||
}) | ||
} | ||
|
||
|
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
Oops, something went wrong.