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

Small wording and formatting changes, moved Getenv inline #120

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,12 @@ LOGLEVEL=info ./sql_exporter
Database specific configurations
--------------------------------

For some database backends some special functionality is available :
For some database backends some special functionality is available:

* cloudsql-postgres: a special `*` caracter can be used to query all databases
accessible by the account
* cloudsql-mysql : same as above
* rds-postgres : this type of URL expects a working AWS configuration
which will use action the equivalent of `rds generate-db-auth-token`
* cloudsql-postgres: A special `*` character can be used to query all databases accessible by the account
* cloudsql-mysql: Same as above
* rds-postgres: This type of URL expects a working AWS configuration
which will use the equivalent of `rds generate-db-auth-token`
for the password. For this driver, the `AWS_REGION` environment variable
must be set.

Expand Down
15 changes: 6 additions & 9 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,19 @@ func (j *Job) updateConnections() {
continue
}
if strings.HasPrefix(conn, "rds-postgres://") {
// reuse postgres SQLDriver by stripping rds- from connexion URL after building the RDS
// authentication token
// Reuse Postgres driver by stripping "rds-" from connection URL after building the RDS authentication token
conn = strings.TrimPrefix(conn, "rds-")
// FIXME - parsing twice the conn url to extract host & username
u, err := url.Parse(conn)
if err != nil {
level.Error(j.log).Log("msg", "Failed to parse URL", "url", conn, "err", err)
continue
}
region := os.Getenv("AWS_REGION")
level.Error(j.log).Log("msg", "failed to parse connection url", "url", conn, "err", err)
continue
}
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
token, err := rdsutils.BuildAuthToken(u.Host, region, u.User.Username(), sess.Config.Credentials)
token, err := rdsutils.BuildAuthToken(u.Host, os.Getenv("AWS_REGION"), u.User.Username(), sess.Config.Credentials)
if err != nil {
level.Error(j.log).Log("msg", "Failed to parse URL", "url", conn, "err", err)
level.Error(j.log).Log("msg", "failed to parse connection url", "url", conn, "err", err)
continue
}
conn = strings.Replace(conn, "AUTHTOKEN", url.QueryEscape(token), 1)
Expand Down
Loading