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

[no-release-notes] Cleaning up a couple issues in yaml config missed during review #8743

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 15 additions & 29 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"`
Host *string `yaml:"host,omitempty"`
Port *int `yaml:"port,omitempty"`
}
Expand Down Expand Up @@ -152,8 +138,8 @@ type YAMLConfig struct {
BranchControlFile *string `yaml:"branch_control_file,omitempty"`
// 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"`
SystemVars_ map[string]interface{} `yaml:"system_variables" minver:"1.11.1"`
Jwks []JwksConfig `yaml:"jwks"`
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 All @@ -407,11 +393,11 @@ func (cfg YAMLConfig) withPlaceholdersFilledIn() YAMLConfig {
if withPlaceholders.ClusterCfg == nil {
withPlaceholders.ClusterCfg = &ClusterYAMLConfig{
StandbyRemotes_: []StandbyRemoteYAMLConfig{
StandbyRemoteYAMLConfig{
{
Name_: "standby_replica_one",
RemoteURLTemplate_: "https://standby_replica_one.svc.cluster.local:50051/{database}",
},
StandbyRemoteYAMLConfig{
{
Name_: "standby_replica_two",
RemoteURLTemplate_: "https://standby_replica_two.svc.cluster.local:50051/{database}",
},
Expand All @@ -438,7 +424,7 @@ func (cfg YAMLConfig) withPlaceholdersFilledIn() YAMLConfig {

if withPlaceholders.Vars == nil {
withPlaceholders.Vars = []UserSessionVars{
UserSessionVars{
{
Name: "root",
Vars: map[string]interface{}{
"dolt_show_system_tables": 1,
Expand All @@ -455,8 +441,8 @@ func (cfg YAMLConfig) withPlaceholdersFilledIn() YAMLConfig {
}
}

if withPlaceholders.Jwks == nil {
withPlaceholders.Jwks = &[]JwksConfig{}
if len(withPlaceholders.Jwks) == 0 {
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
6 changes: 3 additions & 3 deletions go/libraries/doltcore/servercfg/yaml_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jwks:
expected.MetricsConfig = MetricsYAMLConfig{
Host: ptr("123.45.67.89"),
Port: ptr(9091),
Labels: &map[string]string{
Labels: map[string]string{
"label1": "value1",
"label2": "2",
"label3": "true",
Expand All @@ -121,7 +121,7 @@ jwks:
},
},
}
expected.Jwks = &[]JwksConfig{
expected.Jwks = []JwksConfig{
{
Name: "jwks_name",
LocationUrl: "https://website.com",
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestYAMLConfigVerboseStringEquivalent(t *testing.T) {
},
YAMLConfig{
MetricsConfig: MetricsYAMLConfig{
Labels: &map[string]string{
Labels: map[string]string{
"xyz": "123",
"0": "AAABBB",
},
Expand Down
Loading