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

When does the newly created mysql username or password contain characters ? , the startup will fail. #831

Open
midy177 opened this issue Apr 8, 2024 · 0 comments

Comments

@midy177
Copy link

midy177 commented Apr 8, 2024

When does the newly created mysql username or password contain characters ? , the startup will fail.

After inspection, it was found that in collector/exporter.go:107After inspection, it was found that in the processing method of collector/exporter.go 107, when the password contains the characters ? The logic does not work correctly.
```golang`
// New returns a new MySQL exporter for the provided DSN.
func New(ctx context.Context, dsn string, scrapers []Scraper, logger log.Logger) *Exporter {
// Setup extra params for the DSN, default to having a lock timeout.
dsnParams := []string{fmt.Sprintf(timeoutParam, *exporterLockTimeout)}

if *slowLogFilter {
	dsnParams = append(dsnParams, sessionSettingsParam)
}

if strings.Contains(dsn, "?") {
	dsn = dsn + "&"
} else {
	dsn = dsn + "?"
}
dsn += strings.Join(dsnParams, "&")

return &Exporter{
	ctx:      ctx,
	logger:   logger,
	dsn:      dsn,
	scrapers: scrapers,
}

}

 It is recommended to change it to:
```golang
// New returns a new MySQL exporter for the provided DSN.
func New(ctx context.Context, dsn string, scrapers []Scraper, logger log.Logger) *Exporter {
	// Setup extra params for the DSN, default to having a lock timeout.
	dsnParams := []string{fmt.Sprintf(timeoutParam, *exporterLockTimeout)}

	if *slowLogFilter {
		dsnParams = append(dsnParams, sessionSettingsParam)
	}

	if !strings.HasSuffix(dsn, ")/") {
		arr := strings.Split(dsn, ")/")
		lastItem := arr[len(arr)-1]
		if strings.Contains(lastItem, "?") {
			dsn = dsn + "&"
		}
	} else {
		dsn = dsn + "?"
	}
	dsn += strings.Join(dsnParams, "&")

	return &Exporter{
		ctx:      ctx,
		logger:   logger,
		dsn:      dsn,
		scrapers: scrapers,
	}
}
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

No branches or pull requests

1 participant