Skip to content

Commit

Permalink
Cleaning up a couple issues missed during review
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Jan 14, 2025
1 parent 581c2f9 commit 7d54ed2
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions go/libraries/doltcore/servercfg/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ func nillableIntPtr(n int) *int {
return &n
}

func nillableSlicePtr[T any](s []T) *[]T {
if len(s) == 0 {
return nil
}
return &s
}

func nillableMapPtr[K comparable, V any](m map[K]V) *map[K]V {
if len(m) == 0 {
return nil
}
return &m
}

// BehaviorYAMLConfig contains server configuration regarding how the server should behave
type BehaviorYAMLConfig struct {
ReadOnly *bool `yaml:"read_only,omitempty"`
Expand Down Expand Up @@ -113,7 +99,7 @@ type PerformanceYAMLConfig struct {
}

type MetricsYAMLConfig struct {
Labels *map[string]string `yaml:"labels,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Host *string `yaml:"host,omitempty"`
Port *int `yaml:"port,omitempty"`
}
Expand Down Expand Up @@ -153,7 +139,7 @@ type YAMLConfig struct {
// TODO: Rename to UserVars_
Vars []UserSessionVars `yaml:"user_session_vars,omitempty"`
SystemVars_ map[string]interface{} `yaml:"system_variables,omitempty" minver:"1.11.1"`
Jwks *[]JwksConfig `yaml:"jwks,omitempty"`
Jwks []JwksConfig `yaml:"jwks,omitempty"`
GoldenMysqlConn *string `yaml:"golden_mysql_conn,omitempty"`
MetricsConfig MetricsYAMLConfig `yaml:"metrics,omitempty"`
ClusterCfg *ClusterYAMLConfig `yaml:"cluster,omitempty"`
Expand Down Expand Up @@ -220,7 +206,7 @@ func ServerConfigAsYAMLConfig(cfg ServerConfig) *YAMLConfig {
DataDirStr: ptr(cfg.DataDir()),
CfgDirStr: ptr(cfg.CfgDir()),
MetricsConfig: MetricsYAMLConfig{
Labels: nillableMapPtr(cfg.MetricsLabels()),
Labels: cfg.MetricsLabels(),
Host: nillableStrPtr(cfg.MetricsHost()),
Port: ptr(cfg.MetricsPort()),
},
Expand All @@ -233,7 +219,7 @@ func ServerConfigAsYAMLConfig(cfg ServerConfig) *YAMLConfig {
BranchControlFile: ptr(cfg.BranchControlFilePath()),
SystemVars_: systemVars,
Vars: cfg.UserVars(),
Jwks: nillableSlicePtr(cfg.JwksConfig()),
Jwks: cfg.JwksConfig(),
}
}

Expand Down Expand Up @@ -293,7 +279,7 @@ func ServerConfigSetValuesAsYAMLConfig(cfg ServerConfig) *YAMLConfig {
DataDirStr: zeroIf(ptr(cfg.DataDir()), !cfg.ValueSet(DataDirKey)),
CfgDirStr: zeroIf(ptr(cfg.CfgDir()), !cfg.ValueSet(CfgDirKey)),
MetricsConfig: MetricsYAMLConfig{
Labels: zeroIf(ptr(cfg.MetricsLabels()), !cfg.ValueSet(MetricsLabelsKey)),
Labels: zeroIf(cfg.MetricsLabels(), !cfg.ValueSet(MetricsLabelsKey)),
Host: zeroIf(ptr(cfg.MetricsHost()), !cfg.ValueSet(MetricsHostKey)),
Port: zeroIf(ptr(cfg.MetricsPort()), !cfg.ValueSet(MetricsPortKey)),
},
Expand All @@ -306,7 +292,7 @@ func ServerConfigSetValuesAsYAMLConfig(cfg ServerConfig) *YAMLConfig {
BranchControlFile: zeroIf(ptr(cfg.BranchControlFilePath()), !cfg.ValueSet(BranchControlFilePathKey)),
SystemVars_: zeroIf(systemVars, !cfg.ValueSet(SystemVarsKey)),
Vars: zeroIf(cfg.UserVars(), !cfg.ValueSet(UserVarsKey)),
Jwks: zeroIf(ptr(cfg.JwksConfig()), !cfg.ValueSet(JwksConfigKey)),
Jwks: zeroIf(cfg.JwksConfig(), !cfg.ValueSet(JwksConfigKey)),
}
}

Expand Down Expand Up @@ -388,7 +374,7 @@ func (cfg YAMLConfig) withPlaceholdersFilledIn() YAMLConfig {
}

if withPlaceholders.MetricsConfig.Labels == nil {
withPlaceholders.MetricsConfig.Labels = &map[string]string{}
withPlaceholders.MetricsConfig.Labels = map[string]string{}
}
if withPlaceholders.MetricsConfig.Host == nil {
withPlaceholders.MetricsConfig.Host = ptr("localhost")
Expand Down Expand Up @@ -456,7 +442,7 @@ func (cfg YAMLConfig) withPlaceholdersFilledIn() YAMLConfig {
}

if withPlaceholders.Jwks == nil {
withPlaceholders.Jwks = &[]JwksConfig{}
withPlaceholders.Jwks = []JwksConfig{}
}

return withPlaceholders
Expand Down Expand Up @@ -675,7 +661,7 @@ func (cfg YAMLConfig) DisableClientMultiStatements() bool {
// MetricsLabels returns labels that are applied to all prometheus metrics
func (cfg YAMLConfig) MetricsLabels() map[string]string {
if cfg.MetricsConfig.Labels != nil {
return *cfg.MetricsConfig.Labels
return cfg.MetricsConfig.Labels
}
return nil
}
Expand Down Expand Up @@ -744,7 +730,7 @@ func (cfg YAMLConfig) SystemVars() map[string]interface{} {
// wksConfig is JSON Web Key Set config, and used to validate a user authed with a jwt (JSON Web Token).
func (cfg YAMLConfig) JwksConfig() []JwksConfig {
if cfg.Jwks != nil {
return *cfg.Jwks
return cfg.Jwks
}
return nil
}
Expand Down

0 comments on commit 7d54ed2

Please sign in to comment.