fleet/server/datastore/mysql/config.go
Victor Lyuboslavsky 506901443d
Moved common_mysql package to server/platform/mysql (#38017)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #37244

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] QA'd all new/changed functionality manually



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Internal MySQL utility package reorganized and all internal imports
updated to the new platform location; no changes to end-user
functionality or behavior.

* **Documentation**
* Added platform package documentation describing infrastructure
responsibilities and architectural boundaries to guide maintainers.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-08 13:17:19 -06:00

77 lines
2 KiB
Go

package mysql
import (
"time"
"github.com/fleetdm/fleet/v4/server/config"
common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
"github.com/go-kit/log"
"github.com/ngrok/sqlmw"
)
const (
defaultMaxAttempts int = 15
defaultMinLastOpenedAtDiff = time.Hour
)
// DBOption is used to pass optional arguments to a database connection
type DBOption func(o *common_mysql.DBOptions) error
// Logger adds a Logger to the datastore.
func Logger(l log.Logger) DBOption {
return func(o *common_mysql.DBOptions) error {
o.Logger = l
return nil
}
}
// WithInterceptor adds the sql Interceptor to the datastore.
func WithInterceptor(i sqlmw.Interceptor) DBOption {
return func(o *common_mysql.DBOptions) error {
o.Interceptor = i
return nil
}
}
// Replica sets the configuration of the read replica for the datastore.
func Replica(conf *config.MysqlConfig) DBOption {
return func(o *common_mysql.DBOptions) error {
o.ReplicaConfig = toCommonMysqlConfig(conf)
return nil
}
}
// LimitAttempts sets a the number of attempts
// to try establishing a connection to the database backend
// the default value is 15 attempts
func LimitAttempts(attempts int) DBOption {
return func(o *common_mysql.DBOptions) error {
o.MaxAttempts = attempts
return nil
}
}
func TracingEnabled(lconfig *config.LoggingConfig) DBOption {
return func(o *common_mysql.DBOptions) error {
o.TracingConfig = toCommonLoggingConfig(lconfig)
return nil
}
}
// WithFleetConfig provides the fleet configuration so that any config option
// that must be used in the datastore layer can be captured here.
func WithFleetConfig(conf *config.FleetConfig) DBOption {
return func(o *common_mysql.DBOptions) error {
o.MinLastOpenedAtDiff = conf.Osquery.MinSoftwareLastOpenedAtDiff
o.PrivateKey = conf.Server.PrivateKey
return nil
}
}
// SQLMode allows setting a custom sql_mode string.
func SQLMode(mode string) DBOption {
return func(o *common_mysql.DBOptions) error {
o.SqlMode = mode
return nil
}
}